我如何从作者管理面板隐藏一些类别?

时间:2013-05-10 作者:Smart Shovon

我希望作者不能看到一些类别从作者管理面板,但管理员可以看到。如何隐藏某些类别?我的网站http://techjagot.com ..

这里显示一些函数。PHP代码

<?php

// Theme Settings Page
require_once(TEMPLATEPATH . "/theme-settings.php");

// Theme Styles
require_once(TEMPLATEPATH . "/theme-styles.php");

// Theme Widgets
require_once(TEMPLATEPATH . "/theme-widgets.php");

// Load Custom Post Options for Write Post and Write Page
require_once(TEMPLATEPATH . "/theme-metaboxes.php");

// Load Theme Javascript
require_once(TEMPLATEPATH . "/theme-js.php");

// Theme Image Functions
require_once(TEMPLATEPATH . "/theme-images.php");

// Register widgetized areas
function theme_widgets_init() {
    register_sidebar(array (
        \'name\'=>\'Sidebar-Wide - Top\',
        \'id\'=>\'widget-1\',
        \'before_widget\' => \'<div id="%1$s" class="widget %2$s"><div class="widget-wrap">\',
        \'after_widget\' => \'</div></div>\',
        \'before_title\' => \'<h3 class="widgettitle"><span>\',
        \'after_title\' => \'</span></h3>\',
        ));
    register_sidebar(array (
        \'name\'=>\'Sidebar-Wide - Bottom Left\',
        \'id\'=>\'widget-2\',
        \'before_widget\' => \'<div id="%1$s" class="widget %2$s"><div class="widget-wrap">\',
        \'after_widget\' => \'</div></div>\',
        \'before_title\' => \'<h3 class="widgettitle"><span>\',
        \'after_title\' => \'</span></h3>\',
        ));
    register_sidebar(array (
        \'name\'=>\'Sidebar-Wide - Bottom Right\',
        \'id\'=>\'widget-3\',
        \'before_widget\' => \'<div id="%1$s" class="widget %2$s"><div class="widget-wrap">\',
        \'after_widget\' => \'</div></div>\',
        \'before_title\' => \'<h3 class="widgettitle"><span>\',
        \'after_title\' => \'</span></h3>\',
        ));
    register_sidebar(array (
        \'name\'=>\'Sidebar-Narrow\',
        \'id\'=>\'widget-4\',
        \'before_widget\' => \'<div id="%1$s" class="widget %2$s"><div class="widget-wrap">\',
        \'after_widget\' => \'</div></div>\',
        \'before_title\' => \'<h3 class="widgettitle"><span>\',
        \'after_title\' => \'</span></h3>\',
        ));
    register_sidebar(array (
        \'name\'=>\'Footer Widget 1\',
        \'id\'=>\'widget-5\',
        \'before_widget\' => \'<div id="%1$s" class="widget %2$s"><div class="widget-wrap">\',
        \'after_widget\' => \'</div></div>\',
        \'before_title\' => \'<h3 class="widgettitle"><span>\',
        \'after_title\' => \'</span></h3>\',
    ));

2 个回复
SO网友:zlovelady

尝试restrict categories plugin. 它允许您根据用户角色或单个用户配置在Wordpress管理中可见的类别。

SO网友:denis.stoyanov

这里有一个小片段可以完成这项工作。Found it here.

/*
 * Hide Specified Categories (by ID) from administrators
 */

add_action( \'admin_init\', \'wpse_55202_do_terms_exclusion\' );

function wpse_55202_do_terms_exclusion() {
    //Where is the string \'author\' you need to replace it with your users\' role
    if( current_user_can(\'author\') )
        add_filter( \'list_terms_exclusions\', \'wpse_55202_list_terms_exclusions\', 10, 2 );
}

function wpse_55202_list_terms_exclusions($exclusions,$args) {
    // edit 3 with your category\'s ID
    return $exclusions . " AND ( t.term_id <> 3 ) ";
}

结束