Version 1.4

The plugin toolkit has been getting a lot of useful classes recently, so I though a version bump was in order.

scbUtil

scbUtil is a collection of useful little functions that I was using in a lot of my plugins. My favourite is the debug() function. Then there’s html() and html_link() for HTML generation. There are several other useful bits in there, but you’ll have to discover them yourself.

scbRewrite

One of the areas I wasn’t comfortable working with was the Rewrite API. The scbRewrite class was distilled from a discussion on wp-hackers. It’s only job is to take the rewrite rules you specify and hook them in all the right places.

If you would like to “try before you buy”, you can browse the source here.

Version 1.3

Here are the changes from the earlier version:

Admin pages generated with AdminPage or BoxesPage will be slightly faster because data is sent through AJAX.

The scbCron class has two new methods:

  • do_now() – executes the callback immediately
  • do_once() – executes the callback once, using wp_cron (with optional delay)

The scbOptions class has a new method set() that replaces update_part(). It also has a new documentation page.

Finally, version 1.3 of scbFramework only works with WordPress 2.8 or older.

Here is the list of changes.

scbOptions Reference

Every plugin that’s more than 100 lines of code has at least one setting stored in the database. The functions that come with WordPress for managing options are ok, but they can be used better.

Here’s how the scbOptions class makes your life easier as a plugin developer:

Advantages

All in one place

scbOptions stores all fields in a single database row. Ask any WP plugin author worth his salt and he will agree that that’s the way to go.

Clean up on your way out

When the plugin is uninstalled, the options will also be deleted to keep the database clean.

Read on…

Version 1.2

When you need to create a new database table, all you should be thinking about are the table columns, right? Well, with the new scbTable class added in version 1.2, you can.

Creating a table is as easy as:

new scbTable('my_table', __FILE__, "
	id bigint(20) unsigned NOT NULL default 0,
	foobar varchar(100) NOT NULL,
	PRIMARY KEY  (id),
");

The class takes care of creating or updating the table structure, as necessary.

Also, you can access it with $wpdb->my_table, just like you would any other WordPress table.

Version 1.1

The first update for scbFramework has an important bugfix in the scbOptions class.

The scbBoxesPage now creates perfect WP 2.8 style dashboard-like admin pages.

Also, several methods have been added and revised in scbAdminPage. Because of this, version 1.1 is not fully backwards compatible.

You can see all the changes from version 1.0.1 here.

How to use scbFramework in your plugins

Before making this framework public, I used to include the files with each plugin. As the number of plugins increased, I had to update each one every time I modified the framework.

After a while, I found a way to make all plugins on an instalation use the most recent framework version installed. This didn’t help much.

Finally, I made it a standalone plugin which you only need to install once.

So, currently, there are two possibilities:

Standalone plugin

As long as the scbFramework plugin is activated, your plugin will work perfectly. If you want to spare users from ugly error messages, you can include a small file, called scb-check.php. It will check that scbFramework is installed and if not, it will deactivate your plugin and display a friendly notice with an install link.

Including class files

If you don’t want to require users to install the standalone plugin, you can include all the class files with your plugin. You will also want to include another file, called load.php that takes care of autoloading classes as needed. (It will have to be placed in the same directory as the class files)

You can see a usage example by looking at the Front-end Editor plugin.

Introducing scbFramework

While developing plugins for WordPress, I found that one of the most time-consuming and error prone tasks was creating user-friendly settings pages.

That is how this framework was born. It’s basically a set of extensible classes that make plugin development faster. I already use it in most of my plugins.

It requires PHP5 and WordPress 2.5 or newer.

scbForms

This by far the most useful class. With it, you can create any type of form element without writing a single line of HTML.

scbOptions

This is a class that handles storing and updating plugin settings in a single field in the wp_options table.

scbAdminPage

This class extends scbForms to provide an easy way to create custom admin pages.

scbBoxesPage

This is an extension to the scbOptionsPage class that lets you easily create dashboard-like pages with collapsible boxes.

scbCron

This is a class that lets you create wp-cron schedules easier.

scbWidget

This class makes scbForms work with the new WP_widget class in WP 2.8.

Hello, I'm scribu and I'm a web developer. Welcome to my site!