A
A
Alexander Sobolev2021-08-20 12:40:42
WordPress
Alexander Sobolev, 2021-08-20 12:40:42

How to understand in Wordpress whether the required plugin is installed and active?

Hello!
In my code, I need to understand if the Google Doc Embedder plugin is installed and active.
Ok, there is a get_plugins() function where I check if the plugin I need exists, but the output array doesn't contain the path needed for is_plugin_active()
How do I check if a plugin is active or get the path to the plugin I need?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sobolev, 2021-08-20
@san_jorich

Dmitry Alyoshin , thanks for the detailed answer!
1. Not an option, because the path is not known in advance
2. 3. I didn’t quite understand the meaning ..
In general, all this prompted a “bicycle” ..

function es_docsControl(){
    
    $plugins = get_plugins();    $plugin = array_keys($plugins); $needle_plugin = 'Google Doc Embedder';    
    
    foreach($plugin as $path){      
      if( in_array($needle_plugin, $plugins[$path] ) ) {
        if( is_plugin_active( $path )){ return true; } else { return false; }        
      } 
    }    
  }

  add_shortcode('es_docsControl','es_docsControl');

D
Dmitry Alyoshin, 2021-08-20
@ArchitectOfRuin

1. Checking if the plugin is active:

function check_plugin_state(){
    if (is_plugin_active('easy-digital-downloads/easy-digital-downloads.php')){
     echo 'plugin is active';
   }else{
    echo 'plugin is not active';
   }
}
add_action('admin_init', 'check_plugin_state');

2. Checking if there is a certain class:
if(class_exists('Easy_Digital_Downloads')){
   echo 'plugin is active';
}else{
   echo 'plugin is not active';
}

3. Checking if there is a certain function:
if(function_exists('EDD')){
   echo 'plugin is active';
}else{
   echo 'plugin is not active';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question