• Resolved mme

    (@mme)


    Hi,

    I keep getting this error when putting this in my plugin:

    Fatal error: Call to undefined function is_plugin_active() in /home/xxxx/xx

    if (is_plugin_active('wplite/wplite.php')) {
    wp_get_current_user();
    if ($current_user->user_login=="Webmaster") {
    remove_action('admin_menu', 'wplite_disable_menus');
    remove_action('admin_head', 'wplite_disable_metas');
    }}

    Why is this happening?

Viewing 8 replies - 1 through 8 (of 8 total)
  • +1 I am getting the same Fatal error. Also, I don’t see is_plugin_active in functions.php for WP v3.0.1. Has this function been eliminated from this latest WP version? –Bill

    Thread Starter mme

    (@mme)

    Hi,

    I have found a website that shows a workaround maybe not the best but it works:

    https://webdesign.onyou.ch/2010/07/28/check-if-a-wordpress-plugin-is-active/

    Thanks,

    mme

    Mme-
    Great- thanks for sharing your find.

    I am checking several plugins, so I’m using a variable to allow the code to be repeated (changing only the var $plugin_var name being tested).

    <?php
      $plugin_var= "relevanssi";
      if (in_array( $plugin_var.'/'.$plugin_var.'.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) echo " (active plugin: ".$plugin_var.")";
    ?>

    This solution works just fine. Thanks! –Bill

    Thread Starter mme

    (@mme)

    You would probably be better off making a function of it then:

    <?php
    function plugin_is_active($plugin_var) {return in_array( $plugin_var. '/' .$plugin_var. '.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ); }
    ?>

    This code is untested so it may contain some errors.

    Place in the ‘functions.php’ in your theme file.

    to run just call the following:

    plugin_is_active('plugin_name')

    Hope that helps,

    Regards,

    mmd

    Mme-
    Good idea, a function is definitely more flexible (and reusable). Your function code works as written; I just added a temporary variable to be assigned the in_array function, and then be returned by function plugin_is_active.

    <?php
      function plugin_is_active($plugin_var) {
        $return_var = in_array( $plugin_var. '/' .$plugin_var. '.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
        return $return_var;
      }
    ?>

    Appreciate your references and ideas. –Bill

    Thanks for the function, which was exactly what I needed, since the is_plugin_active() function from WordPress led to a fatal error.

    One suggestion, though: I reckon the function will not find plugins that are located in a subdirectory with a different name as the actual php-file, e.g. “disqus-comment-system/disqus.php”.

    I changed it to this (very simple):

    <?php
      function plugin_is_active($plugin_path) {
        $return_var = in_array( $plugin_path, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
        return $return_var;
      }
    ?>

    You’ll have to provide the complete relatve path within your plugins-directory e.g. as the aforementioned “disqus-comment-system/disqus.php”.

    I also received a similar fatal error and instead of writing a new function from scratch I opened /wp-admin/includes/plugin.php and copy/pasted (and prefixed) the function code for is_plugin_active into my theme’s functions.php file:

    function mythemename_is_plugin_active( $plugin ) {
        return in_array( $plugin, (array) get_option( 'active_plugins', array() ) );
    }

    And the code I used to call it:

    if ( mythemename_is_plugin_active('plugin-directory/plugin.php') )
        echo "ACTIVE";

    Not all that different from some of the aforementioned solutions, but I thought it’d be nice to mention.

    It is important to understand when this fatal error occurs. The Codex clearly states that this function is available within admin pages only. This is why checking if plugin in question is in the resulting array of get_option( ‘active_plugins’ ) should be a preferred method.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘is_plugin_active’ is closed to new replies.