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.