get_user_meta()
是的包装器get_metadata()
. 如果触发此问题,询问用户是否可以使用富编辑器,您可以通过该调用禁用它。
<?php
/**
* Plugin Name: (#116210) Disable RichEdit by User or Role
* Author: Franz Josef Kaiser <[email protected]>
*/
defined( \'ABSPATH\' ) OR exit;
add_filter( \'get_user_metadata\', \'wpse116210VisualEditorDisabled\', 20, 4 );
function wpse116210VisualEditorDisabled( $enabled, $object_id, $meta_key, $single ) {
if ( ! is_admin() )
return $enabled;
// Conditional switch for different post types
if ( \'post\' === get_current_screen()->post_type )
{
$user = wp_get_current_user();
// Check here if you want *that* user/role to be enabled/disabled.
$enabled = FALSE;
}
return $enabled;
}
另一种选择可能是使用
WP_Role#has_cap
检查(以防在那里使用)。它还有一个过滤器:
\'role_has_cap\'
<?php
/**
* Plugin Name: (#116210) Disable RichEdit by Role
* Author: Franz Josef Kaiser <[email protected]>
*/
defined( \'ABSPATH\' ) OR exit;
add_filter( \'role_has_cap\', \'wpse116210RoleHasCap\' );
function wpse116210RoleHasCap( $allCaps, $checkedCap, $roleName )
{
$role = get_role( $roleName );
// Do your check if you want to allow it. Return *boolean*.
return $allCaps[ $checkedCap ];
}