Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

210 PART III • Using Plugins with WordPress


you want to use more cutting-edge versions of PHP and/or MySQL. If you take that route, be
sure to output an error message should someone try to run your plugin using older versions
of PHP and/or MySQL.

How far back you want to let your users go with your plugin is up to you. Since the addition
of automatic updates, one can only hope that the updating frequency of the end users is
higher than it was before auto updates, but a surprisingly large number of blogs still run on
older versions of WordPress, which is bad news for developers and for site owners. After all,
older versions can lead to security issues as well as compatibility problems.

CHECK IF A FUNCTION EXISTS
The following is a useful little code snippet that you should remember; it checks whether a
function exists. You can use this to make sure that functions aren’t called when they’re not
actually available. The simplest form of this is found in themes, where a function_exists
check will see if a function pertaining to a plugin is available (that is, is the plugin active or not?).

The code’s really simple:

if ( function_exists( 'smashing_function_here' ) ) {
// Whatever you put here only happens if true
}

You can read more about function_exists, which isn’t a WordPress-specific feature
but rather a PHP function, at http://php.net/manual/en/function.
function-exists.php.

HOSTING YOUR PLUGINS ON WORDPRESS.ORG


Just as with themes, there is an official plugin directory on WordPress.org where you can host
your plugins. You don’t have to post your plugins on that site, of course, but doing so allows
users to get automatic updates so that they can keep up-to-date with the latest fixes.

However, there are some terms that your plugins needs to fulfill to be hosted on
WordPress.org:

◾ The plugins must be licensed under a GPL-compatible license.
◾ The plugin can’t do anything illegal or be “morally offensive.”
◾ The plugin must be hosted in the WordPress.org subversion repository.
◾ The plugin must have a valid readme file.

To get access, you need to be a WordPress.org user. Then submit your plugin (http://
wordpress.org/plugins/add) and wait for approval. This process can take some time,
depending on the workload of the people involved.
Free download pdf