GetSimple Support Forum

Full Version: if plugin is active ...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I forgot where to find certain info regarding theme building.

What if you want to set certain code in your theme depending if a plugin is active, what code do you use?
no function in 3.3.x
but you would do it like this.

PHP Code:
/**
 * check if a plugin is active
 * determine if a plugin is active
 *
 * @since 3.4
 * @param  string $pluginid
 * @return bool   returns true if active
 */
function pluginIsActive($pluginid){
    GLOBAL 
$live_plugins;
    return isset(
$live_plugins[$pluginid.'.php']) && ($live_plugins[$pluginid.'.php'] == 'true' || $live_plugins[$pluginid.'.php'] === true);

(2015-05-21, 05:05:42)shawn_a Wrote: [ -> ]no function in 3.3.x
but you would do it like this.



PHP Code:
/**
 * check if a plugin is active
 * determine if a plugin is active
 *
 * @since 3.4
 * @param  string $pluginid
 * @return bool   returns true if active
 */
function pluginIsActive($pluginid){
 GLOBAL 
$live_plugins;
 return isset(
$live_plugins[$pluginid.'.php']) && ($live_plugins[$pluginid.'.php'] == 'true' || $live_plugins[$pluginid.'.php'] === true);


Ok, thanks. Although I don't really understand the code. It is for activating a plugins specific code in a theme, but only if plugin exist. I think I just make a separate template file.
well no it just checks if a plugin is active
To use shawn_a's function you should just do like this:

PHP Code:
<?php if (pluginIsActive('i18n_base')) { ?>
  <div>You can only see me if i18n_base plugin is activated</div>
<?php ?>

Or in a template file: 
PHP Code:
<?php if (pluginIsActive('i18n_base')) { include('mytemplate.php'); } ?>
Thanks, but I want to do a certain thing instead of another (default) thing. So if plugin is active, do this, if not, do something else.
The you just add an else{}
Ok thanks, I see if I can make it work..
Another way to know if a plugin is (or isn't) active is checking for some of the plugin's functions (that is available to the frontend), e.g.
PHP Code:
<?php if (!function_exists('i18n_init')) { ?>
   <p>I18N plugin not activated!</p>
<?php ?>
Yeah like Carlos said, that's probably the best option if you are about to call the functions especially.