我找到了这个有效的代码。
参考号:https://gist.github.com/trinitybranding/72066ca34584535dccbe3290dee02791
我重命名了原始函数名。
function __hasMetabox( $meta_box_id, $post_type = false ){
global $wp_meta_boxes, $grist_meta_box_found;
$grist_meta_box_found = false; // assume not found by default
// if meta boxes are not yet set up, let\'s issue an error
if( empty( $wp_meta_boxes ) or ! is_array( $wp_meta_boxes ) )
return new WP_Error( \'missing-meta-boxes\', \'global $wp_meta_boxes is not the expected array\' );
// should we only look at meta boxes for a specific post type?
if ( $post_type )
$meta_boxes = $wp_meta_boxes[ $post_type ];
else
$meta_boxes = $wp_meta_boxes;
// step through each meta box registration and check if the supplied id exists
array_walk_recursive( $meta_boxes, function( $value, $key, $meta ){
global $grist_meta_box_found;
if ( $key === \'id\' and strtolower( $value ) === strtolower( $meta ) )
$grist_meta_box_found = true;
}, $meta_box_id );
$return = $grist_meta_box_found; // temp store the return value
unset( $grist_meta_box_found ); // remove var from from global space
return $return;
}
那就做点像。。。
add_action(\'add_meta_boxes\', function() {
global $wp_meta_boxes, $post;
if (__hasMetabox(\'submitdiv\', $post->post_type))
$wp_meta_boxes[$post->post_type][\'side\'][\'core\'][\'submitdiv\'][\'title\'] = \'Amazing!!!\';
});
输出示例:
