Last active
February 19, 2016 04:00
-
-
Save rilwis/b733f20369b6c282e68f to your computer and use it in GitHub Desktop.
Register Meta Boxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// IMPORTANT: This is depracated and not supported any more | |
// Global variable which stores all meta boxes. | |
global $meta_boxes; | |
$meta_boxes = array(); | |
$prefix = 'rw_'; | |
// 1st meta box | |
$meta_boxes[] = array( | |
'id' => 'personal', | |
'title' => __( 'Personal Information', 'textdomain' ), | |
'post_types' => array( 'post', 'page' ), | |
'fields' => array( | |
array( | |
'name' => __( 'Full name', 'textdomain' ), | |
'desc' => 'Format: First Last', | |
'id' => $prefix . 'fname', | |
'type' => 'text', | |
'std' => 'Anh Tran', | |
'class' => 'custom-class', | |
'clone' => true, | |
), | |
) | |
); | |
// 2nd meta box | |
$meta_boxes[] = array( | |
'title' => __( 'Media', 'textdomain' ), | |
'post_types' => 'movie', | |
'fields' => array( | |
array( | |
'name' => __( 'URL', 'textdomain' ), | |
'id' => $prefix . 'url', | |
'type' => 'text', | |
), | |
) | |
); | |
function YOURPREFIX_register_meta_boxes() { | |
global $meta_boxes; | |
if ( ! class_exists( 'RW_Meta_Box' ) ) | |
return; | |
foreach ( $meta_boxes as $meta_box ) { | |
new RW_Meta_Box( $meta_box ); | |
} | |
} | |
add_action( 'admin_init', 'YOURPREFIX_register_meta_boxes' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'rwmb_meta_boxes', 'YOURPREFIX_register_meta_boxes' ); | |
function YOURPREFIX_register_meta_boxes( $meta_boxes ) { | |
$prefix = 'rw_'; | |
// 1st meta box | |
$meta_boxes[] = array( | |
'id' => 'personal', | |
'title' => __( 'Personal Information', 'textdomain' ), | |
'post_types' => array( 'post', 'page' ), | |
'context' => 'normal', | |
'priority' => 'high', | |
'fields' => array( | |
array( | |
'name' => __( 'Full name', 'textdomain' ), | |
'desc' => 'Format: First Last', | |
'id' => $prefix . 'fname', | |
'type' => 'text', | |
'std' => 'Anh Tran', | |
'class' => 'custom-class', | |
'clone' => true, | |
), | |
) | |
); | |
// 2nd meta box | |
$meta_boxes[] = array( | |
'title' => __( 'Media', 'textdomain' ), | |
'post_types' => 'movie', | |
'fields' => array( | |
array( | |
'name' => __( 'URL', 'textdomain' ), | |
'id' => $prefix . 'url', | |
'type' => 'text', | |
), | |
) | |
); | |
return $meta_boxes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment