• Hi, I am having trouble removing submenu page Yoast Premium Workouts anbd Redirects for Editor role. With this code I have been able to remove all Yoast submenu items but the Premium ones like Workouts and Redirects.

    function ia_hide_menu_items_for_editor_in_wpadmin() {
    
    ? ? if (current_user_can('editor')) {
    
    ? ? ? ? remove_menu_page('admin.php?page=ai1ic_settings_page');
    
    ? ? ? ? remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
    
    ? ? ? ? remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu
    
    ? ? ? ? remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php' ); // hide the customizer submenu
    
    ? ? ? ? remove_submenu_page( 'themes.php', 'themes.php?page=ai1ic_settings_page&tab=tab2' );
    
    ? ? ? ? remove_menu_page('wpseo_dashboard'); //Hide "Yoast SEO"
    
    ? ? ? ? remove_menu_page ('admin.php?page=wpseo_redirects', 0);
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_dashboard'); //Hide "Yoast SEO → General"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_page_settings'); //Hide "Yoast SEO → Settings"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_integrations'); //Hide "Yoast SEO → Integrations"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_tools'); //Hide "Yoast SEO → Tools"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_page_academy'); //Hide "Yoast SEO → Academy"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_licenses'); //Hide "Yoast SEO → Premium"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_workouts'); //Hide "Yoast SEO → Workouts"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_redirects'); //Hide "Yoast SEO → Redirects"
    
    ? ? ? ? remove_submenu_page('wpseo_dashboard', 'wpseo_page_support'); //Hide "Yoast SEO → Support"
    
    ? ? ? ? remove_submenu_page('admin.php', 'wpseo_workouts');
    
    ? ? ? ? remove_submenu_page('admin.php', 'wpseo_wpseo_redirects');
    
    ? ? }
    
    }
    
    add_action('admin_head', __NAMESPACE__ . '\\ia_hide_menu_items_for_editor_in_wpadmin');
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Melita Poropat

    (@mebo)

    So I found a solution that works for this case. Basicly added class to body element for logged in user and than with css used display none property. Good enough for now untill Yoast implements something for Premium submenu links in future.

    This is the code:

    //solution based on https://gist.github.com/jancbeck/3178689?permalink_comment_id=3083404#gistcomment-3083404
    
    add_filter("admin_body_class", function($classes) {
    
        $user = wp_get_current_user();
    
        foreach ($user->roles as $user_role) {
    
          $classes .= " user-role-{$user_role}";
    
        }
    
        return $classes;
    
      });
    
    // hide Premium Yoast sub pages for editor
    
    function add_custom_css_for_editor() {
    
        if (is_admin() && current_user_can('editor')) {
    
            echo '<style>';
    
            echo 'body.user-role-editor #toplevel_page_wpseo_workouts {';
    
            echo '    display: none !important;';
    
            echo '}';
    
            echo '</style>';
    
        }
    
    }
    
    add_action('admin_head', __NAMESPACE__ . '\\add_custom_css_for_editor');
    Thread Starter Melita Poropat

    (@mebo)

    Hopefully someone from Yoast will do something for Premium sub menu pages so that we can easily hide it for some users. For now this is considered to be resolved from my perspective

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Not able to remove Premium Redirects and Workout admin pages for Editor role’ is closed to new replies.