无法从edit.php中删除插件的元框

时间:2013-04-30 00:24:10

标签: wordpress wordpress-plugin meta-boxes

我正在尝试从edit.php屏幕删除插件的Page Links To元素用于作者用户角色(文章编辑)...我可以为所有其他元文件执行此操作但page-links-to

这是我的代码

if ( current_user_can('author') )
{

    function my_remove_meta_boxes()
    {
        remove_meta_box('postexcerpt', 'post', 'normal');
        remove_meta_box('trackbacksdiv', 'post', 'normal');
        remove_meta_box('postcustom', 'post', 'normal');
        remove_meta_box('revisionsdiv', 'post', 'normal');
        remove_meta_box('commentstatusdiv', 'post', 'normal');
        remove_meta_box('commentsdiv', 'post', 'normal');
        remove_meta_box('slugdiv', 'post', 'normal');
        remove_meta_box('tagsdiv-post_tag', 'post', 'side');
        remove_meta_box('categorydiv', 'post', 'side');
        remove_meta_box('postimagediv', 'post', 'side');

        remove_meta_box('page-links-to', 'post', 'normal');

    }
    add_action( 'do_meta_boxes', 'my_remove_meta_boxes' );

在插件的源代码中,我发现了这个:

function do_meta_boxes( $page, $context ) {
        // Plugins that use custom post types can use this filter to hide the PLT UI in their post type.
        $plt_post_types = apply_filters( 'page-links-to-post-types', array_keys( get_post_types( array('show_ui' => true ) ) ) );

        if ( in_array( $page, $plt_post_types ) && 'advanced' === $context )
            add_meta_box( 'page-links-to', 'Page Links To', array( $this, 'meta_box' ), $page, 'advanced', 'low' );
    }

但是我找不到任何方法来检测一个工作钩子来移除metabox。

1 个答案:

答案 0 :(得分:3)

两个选项。

为钩子添加较低的优先级。

add_action( 'do_meta_boxes', 'my_remove_meta_boxes', 9999 );

到目前为止,插件挂钩应该已经运行并且删除工作正常。我建议在回调函数current_user_can中移动my_remove_meta_boxes()

使用插件提供的挂钩

add_filter( 'page-links-to-post-types', 'remove_box_so_16290352' );

function remove_box_so_16290352( $post_types )
{
    $key = array_search( 'page', $post_types );
    if( $key !== false ) {
        unset($post_types[$key]);
    }

    return $post_types;
}
相关问题