'my-meta-box-1', 'title' => 'Match details', 'pages' => array('post', 'matches'), // multiple post types, accept custom post types 'context' => 'normal', // normal, advanced, side (optional) 'priority' => 'high', // high, low (optional) 'fields' => array( array( 'name' => 'Enable match details', // check box 'id' => $prefix . 'checkbox', 'type' => 'checkbox' ), array( 'name' => 'Team 1', 'desc' => 'vs', 'id' => $prefix . 'team1', 'type' => 'text', // text box 'std' => '', ), array( 'name' => 'Team 2', 'desc' => '', 'id' => $prefix . 'team2', 'type' => 'text', // text box 'std' => '', ), array( 'name' => 'Match type', 'id' => $prefix . 'select', 'type' => 'select', // select box 'options' => array( // array of name, value pairs for select box array('name' => 'Single Elimation', 'value' => 'bo1'), array('name' => 'Best of 3', 'value' => 'bo3'), array('name' => 'Best of 5', 'value' => 'bo5') ) ), ) ); // second meta box $meta_boxes[] = array( 'id' => 'my-meta-box-2', 'title' => 'Champion picks and bans', 'pages' => array('post', 'matches'), // custom post types, since WordPress 3.0 'context' => 'normal', 'priority' => 'high', 'fields' => array( array( 'name' => 'Enable champion picks and bans', // check box 'id' => $prefix . 'checkboxpickbans', 'type' => 'checkbox' ), array( 'name' => 'Team 1 Champion Picks', 'id' => $prefix . 'select1', 'type' => 'champselect', // select box 'options' => array( // array of name, value pairs for select box array('name' => 'Alistar', 'value' => 'alistar'), array('name' => 'Ahri', 'value' => 'ahri'), array('name' => 'Sona', 'value' => 'sona'), array('name' => 'Annie', 'value' => 'annie'), array('name' => 'Urgot', 'value' => 'urgot'), array('name' => 'Wukong', 'value' => 'wukong') ) ), array( 'name' => 'Team 2 Champion Picks', 'id' => $prefix . 'select2', 'type' => 'champselect', // select box 'options' => array( // array of name, value pairs for select box array('name' => 'Alistar', 'value' => 'alistar'), array('name' => 'Ahri', 'value' => 'ahri'), array('name' => 'Sona', 'value' => 'sona'), array('name' => 'Annie', 'value' => 'annie'), array('name' => 'Urgot', 'value' => 'urgot'), array('name' => 'Wukong', 'value' => 'wukong') ) ), array( 'name' => 'Team 1 Champion Bans', 'id' => $prefix . 'select3', 'type' => 'champbans', // select box 'options' => array( // array of name, value pairs for select box array('name' => 'Alistar', 'value' => 'alistar'), array('name' => 'Ahri', 'value' => 'ahri'), array('name' => 'Sona', 'value' => 'sona'), array('name' => 'Annie', 'value' => 'annie'), array('name' => 'Urgot', 'value' => 'urgot'), array('name' => 'Wukong', 'value' => 'wukong') ) ), array( 'name' => 'Team 2 Champion Bans', 'id' => $prefix . 'select4', 'type' => 'champbans', // select box 'options' => array( // array of name, value pairs for select box array('name' => 'Alistar', 'value' => 'alistar'), array('name' => 'Ahri', 'value' => 'ahri'), array('name' => 'Sona', 'value' => 'sona'), array('name' => 'Annie', 'value' => 'annie'), array('name' => 'Urgot', 'value' => 'urgot'), array('name' => 'Wukong', 'value' => 'wukong') ) ), ) ); $meta_boxes[] = array( 'id' => 'my-meta-box-3', 'title' => 'VOD', 'pages' => array('post', 'matches'), // multiple post types, accept custom post types 'context' => 'normal', // normal, advanced, side (optional) 'priority' => 'high', // high, low (optional) 'fields' => array( array( 'name' => 'Enable VOD', // check box 'id' => $prefix . 'checkboxvod', 'type' => 'checkbox' ), array( 'name' => 'VOD Embed Code', 'desc' => 'Link to the matches VOD from own3d, Youtube, Twitch etc', 'id' => $prefix . 'textareavod', 'type' => 'textarea', // text area 'std' => '' ), ) ); foreach ($meta_boxes as $meta_box) { $my_box = new RW_Meta_Box($meta_box); } // Validate value of meta fields // Define ALL validation methods inside this class // and use the names of these methods in the definition of meta boxes (key 'validate_func' of each field) class RW_Meta_Box_Validate { function check_text($text) { if ($text != 'hello') { return false; } return true; } } /** * AJAX delete images on the fly. This script is a slightly altered version of a function used by the Plugin "Verve Meta Boxes" * http://wordpress.org/extend/plugins/verve-meta-boxes/ * */ add_action('wp_ajax_unlink_file', 'unlink_file_callback'); function unlink_file_callback() { global $wpdb; if ($_POST['data']) { $data = explode('-', $_POST['data']); $att_id = $data[0]; $post_id = $data[1]; wp_delete_attachment($att_id); } } /** * Create meta boxes */ class RW_Meta_Box { protected $_meta_box; // create meta box based on given data function __construct($meta_box) { if (!is_admin()) return; $this->_meta_box = $meta_box; // fix upload bug: http://www.hashbangcode.com/blog/add-enctype-wordpress-post-and-page-forms-471.html $upload = false; foreach ($meta_box['fields'] as $field) { if ($field['type'] == 'file' || $field['type'] == 'image') { $upload = true; break; } } $current_page = substr(strrchr($_SERVER['PHP_SELF'], '/'), 1, -4); if ($upload && ($current_page == 'page' || $current_page == 'page-new' || $current_page == 'post' || $current_page == 'post-new')) { add_action('admin_head', array(&$this, 'add_post_enctype')); add_action('admin_head', array(&$this, 'add_unlink_script')); add_action('admin_head', array(&$this, 'add_clone_script')); } add_action('admin_menu', array(&$this, 'add')); add_action('save_post', array(&$this, 'save')); } function add_post_enctype() { echo ' '; } function add_unlink_script(){ echo ' '; } function add_clone_script() { echo ' '; } /// Add meta box for multiple post types function add() { $this->_meta_box['context'] = empty($this->_meta_box['context']) ? 'normal' : $this->_meta_box['context']; $this->_meta_box['priority'] = empty($this->_meta_box['priority']) ? 'high' : $this->_meta_box['priority']; foreach ($this->_meta_box['pages'] as $page) { add_meta_box($this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show'), $page, $this->_meta_box['context'], $this->_meta_box['priority']); } } // Callback function to show fields in meta box function show() { global $post; // Use nonce for verification echo ''; echo '
', ' | ';
switch ($field['type']) {
case 'text':
echo '',
' ', $field['desc']; break; case 'textarea': echo '', ' ', $field['desc']; break; case 'select': echo ''; break; case 'radio': foreach ($field['options'] as $option) { echo '', $option['name']; } break; case 'checkbox': echo ''; break; case 'file': echo $meta ? "$meta " : '', '', ' ', $field['desc']; break; case 'wysiwyg': echo '', ' ', $field['desc']; break; case 'champselect': echo ''; echo ''; echo ''; echo ''; echo ''; break; case 'champbans': echo ''; echo ''; echo ''; break; case 'image': ?> Images attached to this post
'attachment',
'post_parent' => $post->ID,
'numberposts' => -1,
'post_status' => NULL
);
$attachs = get_posts($args);
if (!empty($attachs)) {
foreach ($attachs as $att) {
?>
ID, 'thumbnail'); ?>
Delete Image Upload new Images', ' |
---|