• garcia2

    (@garcia2)


    Does anyone know if we can hide the top admin bar purge all button for specific user roles like authors? I wanna keep it for admins but stop normal writers from randomly clearing the entire cache. Any tips?

Viewing 1 replies (of 1 total)
  • Plugin Support litetim

    (@litetim)

    @garcia2
    Try this code(I added in theme functions.php):

    add_action( 'admin_bar_menu', 'lsc_remove_bar_menu', 99999 );

    add_action( 'wp_before_admin_bar_render', 'lsc_remove_bar_menu', 99999 );

    function lsc_remove_bar_menu( $admin_bar ) {

            global $wp_admin_bar;

            // Roles that should LOSE the purge controls.

            $hide_for_roles = array( 'editor', 'shop_manager' );

            $user = wp_get_current_user();

            if ( ! array_intersect( $hide_for_roles, (array) $user->roles ) ) {

                    return; // not a targeted role -> leave everything

            }

            if ( $wp_admin_bar->get_node( 'litespeed-menu' ) ) {

                    $wp_admin_bar->add_node( array(

                            'id'   => 'litespeed-menu',                       // existing args are kept (merge)

                            'href' => admin_url( 'admin.php?page=litespeed' ),

                    ) );

            }

            // Remove every purge entry (covers both admin + front-end node ids).

            $purge_nodes = array(

                    'litespeed-purge-all',

                    // 'litespeed-purge-all-lscache',

                    // 'litespeed-purge-cssjs',

                    // 'litespeed-purge-cloudflare',

                    // 'litespeed-purge-object',

                    // 'litespeed-purge-opcache',

                    // 'litespeed-purge-ccss',

                    // 'litespeed-purge-ucss',

                    // 'litespeed-purge-localres',

                    // 'litespeed-purge-placeholder',

                    // 'litespeed-purge-vpi',

                    // 'litespeed-purge-avatar',

                    // 'litespeed-purge-single',

                    // 'litespeed-purge-single-ucss',

                    // 'litespeed-single-action',

            );

            foreach ( $purge_nodes as $id ) {

                    $wp_admin_bar->remove_node( $id );

            }

      }


Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.