Basic usage:
Use the following code to create image field:
1 2 3 4 5 6 7 8 |
$xbox->add_field(array( 'id' => 'custom-image', 'name' => __( 'Image', 'textdomain' ), 'type' => 'image', 'default' => 'http://wp.dev/wp-content/uploads/2016/01/iron_man_3_iron_man_vs_mandarin-wallpaper-1366x768-768x432.jpg', )); |
Result:
Advanced usage, with available options:
1 2 3 4 5 6 7 8 9 10 11 12 |
$xbox->add_field(array( 'id' => 'custom-image', 'name' => __( 'Image', 'textdomain' ), 'type' => 'image', 'default' => 'http://wp.dev/wp-content/uploads/2016/01/iron_man_3_iron_man_vs_mandarin-wallpaper-1366x768-768x432.jpg', 'options' => array( 'hide_input' => true,//Default: false 'image_class' => 'custom-class-for-image', ) )); |
Getting saved value:
1 2 3 4 5 6 7 8 |
$xbox = Xbox::get( 'metabox-id' ); $value = $xbox->get_field_value( 'custom-image' ); var_dump($value); //Return: string(103) "http://wp.dev/wp-content/uploads/2016/01/iron_man_----.jpg" |