我已经这么做过很多次了,但这些天来,我面临着元框和wp\\u编辑器的问题,许多通知、错误和奇怪的行为。
我已经能够解决元框通知和保存的问题。主要问题是暂时的。我使用的nonce用于插件使用。但是我的代码在主题中,所以现在我无法在metabox中保存值,也没有更多关于metabox的通知。
但现在我得到通知了Notice: Undefined variable: main_detail
对于wp\\U编辑器。在我点击发布/更新后,它不会保存值
<?php
function wpt_performer_posttype() {
register_post_type( \'performer\',
array(
\'labels\' => array(
\'name\' => __( \'Performer\' ),
\'singular_name\' => __( \'performer\' ),
\'add_new\' => __( \'Add New performer\' ),
\'add_new_item\' => __( \'Add New performer\' ),
\'edit_item\' => __( \'Edit performer\' ),
\'new_item\' => __( \'Add New performer\' ),
\'view_item\' => __( \'View performer\' ),
\'search_items\' => __( \'Search performer\' ),
\'not_found\' => __( \'No performer found\' ),
\'not_found_in_trash\' => __( \'No performer found in trash\' )
),
\'public\' => true,
\'supports\' => array( \'title\',\'thumbnail\',\'page-attributes\' ),
\'capability_type\' => \'post\',
\'rewrite\' => array("slug" => "performer"), // Permalinks format
\'menu_position\' => 6,
\'show_ui\'=>true,
\'query_var\'=>true,
\'register_meta_box_cb\' => \'add_performer_metaboxes\'
)
);
}
add_action( \'init\', \'wpt_performer_posttype\' );
/*Add featured thumbnails to the custom post type*/
add_theme_support( \'post-thumbnails\' );
/*Now we add the meta boxes to the performer*/
// add_action(\'add_meta_boxes\', \'add_performer_metaboxes\');
function add_performer_metaboxes() {
add_meta_box(\'wpt_performer_lines\', __(\'Extra fields\'), \'wpt_performer_lines\', \'performer\', \'normal\', \'high\');
}
function wpt_performer_lines(){
global $post;
wp_nonce_field( \'my_meta_box\', \'performermeta_noncename\' );
$short_description = get_post_meta($post->ID, \'_short_description\', true);
echo \'<label >\';?><?php _e( \'short description:\' );?></label>
<?php echo \'<br><textarea name="_short_description" rows="1" cols="90">\'.$short_description.\'</textarea>\';?>
<?php wp_editor( $main_detail, \'main_detail\', array( \'textarea_name\' => \'_main_detail\', \'textarea_rows\' =>5, \'media_buttons\' => false ) );
}
function wpt_save_performer_meta($post_id, $post) {
if ( ! isset( $_POST[\'performermeta_noncename\'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST[\'performermeta_noncename\'], \'my_meta_box\' ) ) {
return;
}
if ( !current_user_can( \'edit_post\', $post->ID ))
return $post->ID;
$performer_meta[\'_short_description\'] = trim($_POST[\'_short_description\']);
foreach ($performer_meta as $key => $value) { // Cycle through the $performer_meta array!
if( $post->post_type == \'revision\' ) return; // Don\'t store custom data twice
$value = implode(\',\', (array)$value); // If $value is an array, make it a CSV (unlikely)
if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
update_post_meta($post->ID, $key, $value);
} else { // If the custom field doesn\'t have a value
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
}
}
add_action(\'save_post\', \'wpt_save_performer_meta\', 1, 2); // save the custom fields
?>