• Resolved 03131189

    (@03131189-1)


    Hello!

    I would like to turn off the chat for specific users (users with an specific role). Is that possible? and if not, would it be possible that you add a hook in the ‘render’ function of the TrackingCodeHelper class?, something like this:

    
    $manuallyDisabled = apply_filters( 'livechat_disablechat', false );
    if (!$manuallyDisabled|| !$settings['disableMobile'] || ($settings['disableMobile'] && !$check_mobile)) {
    

    This way i could create a custom plugin that hooks to livechat_disablechat to turn the chat off whenever i want.

    • This topic was modified 6 years, 3 months ago by 03131189.
Viewing 1 replies (of 1 total)
  • Plugin Author LiveChat

    (@livechat)

    Hello @03131189-1,

    Krzysztof here, form LiveChat’s Technical Department. At the moment, we do not have the possibility to disable the plugin for users with specific role but there’s a workaround that we can offer.

    We have prepared a small chunk of code that will allow you to disable the plugin for specified role. All that you have to do is to create a new .php file, like disable-plugins.php. After creating such file, add to it the following code:

    <?php
    /*
    Plugin Name: Disable Plugins
    */
    
    add_filter( 'option_active_plugins', 'disable_logged_in_plugin' );
    
    function disable_logged_in_plugin( $plugins ) {
    
        // The 'option_active_plugins' hook occurs before any user information get generated,
        // so we need to require this file early to be able to check for logged in status
        require (ABSPATH . WPINC . '/pluggable.php');
    
        // Get user's role
        $user = wp_get_current_user();
    
        // If we user's role is admin
        if ( in_array( 'administrator', (array) $user->roles ) ) {
    
            // Use the plugin folder and main file name here.
            // is used here as an example
            $plugins_not_needed = array ('wp-live-chat-software-for-wordpress/livechat.php');
            foreach ( $plugins_not_needed as $plugin ) {
                $key = array_search( $plugin, $plugins );
                if ( false !== $key ) {
                    unset( $plugins[ $key ] );
                }
            }
        }
    
        return $plugins;
    }

    After adding a code, just save changes made to your new disable-plugins.php file and add it to the following directory in your WordPress root:
    /wp-content/mu-plugins/.

    That should disable the LiveChat plugin for users with the administrator role. Also, you can modify the role based on your specific use case, by modifying the following line of code:
    if ( in_array( 'administrator', (array) $user->roles ) )

    @03131189-1, I hope that we were able to help! In case of any additional questions or concerns, don’t hesitate to ask!

    Best regards,
    Krzysztof from LiveChat

Viewing 1 replies (of 1 total)
  • The topic ‘Turn off the chat for specific users’ is closed to new replies.