Quantcast
Channel: Xavisys »» wordpress development
Viewing all articles
Browse latest Browse all 8

The Xavisys WordPress Plugin Framework

$
0
0

A few months ago I was chatting with Joost de Valk and he was talking about a new plugin toolkit that he was making. The basic idea was to make a flexible base that he could use to build on for all his plugins. It would handle all the tasks that are common to all his plugins (options page, dashboard widget, etc) and still be easily extended so each plugin could handle more specific tasks as well. Now his plugins (at least some of them) use his toolkit.

It was a great idea, and I finally got around to writing one for my own plugins. I built it as an abstract class (and a tiny CSS file) that I extend for each plugin. Here you’ll get to see a quick tour of what the framework does. Let me know in the comments if you’re interested in seeing a walkthrough of how it was built, and feel free to download Efficient Related Posts to see it in action.

Here are some of the things it does:

  • Stores plugin settings in a protected variable, making them easily available to all methods.
  • Registers the options for the plugin (making sure it works in WPMU and that options.php can handle updates to the options).
  • When an update to the plugin is available, it shows a changelog from the currently installed version to the newly available version (whether they’re one version apart or twenty).
    Changelog
  • Adds an options page for the WordPress plugin settings, complete with a page heading and a Xavisys icon.
  • Styles the options page as two columns with meta boxes (similar to the two column dashboard layout).
    Options Page Screenshot
  • Adds basic meta boxes to the sidebar of the options page, including one with a donate link, one with a link to the support forums, and one showing the latest news from Xavisys.
    Sidebar screenshot
  • It adds links to the plugin row on the plugins page. One link to the support forums and one to the plugin options page.
    Plugin Row Image
  • It adds a dashboard widget with a feed from Xavisys, complete with the Xavisys logo and a way to subscribe via RSS to the Xavisys site.
    Xavisys Dashboard Image
    Dashboard Screen Options Image

It does all this based on variables set in the extending class. For example, the setup for Efficient Related Posts looks something like this:

require_once('xavisys-plugin-framework.php');
class efficientRelatedPosts extends XavisysPlugin {
	protected function _init() {
		$this->_hook = 'efficientRelatedPosts';
		$this->_file = plugin_basename( __FILE__ );
		$this->_pageTitle = __( 'Efficient Related Posts', $this->_slug );
		$this->_menuTitle = __( 'Related Posts', $this->_slug );
		$this->_accessLevel = 'manage_options';
		$this->_optionGroup = 'erp-options';
		$this->_optionNames = array('erp');
		$this->_optionCallbacks = array();
		$this->_slug = 'efficient-related-posts';
		$this->_paypalButtonId = '9996714';
	}
}

Related Posts:


Viewing all articles
Browse latest Browse all 8

Trending Articles