WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Execute plugin if EDITOR is online (8 posts)

  1. Lucas
    Member
    Posted 1 year ago #

    The problem

    I have a CHAT plugin for wordpress, I would like it to be active only when administrator (EDITOR, to be more precise) is online. When the admin is offline there's no use to have a chat on the website, it only consume space.

    Possible Sulutions

    I know little of PHP/Wordpress programming, but I'm almost sure some kind of code in Functions.php might solve the problem, something with admin_init, but it has to disable when admin logs off too.

    Conclusion

    Desired administration role to activate the plugin: Editor

    Plugin name: Online Chat (online-chat/online-chat.php)

    WordPress Version: 3.4.2

    Thanks guys!! I'll be around, trying to make it work here too

  2. I have a CHAT plugin for wordpress

    Is it one here (link please)? Much of the functionality of plugins is added via add_action or add_filter. Using conditional in your functions.php file could let you remove that chat code if the person is not the correct user role.

  3. Lucas
    Member
    Posted 1 year ago #

  4. I was really wishing that you'd have a plugin that is in the WordPress repository here. Your best option would be to contact the plugin author and ask him.

    http://codecanyon.net/user/geosith

    We don't have access to commercial plugin software like that (don't want access either). Once you figure out how that's added then you can write another plugin or edit your theme's functions.php file so that it's removed from the add_action or add_filter and re-added after checking the user role.

  5. Lucas
    Member
    Posted 1 year ago #

    Hmm, but let's suppose that's the code:

    add_action( 'init','oc_init',1);

    How would I adapt it to my needs? :3

  6. Lucas
    Member
    Posted 1 year ago #

    Ok, I'm almost done with it!!

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

    I just need a "if" condition for editor online!! If userid 1 is online, or something like that!

  7. Lucas
    Member
    Posted 1 year ago #

    I think I MADE IT!

    function deactivate_plugin_conditional() {
    if (!is_user_logged_in()) {
        if ( is_plugin_active('online-chat/online-chat.php') ) {
        deactivate_plugins('online-chat/online-chat.php');
        }
    	}
    if (is_user_logged_in()) {
    	activate_plugins('online-chat/online-chat.php');
    	}
    }
    add_action( 'admin_init', 'deactivate_plugin_conditional' );
  8. That's along the lines I was going to suggest. Keep at it you're doing fine. :)

Topic Closed

This topic has been closed to new replies.

About this Topic