Created
October 24, 2017 20:54
-
-
Save omniacode/94f3452ad1e278b895e0ff8b42526fa2 to your computer and use it in GitHub Desktop.
Remove Yoast Metabox for Everyone Except Admins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Removes the Yoast Metabox for Roles other then Admins | |
// Returns true if user has specific role | |
function check_user_role( $role, $user_id = null ) { | |
if ( is_numeric( $user_id ) ) | |
$user = get_userdata( $user_id ); | |
else | |
$user = wp_get_current_user(); | |
if ( empty( $user ) ) | |
return false; | |
return in_array( $role, (array) $user->roles ); | |
} | |
// Disable WordPress SEO meta box for all roles other than administrator and seo | |
function wpse_init(){ | |
if( !( check_user_role( 'seo' ) || check_user_role( 'administrator' )) ) { | |
// Remove page analysis columns from post lists, also SEO status on post editor | |
add_filter( 'wpseo_use_page_analysis', '__return_false' ); | |
// Remove Yoast meta boxes | |
add_action( 'add_meta_boxes', 'disable_seo_metabox', 100000 ); | |
} | |
} | |
add_action('init', 'wpse_init'); | |
function disable_seo_metabox() { | |
remove_meta_box( 'wpseo_meta', 'post', 'normal' ); | |
remove_meta_box( 'wpseo_meta', 'page', 'normal' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really thx !