Basic usage:
Use the following code to create file field:
1 2 3 4 5 6 7 |
$xbox->add_field(array( 'id' => 'custom-file', 'name' => __( 'Image', 'textdomain' ), 'type' => 'file', )); |
Result:
Advanced usage, with available options:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$xbox->add_field(array( 'id' => 'custom-file', 'name' => __( 'Files', 'textdomain' ), 'type' => 'file', 'options' => array( 'multiple' => true,//Default: false 'mime_types' => array( 'jpg', 'jpeg', 'png', 'mp3', 'pdf' ),//Default: array() 'protocols' => array( 'http', 'https' ),//Default: array() 'preview_size' => array( 'width' => '60px' ),//Default: array( 'width' => '64px', 'height' => 'auto' ) ) )); |
Result:
Getting saved value:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
$xbox = Xbox::get( 'metabox-id' ); $value = $xbox->get_field_value( 'custom-file' ); var_dump($value); //Return: array(4) { [0]=> string(95) "-----.jpg" [1]=> string(80) "------jpg" [2]=> string(60) "------Game-of-Thrones.mp3" [3]=> string(59) "------Xbox-Framework.pdf" } $attachment_ids = $xbox->get_field_value( 'custom-file_id' ); var_dump($attachment_ids); //Return: array(4) { [0]=> string(2) "14" [1]=> string(2) "12" [2]=> string(4) "1510" [3]=> string(4) "1778" } |