_meta_box = $meta_box; $upload = false; foreach ( $meta_box['fields'] as $field ) { if ( $field['type'] == 'file' || $field['type'] == 'file_list' ) { $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_menu', array(&$this, 'add') ); add_action( 'save_post', array(&$this, 'save') ); add_filter( 'cmb_show_on', array(&$this, 'add_for_id' ), 10, 2 ); add_filter( 'cmb_show_on', array(&$this, 'add_for_page_template' ), 10, 2 ); } function add_post_enctype() { echo ' '; } // Add metaboxes 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']; $this->_meta_box['show_on'] = empty( $this->_meta_box['show_on'] ) ? array('key' => false, 'value' => false) : $this->_meta_box['show_on']; foreach ( $this->_meta_box['pages'] as $page ) { if( apply_filters( 'cmb_show_on', true, $this->_meta_box ) ) add_meta_box( $this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show'), $page, $this->_meta_box['context'], $this->_meta_box['priority']) ; } } /** * Show On Filters * Use the 'cmb_show_on' filter to further refine the conditions under which a metabox is displayed. * Below you can limit it by ID and page template */ // Add for ID function add_for_id( $display, $meta_box ) { if ( 'id' !== $meta_box['show_on']['key'] ) return $display; // If we're showing it based on ID, get the current ID if( isset( $_GET['post'] ) ) $post_id = $_GET['post']; elseif( isset( $_POST['post_ID'] ) ) $post_id = $_POST['post_ID']; if( !isset( $post_id ) ) return $display; // If value isn't an array, turn it into one $meta_box['show_on']['value'] = !is_array( $meta_box['show_on']['value'] ) ? array( $meta_box['show_on']['value'] ) : $meta_box['show_on']['value']; // If current page id is in the included array, display the metabox if ( in_array( $post_id, $meta_box['show_on']['value'] ) ) return true; else return false; } // Add for Page Template function add_for_page_template( $display, $meta_box ) { if( 'page-template' !== $meta_box['show_on']['key'] ) return $display; // Get the current ID if( isset( $_GET['post'] ) ) $post_id = $_GET['post']; elseif( isset( $_POST['post_ID'] ) ) $post_id = $_POST['post_ID']; if( !( isset( $post_id ) || is_page() ) ) return $display; // Get current template $current_template = get_post_meta( $post_id, '_wp_page_template', true ); // If value isn't an array, turn it into one $meta_box['show_on']['value'] = !is_array( $meta_box['show_on']['value'] ) ? array( $meta_box['show_on']['value'] ) : $meta_box['show_on']['value']; // See if there's a match if( in_array( $current_template, $meta_box['show_on']['value'] ) ) return true; else return false; } // Show fields function show() { // $wp_version used for compatibility with new wp_editor() function global $post, $wp_version; // Use nonce for verification echo ''; echo '
| '; } else { if( $this->_meta_box['show_names'] == true ) { echo ' | '; } echo ' | ';
}
switch ( $field['type'] ) {
case 'text':
echo '','';
break;
case 'text_small':
echo '';
break;
case 'text_medium':
echo '';
break;
case 'text_date':
echo '';
break;
case 'text_date_timestamp':
echo '';
break;
case 'text_time':
echo '';
break;
case 'text_money':
echo '$ ';
break;
case 'textarea':
echo '','';
break;
case 'textarea_small':
echo '','';
break;
case 'textarea_code':
echo '','';
break;
case 'select':
echo '';
echo '';
break;
case 'radio_inline':
if( empty( $meta ) && !empty( $field['std'] ) ) $meta = $field['std'];
echo ' ';
foreach ($field['options'] as $option) {
echo ' ';
echo '';
break;
case 'radio':
if( empty( $meta ) && !empty( $field['std'] ) ) $meta = $field['std'];
foreach ($field['options'] as $option) {
echo '', $option['name'], ' ';
}
echo '', $option['name'].' '; } echo ''; break; case 'checkbox': echo ''; echo ''; break; case 'multicheck': echo '
', $field['name'], ''; echo ''; break; case 'wysiwyg': /* Make sure that the new wp_editor() function is available. * Otherwise, use the "old" version of the WYSIWYG editor */ if( function_exists( 'wp_editor' ) ) { wp_editor( $meta ? $meta : $field['std'], $field['id'], isset( $field['options'] ) ? $field['options'] : array() ); } else { echo ''; } echo ''; break; case 'taxonomy_select': echo ''; echo ''; break; case 'taxonomy_radio': $names= wp_get_object_terms( $post->ID, $field['taxonomy'] ); $terms = get_terms( $field['taxonomy'], 'hide_empty=0' ); foreach ( $terms as $term ) { if ( !is_wp_error( $names ) && !empty( $names ) && !strcmp( $term->slug, $names[0]->slug ) ) { echo '' . $term->name . ' '; } else { echo '' . $term->name .' '; } } echo ''; break; case 'taxonomy_multicheck': echo '
';
if ( $meta != '' ) {
$check_image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $meta );
if ( $check_image ) {
echo ' ';
break;
default:
do_action('cmb_render_' . $field['type'] , $field, $meta);
}
echo '';
echo ' ';
} else {
$parts = explode( "/", $meta );
for( $i = 0; $i < sizeof( $parts ); ++$i ) {
$title = $parts[$i];
}
echo 'File: ', $title, ' (Download / Remove)';
}
}
echo ' | ','|
|---|---|---|---|