• Resolved wpfan1000

    (@wpfan1000)


    Hi,

    I would like to hide the Page SEO Settings (With eg Title and Description fields) metabox in editor based on:

    1) Role of current user

    2) Current post type

    Is this possible?

    Thanks ahead of time…..

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi again 🙂

    I think this will do!

    add_action( 'current_screen', function() {
    	// If TSF is inactive, don't do anything.
    	if ( ! function_exists( 'the_seo_framework' ) || ! the_seo_framework()->loaded )
    		return;
    
    	// Set excluded post types.
    	$excluded_post_types = [
    		'movie',
    		'book',
    	];
    	// Set required capability.
    	$required_cap = 'manage_options';
    
    	$current_screen = get_current_screen();
    
    	// Test conditions
    	if ( ! current_user_can( $required_cap )
    	|| isset( $current_screen->post_type ) && in_array( $current_screen->post_type, $excluded_post_types, true )
    	) {
    		// Disables all scripts, and rendering of the meta box.
    		add_filter( 'the_seo_framework_post_type_disabled', '__return_true' );
    
    		// Security: Don't allow the user to overwrite data, either.
    		remove_action( 'save_post', [ the_seo_framework(), 'inpost_seo_save' ], 1 );
    		remove_action( 'save_post', [ the_seo_framework(), '_save_inpost_primary_term' ], 1 );
    	}
    } );
    

    Note that you can disable SEO for post types entirely on the SEO Settings page, within the General Settings meta box. Disabling like that will also remove all metadata.

    Thread Starter wpfan1000

    (@wpfan1000)

    That looks like a great solution.
    Thanks very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide the Page SEO Settings metabox in editor’ is closed to new replies.