Я работаю на многостраничном сайте wordpress, но этот вопрос имеет значение для регулярного использования в WordPress.
Как я могу скрыть определенные боковые панели определенных групп пользователей (например, редакторов или администраторов)? Я уже пробовал тривиально:
if(is_admin() && user_can(...)){ register_sidebar... }
Но это не скрывает боковую панель, это показывает, что эта боковая панель неактивна, и редактор, если на то пошло, все еще может втягиваться и выходить, как ему нравится.
Благодарю.
Я предполагаю, что вы хотите ограничить доступ к редактированию боковой панели в интерфейсе администратора, а не удалять ее по теме.
Не углубляясь в то, как функции виджета / боковой панели функционируют за кулисами, лучше всего будет играть с глобальным $wp_registered_sidebars
. Однако ключ – когда – слишком рано, а шаблон wp-admin / widgets.php увидит недостающую боковую панель и переместит ее на боковую панель «Неактивные боковые панели». Слишком поздно и, ну, вы не получите никакого эффекта.
add_action('widgets_admin_page', 'sidebar_capabilities'); /** * Keep in mind that you can certainly create custom * capabilities for your sidebars. You could create a loop * that generates new capabilities for each sidebar and assigns them * to admin. You could then manage those capabilities for other * users with the Members plugin by Justin Tadlock */ function sidebar_capabilities(){ global $wp_registered_sidebars; //Remove the comment lines to see the global variable structure. //print_r($wp_registered_sidebars); //Use whatever capabilities you want. //To test as admin, just put junk text for the cap. if(is_admin() && !current_user_can('edit_plugins')){ //This sidebar name is from the twenty-ten theme. unset($wp_registered_sidebars['primary-widget-area']); } }
неadd_action('widgets_admin_page', 'sidebar_capabilities'); /** * Keep in mind that you can certainly create custom * capabilities for your sidebars. You could create a loop * that generates new capabilities for each sidebar and assigns them * to admin. You could then manage those capabilities for other * users with the Members plugin by Justin Tadlock */ function sidebar_capabilities(){ global $wp_registered_sidebars; //Remove the comment lines to see the global variable structure. //print_r($wp_registered_sidebars); //Use whatever capabilities you want. //To test as admin, just put junk text for the cap. if(is_admin() && !current_user_can('edit_plugins')){ //This sidebar name is from the twenty-ten theme. unset($wp_registered_sidebars['primary-widget-area']); } }