-
-
Wordpress Designer theme guide on implementing plugins for public release.
A good theme designer should avoid the need to relies on third party plugins.Is plugin deactivated
Unfortunately, some WordPress theme out there has a “major pending headache” for plugin dependencies breakdown sydrome. Because of this un-friendly trends there is bound shit to happen when the specific plugin is not maintain properly or on certain case of a sudden WordPress upgrade render the plugin useless (this happen a lot when previous WP 2.3 release). To make it worse some ignorant-end-user decide “not to” upgrade their WordPress blog because their favorites theme’s has this specific plugins that will only work with previous vulnerability WordPress version & thus the never ending quotes war begin.
Theme with Plugin dependencies
From the smashing lists of “10 Fresh, Elegant and Clean Wordpress Themes“ there is 3 out of 10 theme with plugins dependencies issue. These threesome is an experienced theme designer. How many wordpress theme with plugin dependencies is out there?
So what’s the point of having clean & elegant theme if it doesn’t properly work and throw “Fatal Error” when certain plugin is deactivated.
Similar issue
Before you asked why you need to write better plugin support read on the following articles at WTC.
- Plugin Deactivation Issues by Ronald Huereca
- If Plugin Deactivation Breaks Your Blog by Jeff Chandler Jeffro2pt0.
Introduction
This guide is intent for WordPress theme designer in hope to improve theme quality and avoid plugin dependencies.
Wordpress Hook
As this is a “quick guide” so I wont cover this broad topics. It might take sometimes to understand the concept still its worth the time. You can read it at WordPress Codex ↓
Avoid Plugin dependencies best practice guide
Lets assume you want to add Lester Chan advanced pagination plugin (Wp-pagenavi) in your theme.
Fallback function
1) First we created a default function for the page navigation links (the next & previous page links). Saved it inside functions.php in your theme folder /wp-content/themes/mytheme/.
functions.php
function wpi_post_link() { next_posts_link(__('« Older Entries','mytheme-name')); echo ' '; previous_posts_link(__('Newer Entries »','mytheme-name')); }Tips: to avoid duplicated function name conflict, its a good practice to have your own unique prefix for function name , ( i.e., wpi_get_time, themename_foo )
HTML & Action Hook Placement
2)Next we add our pagination hook (wpi_pagination) inside index.php templates ( & similar templates files i.e., home.php, category.php, archive.php ) .
index.php
<!-- pagination --> <div id="pagination" class="border clear-both"> <?php do_action('wpi_pagination');?> </div>Example using default (kubrick) wordpress theme index.php templates files.
(kubrick) index.php
<?php get_header(); ?> <div id="content" class="narrowcolumn"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> </div> <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> </div> <?php endwhile; ?> <!-- pagination --> <div id="pagination" class="border clear-both"> <?php do_action('wpi_pagination');?> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php include (TEMPLATEPATH . "/searchform.php"); ?> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>is plugin active (optional)
3) For earlier version of WordPress (version 2.3.x & below) you will need to add the following function.
functions.php
if (version_compare($GLOBALS['wp_version'], '2.5', 'lt')) { function is_plugin_active($plugin_filename) { $plugins = get_option('active_plugins'); if( !is_array($plugins) ) settype($plugins,'array'); return ( in_array($plugin_filename, $plugins) ) ; } }Register Action Hook
4) Open your wp-content/themes/mytheme/functions.php and add the below code.
functions.php
add_action('wpi_pagination', ( is_plugin_active('wp-pagenavi/wp-pagenavi.php') ) ? 'wp_pagenavi' : 'wpi_post_link' );Download example code
Conclusion
If you are one’s of those aspiring WP theme designer “do try” not to depend on third party plugins and avoid using the below phrase if possible
“requires the following plugins to work …”
A public release theme should be “clean from plugin dependencies” and let the end user decide what plugins they need and should have.
External Links
-
- June 8, 2008 at 11:06 am
- June 30, 2008 at 5:24 pm
- 0.3
- url
-
-
-
4 Responses to “Themes plugin dependencies”
Trackback URL: Use the TrackBack url ↑ to ping this article. If your blog does not support Trackbacks you might want to leave a comment instead.
-
-
"write as if you were talking to a good friend (in front of your mother)."
.haveyoursay
Disclaimer: For any content that you post, you hereby grant to Kaizeku Ban the royalty-free, irrevocable, perpetual, exclusive and fully sublicensable license to use, reproduce, modify, adapt, publish, translate, create derivative works from, distribute, perform and display such content in whole or in part, world-wide and to incorporate it in other works, in any form, media or technology now known or later developed. Some rights reserved.
-
Amazing article - you're totally right.
Hello
I am trying to use your code on my test site but I have an error message saying : call to undefined function "is_plugin_active" in functions.php
I have try different things but without succes.
Apologize for my poor english,
Michel.
@micheal if you are using wordpress version less than 2.5 you should add the following code inside your theme's functions.php
function is_plugin_active($plugin_filename){$plugins = get_option('active_plugins');
if( !is_array($plugins) ) settype($plugins,'array');
return ( in_array($plugin_filename, $plugins) ) ;
}
Thanks CK
but I always have the same message :
Fatal error: Call to undefined function is_plugin_active() in C:\xampp\htdocs\wordpress\wp-content\themes\veritas\functions.php on line 27
PS: I am using WP 2.6 on a local install (xampp).
Have a good day.