我希望这段代码只在管理区内运行,因为它也是在公共管理栏上运行的。
/* Reorder Admin Menu to put "Pages" at the top */
function menu_order_filter($menu) {
$content_menu = array(\'edit.php?post_type=page\');
array_splice($menu, 2, 0, $content_menu);
return array_unique($menu);
}
add_filter(\'custom_menu_order\', create_function(\'\', \'return true;\'));
add_filter(\'menu_order\', \'menu_order_filter\');
SO网友:Khadka Pushpendra
Update in 2020, 工作答案,我去了不同的答案,没有一个在新的WordPress中有效。
function hide_categories_for_specific_user( $exclusions, $args ){
if ( ((defined( \'REST_REQUEST\' ) && REST_REQUEST) or $GLOBALS[\'pagenow\'] === \'edit.php\' ) && !current_user_can( \'manage_options\' ) ) {
// IDs of terms to be excluded
$exclude_array = array("12","16","17"); // CHANGE THIS TO IDs OF YOUR TERMS
// Generation of exclusion SQL code
$exterms = wp_parse_id_list( $exclude_array );
foreach ( $exterms as $exterm ) {
if ( empty($exclusions) )
$exclusions = \' AND ( t.term_id <> \' . intval($exterm) . \' \';
else
$exclusions .= \' AND t.term_id <> \' . intval($exterm) . \' \';
}
// Closing bracket
if ( !empty($exclusions) )
$exclusions .= \')\';
// Return our SQL statement
}
return $exclusions;
}
// Finally hook up our filter
add_filter( \'list_terms_exclusions\', \'hide_categories_for_specific_user\', 10, 2 );
回答来自的最终帮助
Hide Some Categories in Post Editor