• Resolved SS88 LLC

    (@ss88_uk)


    Hi @yiannistaos,

    Thank you for this plugin. It’s super simple to use!

    I have one request, can you please remove enqueuing the CSS and JavaScript code if no one is logged into the website?

    Currently, I’m using this code to achieve it:

    add_action('wp_enqueue_scripts', function() {

    if(!is_user_logged_in()) {

    wp_dequeue_style('login-as-user');
    wp_dequeue_script('login-as-user');

    }

    }, 999);

    Thanks!
    Sully

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Yiannis Christodoulou

    (@yiannistaos)

    Hey @ss88_uk ????

    Thank you so much for your kind words and the suggestion.

    Good point! ?? I will include this in the upcoming release. But can you try this first?

    Please, edit the file /wp-content/plugins/login-as-user/includes/class-w357-login-as-user.php (line 468), and replace the function enqueue_styles() with the code below, and let me know if that worked, please.

    public function enqueue_styles() {
    $options = get_option('login_as_user_options', array());
    $message_display_position_option = (!empty($options['message_display_position'])) ? $options['message_display_position'] : 'top';
    $show_admin_link_in_topbar_option = (!empty($options['show_admin_link_in_topbar'])) ? $options['show_admin_link_in_topbar'] : 'yes';

    // do not proceed if user is not logged in
    $old_user = $this->get_old_user();
    if ($old_user instanceof WP_User && ($message_display_position_option !== 'none' || $show_admin_link_in_topbar_option === 'yes')) {
    wp_enqueue_style('login-as-user', plugin_dir_url(dirname(__FILE__)) . 'public/css/public.min.css', array(), LOGINASUSER_VERSION, 'all');
    wp_enqueue_script('login-as-user', plugin_dir_url(dirname(__FILE__)) . 'public/js/public.min.js', array('jquery'), LOGINASUSER_VERSION, false);
    wp_register_style('login-as-user-inline-style', false);
    wp_enqueue_style('login-as-user-inline-style');
    }
    }

    Thanks ??

    Thread Starter SS88 LLC

    (@ss88_uk)

    Hi @yiannistaos,

    That work for me — thank you!

    Sully.

    Plugin Author Yiannis Christodoulou

    (@yiannistaos)

    Hi @ss88_uk,

    Thanks for your suggestion ??

    https://www.web357.com/blog/releases/login-as-user-wordpress-plugin-v1-5-4-released

    02-Oct-2024 : v1.5.4 =
    * Optimized Asset Loading: Prevent CSS and JavaScript files from being enqueued when no user is logged into the site, improving performance. (Thanks to "ss88_uk" for the suggestion!)
    * Update: Removed the includes/plugin-update-checker folder from the free version.
    * Fully compatible with WooCommerce v9.3.x.
    * Role-Based Login Management: Added functionality to define which user roles have the ability to log in as users of other roles. For example, Administrators can be configured to log in as any user with the roles of Customer or Shop Manager, while Office Managers can log in as users with the Author role. [Pro version]
    * Minor stability and performance improvements.
    Thread Starter SS88 LLC

    (@ss88_uk)

    Thank you @yiannistaos!

    Have a great weekend!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.