Skip to content

Instantly share code, notes, and snippets.

@hemusyl
Created March 12, 2017 07:58
Show Gist options
  • Save hemusyl/1308794de7e08dbc6bfff7178a104a60 to your computer and use it in GitHub Desktop.
Save hemusyl/1308794de7e08dbc6bfff7178a104a60 to your computer and use it in GitHub Desktop.
meta box ( Meta box of Option Tree plugin )
<?php
/**
* Initialize the custom Meta Boxes.
*/
add_action( 'admin_init', 'custom_meta_boxes' );
/**
* Meta Boxes demo code.
*
* You can find all the available option types in demo-theme-options.php.
*
* @return void
* @since 2.0
*/
function custom_meta_boxes() {
$versiontwos_feature_meta_box = array(
'id' => 'slide_meta_box',
'title' => __( 'Slider Meta Box', 'versiontwos' ),
'pages' => array( 'slide' ),
'context' => 'normal',
'priority' => 'low',
'fields' => array(
array(
'label' => __( 'Button Link', 'versiontwos' ),
'id' => 'slide_link',
'type' => 'text',
'std' => 'www.google.com',
),
)
);
/**
* Register our meta boxes using the
* ot_register_meta_box() function.
*/
if ( function_exists( 'ot_register_meta_box' ) )
ot_register_meta_box( $versiontwos_feature_meta_box );
$versiontwos_job_meta_box = array(
'id' => 'job_meta_box',
'title' => __( 'Job Meta Box', 'versiontwos' ),
'desc' => __( 'For Example: Full time', 'versiontwos' ),
'pages' => array( 'job' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'label' => __( 'Job Type', 'versiontwos' ),
'id' => 'job_type',
'type' => 'select',
'std' => '',
'choices' => array(
array(
'value' => '',
'label' => __( '-- Choose One --', 'versiontwos' ),
'src' => ''
),
array(
'value' => 'Fulltime',
'label' => __( 'Full time', 'versiontwos' ),
'src' => ''
),
array(
'value' => 'PartTime',
'label' => __( 'Part Time', 'versiontwos' ),
'src' => ''
),
array(
'value' => 'Contractual',
'label' => __( 'Contractual', 'versiontwos' ),
'src' => ''
)
)
),
array(
'label' => __( 'Slary', 'versiontwos' ),
'id' => 'job_slary',
'type' => 'text',
'std' => '',
),
)
);
/**
* Register our meta boxes using the
* ot_register_meta_box() function.
*/
if ( function_exists( 'ot_register_meta_box' ) )
ot_register_meta_box( $versiontwos_job_meta_box );
/**
* Create a custom meta boxes array that we pass to
* the OptionTree Meta Box API Class.
*/
$my_meta_box = array(
'id' => 'demo_meta_box',
'title' => __( 'Demo Meta Box', 'versiontwos' ),
'desc' => '',
'pages' => array( 'post' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'label' => __( 'Conditions', 'versiontwos' ),
'id' => 'demo_conditions',
'type' => 'tab'
),
array(
'label' => __( 'Show Gallery', 'versiontwos' ),
'id' => 'demo_show_gallery',
'type' => 'on-off',
'desc' => sprintf( __( 'Shows the Gallery when set to %s.', 'versiontwos' ), '<code>on</code>' ),
'std' => 'off'
),
array(
'label' => '',
'id' => 'demo_textblock',
'type' => 'textblock',
'desc' => __( 'Congratulations, you created a gallery!', 'versiontwos' ),
'operator' => 'and',
'condition' => 'demo_show_gallery:is(on),demo_gallery:not()'
),
array(
'label' => __( 'Gallery', 'versiontwos' ),
'id' => 'demo_gallery',
'type' => 'gallery',
'desc' => sprintf( __( 'This is a Gallery option type. It displays when %s.', 'versiontwos' ), '<code>demo_show_gallery:is(on)</code>' ),
'condition' => 'demo_show_gallery:is(on)'
),
array(
'label' => __( 'More Options', 'versiontwos' ),
'id' => 'demo_more_options',
'type' => 'tab'
),
array(
'label' => __( 'Text', 'versiontwos' ),
'id' => 'demo_text',
'type' => 'text',
'desc' => __( 'This is a demo Text field.', 'versiontwos' )
),
array(
'label' => __( 'Textarea', 'versiontwos' ),
'id' => 'demo_textarea',
'type' => 'textarea',
'desc' => __( 'This is a demo Textarea field.', 'versiontwos' )
)
)
);
/**
* Register our meta boxes using the
* ot_register_meta_box() function.
*/
if ( function_exists( 'ot_register_meta_box' ) )
ot_register_meta_box( $my_meta_box );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment