Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION if plugin is active ...
#1
Question 
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?
Reply
#2
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);

NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
(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.
Reply
#4
well no it just checks if a plugin is active
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
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'); } ?>
Reply
#6
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.
Reply
#7
The you just add an else{}
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#8
Ok thanks, I see if I can make it work..
Reply
#9
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 ?>
Reply
#10
Yeah like Carlos said, that's probably the best option if you are about to call the functions especially.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)