Get pluginBuy

Quick Start

Here you can find ready pieces of code which you can insert to you current theme functions.php or to a child theme functions.php or to a custom plugin.

Jump to the section you need.

Meta Boxes
Taxonomy Settings
Option Pages

Create a Meta Box

A meta box can be created with a filter hook simple_register_metaboxes.

add_filter( 'simple_register_metaboxes', 'misha_create_a_metabox' );
 
function misha_create_a_metabox( $metaboxes ) {
 
	$metaboxes[] = array(
 		'id' => 'my_metabox',
 		'name' => 'Meta Box',
 		'post_type' => array( 'page' ),
 		'fields' => array(
			array(
				'id' => 'my_field',
				'label' => 'Label',
				'type' => 'text',
			),
			array(
				'id' => 'my_checkbox',
				'label' => 'Label',
				'type' => 'checkbox',
				'short_description' => 'Yes'
			)
 		)
 	);
 
	return $metaboxes;
 
}

And here is the result:

Simple WordPress Meta box

After that you can use get_post_meta() and field ID to get the data in your template files:

$checkbox_value = get_post_meta( $post_id, 'my_checkbox', true );

Create Settings for a Taxonomy

In this case you would need another filter hook which is simple_register_taxonomy_settings.

add_filter( 'simple_register_taxonomy_settings', 'misha_taxonomy_settings' );
 
function misha_taxonomy_settings( $settings ) {
 
	$settings[] = array(
 		'id' => 'mishatest',
 		'taxonomy' => array( 'post_tag' ),
 		'fields' => array(
			array(
				'id' => 'my_field',
				'label' => 'Text Field',
				'type' => 'text',
			),
			array(
				'id' => 'my_select_field',
				'label' => 'Select field',
				'type' => 'select',
				'placeholder' => 'Please choose wisely...',
				'options' => array(
					'val1' => 'Option 1',
					'val2' => 'Option 2',
				),
			)
 		)
 	);
 
	return $settings;
 
}

And here is what we got:

WordPress term taxonomy settings

To get the data in your template files use get_term_meta() WordPress function.

$selectfield_value = get_term_meta( $post_id, 'my_select_field', true );

Create an Option Page

My plugin allows to create option pages as well with a hook simple_register_option_pages.

add_filter( 'simple_register_option_pages', 'misha_option_page' );
 
function misha_option_page( $option_pages ) {
 
	$option_pages[] = array(
		'id'	=> 'misha_settings',
		'title' => 'My Page Settings',
		'menu_name' => 'My page',
		'capability' =>	'edit_posts',
		'fields' => array(
			array(
				'id' => 'my_field',
				'label' => 'Text Field',
				'type' => 'text',
			),
			array(
				'id' => 'my_checkbox',
				'label' => 'Checkbox',
				'type' => 'checkbox',
				'short_description' => 'Yesss'
			),
			array(
				'id' => 'my_image',
				'label' => 'Image',
				'type' => 'image',
			)
 		),
	);
 
	return $option_pages;
 
}

So we have a pretty simple settings page:

Create a custom option page

After that use get_option() function in your template files to get the data.

$field = get_option( 'my_field' );