How to Write Plugins for WordPress MU – updated

Last year I gave a ink to a short post on the basics of WPMU plugin development by itdamager. It turns out that that post is no longer available online. So is a cached copy of it:

Plugins for WordPress and WordPress MU are very similar but there are a few specific MU commands and plugin placement differences you should consider when creating a plugin for WPMU.

  • WordPress MU plugins can either be globally enabled or individually enabled/disabled by each user, depending on their purpose.
  • WordPress MU will allow you to check if the user is a site admin or not.
  • WordPress MU will allow your plugin to use ‘per blog’ settings, or ‘per site’ (sitewide) settings, depending on your needs.
  • WordPress MU has variables that are useful to plugin development

Global Plugins
Wordpress MU has a special plugins directory called mu-plugins. Any plugin placed within this directory will automatically be enabled globally. Users cannot disable or view the plugins located here. To ‘disable’ a global plugin, delete the plugin file from your server.

User Enabled Plugins
Plugins that users are allowed to enable/disable for themselves are placed in the standard plugins directory. This would include many of the standard plugin’s that are already available for WordPress. If your plugin will reside here, you can probably follow the standard WordPress plugin development instructions on the codex.

Site Admins
Certain users, (admin by default) can be given the ability to administrate a WPMU installation.

If you want your plugin’s config screen(s) to be available only to WPMU admins, or certain functions only available to admin users, then you can use the following MU functions to test if a user is a site admin or not:

get_currentuserinfo() – get_currentuserinfo requires no arguments and preloads, if not done already, information about, you guessed it, the current user.

is_site_admin() – is_site_admin, as the name implies, will return true if the user is a site admin, and false if they are not.

By using those two functions you can write code or config screens that are admin specific and unavailable to regular users.

Sitewide Settings
WPMU has commands that allow retrieval/storage of global options.

add_site_option($name, $value) – Adds a new sitewide option to the database.

update_site_option($name, $value) – Updates a sitewide option, adds it if it don’t exist.

get_site_option($name) – Retrieves a sitewide option from the database.

WPMU Variables
Many useful variables are available in WordPress MU. Here are a few.

$blog_id
$user_id
$current_site
$current_blog
$wpmuBaseTablePrefix
$table_prefix

Contants
VHOST – yes if installed using sub-domains, no if installed using sub-directories.

More MU Specific Commands
For a full list of all commands specific to WPMU, refer to wpmu-functions.php where you will find they are all defined with self explanatory names, in most cases.

Did you find this post interesting? Please subscribe to my feed.

Post a Comment

Your email is never published nor shared. Required fields are marked *