WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[resolved] Remove seo for roles lower then administrator (3 posts)

  1. shmk
    Member
    Posted 2 years ago #

    Is it possible to remove the SEO box inside Pages and Posts for roles lower than admin?

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

    No, although it will be possible to remove the advanced tab in an upcoming version.

  3. boxcarpress
    Member
    Posted 2 years ago #

    I had this need when using WordPress SEO in conjunction with Revisionary. Revisionary allows moderation of user-submitted corrections, but unfortunately didn't allow moderation of the titles and descriptions set in WordPress SEO. This allowed any user with a "Revisor" role to alter the title or description of the page, unmoderated.

    I added the following code to my theme's functions.php to remove the admin bar and meta boxes (that alter WordPress SEO settings for a post/page) for all Revisor users:

    function wpu_check_role( $role_to_check ){
    	//check to make sure pluggable.php and user.php have been loaded at this point
    	if (function_exists( 'is_user_logged_in' ) && function_exists( 'get_current_user_id' ) ) {
    			//check that user is logged in
    		if ( is_user_logged_in() ) {
    			//load user from logged-in user id
    			$user_ID = get_current_user_id();
    			$user = new WP_User( $user_ID );
    			//not sure why there would be more than one role, but let's iterate through it just in case there's a reason
    			if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    				foreach ( $user->roles as $role ) {
    					//return true if we have a match
    					if( $role == $role_to_check ) {
    						return true;
    					}
    				}
    			}
    		}
    	}
    	//no match found
    	return false;
    }
    
    if( wpu_check_role( 'revisor' ) ) {
    	//remove the seo forms when editing posts
    	remove_all_actions( 'add_meta_boxes' );
    	//remove the seo admin bar item (which just gave an access error when clicked)
    	remove_all_actions( 'admin_bar_menu' );
    }

    Hope this helps others in a similar situation.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic