Feeds

plugins

 Integrating Plugins With Your WordPress Themes Using functions.php

Submitted by nathanrice on May 22, 2007 - 8:09pm in

Have you ever been browsing through the theme viewer or checking out the daily theme release announcements over at WeblogToolsCollection.com, and noticed that a certain theme requires a plugin to function correctly (or at least has a feature that requires a plugin to work)? I certainly have, and although I have never required a plugin for any themes I've released, I can see why one would want to include the functionality of a plugin to make that theme even more awesomely cool (and perhaps get more downloads).

But it is generally frowned upon to require the user to download and install a plugin in order for your theme to work properly. So what is a designer to do? Of course, he could just try to figure out what the plugin does by examining the code, but most designers don't have a working knowledge of PHP/MySQL. Another option is to just remove the feature from your theme, but that means you lose that super-cool feature that might have set your theme apart from the others.

Thankfully, there is a solution that is actually quite simple.

A while back, I was working on a custom design for a client, and he requested a very long list of features that were beyond what I could do with a vanilla WordPress install. So naturally, I hit google up for any plugins that would give me the functionality he was looking for. But again, I wanted to deliver a fully functional theme to this client, without having to instruct him to install a list of plugins to get the theme working properly.

After thinking for a while, it hit me: just copy the code from the plugin into the functions.php file of the WordPress theme. I did so, and it worked like a charm! Absolutely no plugins were activated, and I was able to deliver a theme that worked perfectly right out of the box.

A few possible limitations to this method.

I'm not sure about this, but some plugins do add new rows/columns/tables to your database. There is a possibility that a plugin will do this upon activation, and may not work as an integrated function in the functions.php file. Again, I'm not sure about this.

Also, plugins with multiple files, especially plugins that require you place files/folders in multiple locations, probably won't be easily integrated into your theme. Plugins that only require a single file upload are best.

A few extra tips

  1. Be sure to keep the plugin information in tact when copying the content of a plugin file over to your functions.php file. This way you can keep track of which plugins are installed, and where one ends and another begins.
  2. Be sure to copy the entire contents of the plugin file to your functions.php file. If you're missing an opening or closing tag anywhere, it could break your theme.
  3. Use obvious separators when integrating multiple plugins. This is sort of like point 1, but you'll definitely want to use a consistent and obvious marker for when a plugin begins and ends.
  4. Test, Test, TEST!!! Do not just slap the code in last minute and expect it to work. Test it extensively and make sure that your theme doesn't break. Plugins are buggy sometimes, so you need to make sure it's working properly before you release it or make it live.

One Final Tip

If you are comfortable enough with PHP, it should be noted that you can put the plugin files in a folder within your theme folder, and simply use your functions.php file to include those plugin files. I like to keep the php calls to a minimum, but you're certainly welcome to go that route if you are more comfortable with it.

Anyway, I thought that was a cool little tip, and hopefully so will you.

Happy Coding!


 Monetize With Performancing

Submitted by Ryan Caldwell on April 17, 2007 - 1:46pm in

Community is important to us at Performancing. Over the next few months we plan to roll out a number of new programs that enhance and give back to the Performancing community.

Earn $10 For Front Page Blog Posts

If we like your blog post enough to move it to the front page, you'll earn $10. Each day, we'll scour the entire set of Performancing blog posts and when we find posts that contain useful information, we'll promote them to the front page. On the 1st of each month, we'll pay users for the previous month.

AdSense Revenue Share

This is exciting. We're sharing 70% of all AdSense revenue generated by your own content. This gives you a chance to utilize and leverage the strong Performancing platform to add an additional revenue stream for your online endeavors. Additionally, you earn 10% of all AdSense revenue generated by users that you refer to Performancing.

To setup AdSense sharing, go to "my account" in the right navigation menu. Then click "edit" followed by AdSense ID. Here you can enter your own AdSense ID.

To refer users to Performancing, go to "my account" and scroll down to "Your referral link" - if a new user uses this link to sign-up at Performancing, you'll receive 10% of AdSense Revenue generated by the user's own content.

Theme Contests

Details are forthcoming, but we will be holding regular WordPress and Drupal theme contests with substantial cash prizes. Stay tuned!

Plugin/Module Contests

As with our theme contests, we'll be offering substantial cash prizes for plugins developed for Firefox and WordPess, as well modules developed for Drupal. Contest winners will include not only the developers, but also those who provide the concepts/ideas which we get implemented.