• I’m trying to create a code in functions.php to:

    • Enable a plugin if there’s any user online (any user, not only if the current visitor is logged in)
    • Disable a plugin if there’s
      no user online

    So I made:

    function deactivate_plugin_conditional() {
        if (is_user_logged_in()) {
        	activate_plugins('online-chat/online-chat.php');
        	}
        if (!is_user_logged_in()) {
            deactivate_plugins('online-chat/online-chat.php');
        	}
        }
        add_action( 'admin_init', 'deactivate_plugin_conditional' );

    But it doesn’t works quite right, since is_user_logged_in is a condition relative to the current visitor, and I need a global condition… If there’s any user online, activate plugin. If not, deactivate plugin.

    The reason: Registration in this website is restricted, there’s only one user, and this is a chat plugin… So, the chat will only be enabled if the admin is online and available to chat, otherwise it won’t show up!

    edit: So, I was looking at online-chat.js and found this code:

    if($chatElements.userList.children('li').length < 1){
    		$('#oc-no-users-online-notice').show();
    	} else {
    		$chatElements.userList.children('li.online, li.active').on('click',activateOpenChat);
    	}

    Is there a way to deactivate and activate the plugin withing the js?

The topic ‘Deactivate plugin via javascript or functions.php?’ is closed to new replies.