Discussion:
What is the best method to check a theme's dependencies on plugins?
Bjorn Wijers
2009-11-27 13:57:50 UTC
Permalink
Hi there,

I'm working on a theme which is going to be used in conjunction with a
lot of plugins. So naturally I want to make sure these plugins are all
active and ready for my theme to use, but I'm not sure about the best
way to approach this. Oh, and I need to install this theme on a blog
part of a WP MU install. As far as I can see I have two options:

1) Use this solution posted in 2005:
http://jonathanleighton.com/blog/2005/09/13/wordpress-plugin-dependencies/

2) Or do something like this in the functions.php of my theme, which at
the moment does not seem to work (any hints on why it's not working
appreciated).

[code]
/**
* Checks if certain plugins are active before this theme can be used.
* This function is called by the switch_theme() Wordpress action.
*
* @access private
* @param string Theme name
* @return string theme name or stop and display an error message
*/
if( ! function_exists('_bbtheme_check_dependencies') ) {
function _bbtheme_check_dependencies($theme_name) {

// return theme name directly if not using our theme
if( $theme_name !== 'bbtheme' ) { return $theme_name; }

// are plugins we need active and available?
if( ! is_active_plugin('register-plus/register-plus.php') ) {
die (__('Register Plus not active', $bbtheme_txt_domain) );
} else if( ! is_active_plugin('userphoto/userphoto.php') ) {
die (__('User Photo plugin not active.', $bbtheme_txt_domain) );
}
}
}

// upon theme activation check dependencies
add_action('switch_theme', '_bbtheme_check_dependencies');

[/code]

Thanks in advance,
--
met vriendelijke groet,
Bjorn Wijers

* b u r o b j o r n .nl *
digitaal vakmanschap | digital craftsmanship

Concordiastraat 68-126
3551 EM Utrecht
The Netherlands

phone: +31 6 49 74 78 70
http://www.burobjorn.nl
Eric Marden
2009-12-03 22:54:22 UTC
Permalink
Post by Bjorn Wijers
I'm working on a theme which is going to be used in conjunction with a
lot of plugins. So naturally I want to make sure these plugins are all
active and ready for my theme to use, but I'm not sure about the best
way to approach this.
Your best bet is to have the theme gracefully degrade if the plugins
aren't available. Using function_exists around functionality that
depends on a plugin. You could have a custom options screen in the
admin with a checklist for each plugin, helping users set up the theme
properly and maybe even use a sticky notice (like akismet does) to
drive users there after theme activation.


- Eric Marden
__________________________________
http://xentek.net/code/wordpress/
tw: @xentek

Loading...