Answer the question
In order to leave comments, you need to log in
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
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');
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');
if(class_exists('Easy_Digital_Downloads')){
echo 'plugin is active';
}else{
echo 'plugin is not active';
}
if(function_exists('EDD')){
echo 'plugin is active';
}else{
echo 'plugin is not active';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question