Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 737193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:41:34+00:00 2026-05-14T07:41:34+00:00

I know I can use activate_plugin() from inside a given, active plugin in WordPress,

  • 0

I know I can use activate_plugin() from inside a given, active plugin in WordPress, to activate another plugin. But what I want to know is how do I programmatically check if that plugin is already active?

For instance, this snippet of code can be temporarily added to an existing plugin’s initial file to activate a partner plugin:

add_action('wp','activatePlugins');

function activatePlugins() {
  if( is_single() || is_page() || is_home() || is_archive() || is_category() || is_tag()) {
    @ activate_plugin('../mypartnerplugin/thepluginsmainfile.php');
  }
}

Then, use a Linux command line tool to spider all your sites that have this code, and it will force a page view. That page view will cause the above code to fire and activate that other plugin. That’s how to programmatically activate another plugin from a given plugin as far as I can tell.

But the problem is that it gets activated over and over and over again. What would be great is if I had an if/then condition and some function I could call in WordPress to see if that plugin is already activated, and only activate it once if not active.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:41:34+00:00Added an answer on May 14, 2026 at 7:41 am

    Here’s the solution:

    http://codex.wordpress.org/Function_Reference/is_plugin_active

    <?php
       if (!is_plugin_active('plugin-directory-path/plugin-file.php')) {
          @ activate_plugin('plugin-directory-path/plugin-file.php');
       }
    

    You can set that plugin-directory-path either to a fixed path, or to a relative path. (Just not a web URL path.)

    Note that wp-admin/includes/plugin.php must be loaded for the above code to work. Therefore, the final solution was:

    add_action('wp','myPluginTool');
    
    function myPluginTool() {
    if( is_single() || is_page() || is_home() || is_archive() || is_category() || is_tag()) {
    
      $sDir = dirname(__FILE__);
      $sDir = rtrim($sDir, '/');
      $sDir = str_replace('/myplugin','',$sDir); // myplugin was folder name of current plugin
      $sDir = rtrim($sDir, '/');
    
      require_once($sDir . '/../../wp-admin/includes/plugin.php');
    
      // DEACTIVATE
      if (is_plugin_active($sDir . '/partnerplugin/partner.php')) {
        deactivate_plugins($sDir . '/partnerplugin/partner.php');
      }
    
      /*
      // ACTIVATE
      if (!is_plugin_active($sDir . '/partnerplugin/partner.php')) {
        activate_plugin($sDir . '/partnerplugin/partner.php');
      }
      */
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 438k
  • Answers 438k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nested types don't work that way. You can't "override" types.… May 15, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer You are missing the right parenthesis. May 15, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer What Sdk are u using? since Android sdk 1.6 the… May 15, 2026 at 4:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.