Edit: Updated for WordPress 4.9+ and increased compatibility with PHP <= 5.4
WordPress核心不提供本机disable the theme customizer的钩子,但有一种聪明而优雅的方法通过改变全局$子菜单变量从外观菜单中删除“自定义”链接:
/**
* Remove Admin Menu Link to Theme Customizer
*/
add_action( 'admin_menu', function () {
global $submenu;
if ( isset( $submenu[ 'themes.php' ] ) ) {
foreach ( $submenu[ 'themes.php' ] as $index => $menu_item ) {
if ( in_array( array( 'Customize', 'Customizer', 'customize' ), $menu_item ) ) {
unset( $submenu[ 'themes.php' ][ $index ] );
}
}
}
});
虽然此处和其他地方的其他代码示例不负责任地依赖于全局$子菜单变量的特定数字索引(例如$submenu [‘themes.php’] [6] [0],…),但此方法会智能地遍历层次结构,因此它应该与旧的(3.x)和更新版本的WordPress(4.x)兼容.