WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Detecting already installed plugins (6 posts)

  1. mogman1
    Member
    Posted 5 years ago #

    I'm writing a plugin and I've noticed that when another plugin is installed, specifically Dean's FCKEditor for WordPress, parts of mine break. I'm trying to work with the author of that plugin to find a solution, but there's a chance I might not find one or get a response. In the meantime, I have a solution that can work around it, but it's not very elegant. Thus I'd only like that workaround to show up if and only if the FCKEditor is installed.

    Is there some way to access a list of installed plugins, specifically from the context of page/post editor pages, to check if that specific plugin is installed?

  2. Roger Theriault
    Member
    Posted 5 years ago #

    I wrote this for my plugin... feel free to change the function name so you don't collide with mine. Not guaranteed 100% if a user has customized the plugin's directory name.

    Usage: gre_is_plugin_there('/great-real-estate')

    function gre_is_plugin_there($plugin_dir) {
    	$plugins = get_plugins($plugin_dir);
    	if ($plugins) return true;
    	return false;
    }
  3. Ogre
    Member
    Posted 5 years ago #

    Not all plugins live inside a subdirectory. Some are bare .php files.

  4. mogman1
    Member
    Posted 5 years ago #

    Thanks for the suggestion. That led me to the is_plugin_active() function (searching through the source myself) and then to the option that WordPress itself sets that contains an array of active plugins. I looked through the list of options to start with (thinking there must be something there) but missed it in the horde of options to be found. I can just grab that option, and check against it for some derivative of the plugin I'm looking for. I spent close to an hour looking for something like this, the WordPress codex can be a pain sometimes.

  5. Roger Theriault
    Member
    Posted 5 years ago #

    The code I posted should detect even inactive plugins and presumes you know which one you're looking for; some of the other functions only work with active plugins. A perusal of wp-admin/plugins.php may help in understanding how to accumulate a list of plugins, and determining their status. By the way, get_plugins() with no arguments is supposed to return a list of all detected plugins.

    Part of the Codex problem is search. Sometimes Google is better for that, it even has Trac changelog pages indexed. Assuming you have worked out the right terms to search for :-) But there's nothing better than the actual code.

  6. jsherk
    Member
    Posted 5 years ago #

    I am writing a mod and it needs to know if specific plugin is activated or not. The following code will deterine if any plugin is activated or deactivated, you just need to put the plugins directory (if it uses one) and the main plugin file name (including the .php).

    For example, I needed to find out if the Post Notification plugin was active... it's directory within the plugins directory is called 'post-notification', and the main file is called 'post_notification.php'

    <?php
    $plugin_name = 'post-notification/post_notification.php';
    $is_active = is_plugin_active($plugin_name);
    if ($is_active == '1') {
      echo '<span style="color: green;">ACTIVE!</span>';
    } else {
      echo '<span style="color: red;">Deactivated.</span>';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic