How to make plugin required in a wp theme without using php conditional statements when calling an individual function from that plugin?

is_plugin_active() is rather fragile: it will break when either the plugin author renames the main file or when the user renames the plugin’s directory or main file. It’s better to check if a certain public function exists.

To avoid having to make that check each time you need some of the plugin’s functionality, you could show a message in the admin area:

add_action( 'admin_notices', 'my_theme_dependencies' );

function my_theme_dependencies() {
  if( ! function_exists('plugin_function') )
    echo '<div class="error"><p>' . __( 'Warning: The theme needs Plugin X to function', 'my-theme' ) . '</p></div>';
}

Another alternative is to use something like http://tgmpluginactivation.com/

Leave a Comment