PHP code example of moogatw / wp-metabox

1. Go to this page and download the library: Download moogatw/wp-metabox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moogatw / wp-metabox example snippets




use MGD\Metabox;

$options = array( ... );

$books = new Metabox( $options );


// Require the Composer autoloader.
ox;

## Usage

To create a metabox, first instantiate an instance of `Metabox`.  The class takes one argument, which is an associative array.  The keys to the array are similar to the arguments provided to the [add_meta_box](https://developer.wordpress.org/reference/functions/add_meta_box/) WordPress function; however, you don't provide `callback` or `callback_args`.


$metabox->addText(array(
	'id' => 'metabox_text_field',
	'label' => 'Text',
	'desc' => 'An example description paragraph that appears below the label.'
));

$metabox->addTextArea(array(
	'id' => 'metabox_textarea_field',
	'label' => 'Textarea',
	'desc' => 'An example description paragraph that appears below the label.'
));

$metabox->addCheckbox(array(
	'id' => 'metabox_checkbox_field',
	'label' => 'Checkbox',
	'desc' => 'An example description paragraph that appears below the label.'
));

$metabox->addRadio(
	array(
		'id' => 'metabox_radio_field',
		'label' => 'Radio',
		'desc' => 'An example description paragraph that appears below the label.',
	),
	array(
		'key1' => 'Value One',
		'key2' => 'Value Two'
	)
);

$metabox->addSelect(
	array(
		'id' => 'metabox_select_field',
		'label' => 'Select',
		'desc' => 'An example description paragraph that appears below the label.',
	),
	array(
		'key1' => 'Value One',
		'key2' => 'Value Two'
	)
);

$metabox->addImage(array(
	'id' => 'metabox_image_field',
	'label' => 'Image Upload',
	'desc' => 'An example description paragraph that appears below the label.'
));

$metabox->addEditor(array(
	'id' => 'metabox_editor_field',
	'label' => 'Editor',
	'desc' => 'An example description paragraph that appears below the label.'
));

$metabox->addNumber(array(
	'id' => 'metabox_number_field',
	'label' => 'Number',
	'desc' => 'An example description paragraph that appears below the label.'
));

$metabox->addColor(array(
	'id' => 'metabox_color_field',
	'label' => 'Color',
	'desc' => 'An example description paragraph that appears below the label.'
));

$metabox->addText(array(
	'id' => 'metabox_text_field',
	'label' => 'Text',
	'desc' => 'An example description paragraph that appears below the label.'
	'col' => '6',
));

$metabox->addRadio(
	array(
		'id' => 'metabox_radio_field',
		'label' => 'Radio',
		'desc' => 'An example description paragraph that appears below the label.',
		'col' => '3',
	),
	array(
		'key1' => 'Value One',
		'key2' => 'Value Two'
	)
);


$metabox_repeater_block_fields[] = $metabox->addText(array(
	'id' => 'metabox_repeater_text_field',
	'label' => 'Photo Title'
), true);

$metabox_repeater_block_fields[] = $metabox->addTextArea(array(
	'id' => 'metabox_repeater_textarea_field',
	'label' => 'Photo Description'
), true);

$metabox_repeater_block_fields[] = $metabox->addImage(array(
	'id' => 'metabox_repeater_image_field',
	'label' => 'Upload Photo'
), true);

$metabox->addRepeaterBlock(array(
	'id' => 'metabox_repeater_block',
	'label' => 'Photo Gallery',
	'fields' => $metabox_repeater_block_fields,
	'desc' => 'Photos in a photo gallery.',
	'single_label' => 'Photo'
));