我已将此元框添加到我的网站:
// Assistant Editor Box
add_action( \'add_meta_boxes\', \'assistant_editor_box\' );
function assistant_editor_box() {
add_meta_box(
\'assistant_editor_box\', // id, used as the html id att
__( \'Assistant Editor\' ), // meta box title
\'assistant_editor_cb\', // callback function, spits out the content
\'post\', // post type or page. This adds to posts only
\'side\', // context, where on the screen
\'high\' // priority, where should this go in the context
);
}
function assistant_editor_cb( $post ) {
global $wpdb;
$value = get_post_meta($post->ID, \'proofread\', true);
echo \'<div class="misc-pub-section misc-pub-section-last"><span id="timestamp"><label>Proofread: </label>\';
$assedit = array(
1 => \' Yes \',
);
echo \'<select name="proofread">\';
echo \'<option value=""\' . ((($value == \'\') || !isset($assedit[$value])) ? \' selected="selected"\' : \'\') . \'> No </option>\';
// output
foreach ($assedit as $id => $text) {
echo \'<option value="\' . $id . \'"\' . (($value == $id) ? \' selected="selected"\' : \'\') . \'">\' . $text. \'</option>\';
}
echo \'</select>\';
echo \'</span></div>\';
}
add_action( \'save_post\', \'save_metadata\');
function save_metadataeditass($postid)
{
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) return false;
if ( !current_user_can( \'edit_page\', $postid ) ) return false;
if( empty($postid) ) return false;
if ( is_null($_REQUEST["proofread"]) ) {
delete_post_meta($postid, \'proofread\');
} else {
update_post_meta($postid, \'proofread\', $_REQUEST[\'proofread\']);
}
}
// END Assistant Editor Box
我想根据能力限制对它的访问。我尝试了以下代码:
function remove_assistant_editor_box_meta() {
if (!current_user_can(\'edit_others_posts\')){
remove_meta_box( \'assistant_editor_box\', \'post\', \'side\' );
}
}
add_action( \'admin_menu\' , \'remove_assistant_editor_box_meta\' );
不起作用,也尝试了以下操作:
function remove_assistant_editor_box_meta(){
if(function_exists(\'assistant_editor_box\') && !current_user_can(\'edit_others_posts\')){
add_filter(\'assistant_editor_box\', \'__return_false\');
}
}
add_action(\'init\', \'remove_assistant_editor_box_meta\');
根据Wordpress文档,第一个代码应该可以工作,
what in the world am I doing wrong here?