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

(avery) #1

CHAPTER 7 • Making the Most of WordPress Plugins 179


As for the directory structure, almost everything is the same as in the standard version of
WordPress. The only real difference is the blogs.dir directory in the wp-content folder, which
contains all the created blogs’ data, such as images and uploads. You won’t be using that folder
much because themes and plugins belong in the main wp-content folder, just as you’re used to.


If you want to force your plugins across the network, you can choose to activate them sitewide
(as an admin superuser). Another option is to use must-use plugins or just drop any plugin in
the wp-content/mu-plugins/ folder, although that might end up giving you some problems
should the plugin be unsuited for this. Activating sitewide is usually the best solution.


Actual plugin development is just as for standalone WordPress. You do, however, need to be
extra careful when creating new tables in the database or relying on content from core tables.
Most of the time, you’ll be fine, but there are some differences in the database when you’re
running several sites in a WordPress install, so be watchful.


Another thing to consider when creating plugins for a multisite is how they are intended
to be used. Because you can run a multisite install in so many ways, open or closed, with
plugins enabled for bloggers, just for admin, and so on, you may have to rethink the way the
plugin works.


SITEWIDE WORDPRESS PLUGINS


You can also activate plugins sitewide from within admin. This means that you can activate
plugins located in wp-content/plugins/ to be active sitewide. This is of course a lot more user
friendly, so you should definitely consider managing sitewide plugin-powered features this
way, rather than with must-use plugins. After all, because WordPress supports automatic
updates, the more that are available at a click from within the admin interface, the better.


PLUGIN BASICS


There’s not enough space in this book to delve too far into the world of plugins. This section
and the following ones are meant to help experienced PHP programmers get their thoughts in
order so that they can write the plugins they need. For additional reading, consult the Writing
a Plugin section of the WordPress Codex at http://codex.wordpress.org/
Writing_a_Plugin.


A plugin’s essentials are similar to a theme’s essentials:


◾ The main plugin file needs to be a PHP file with a unique filename or a unique folder
name if your plugin consists of several files inside a folder.
◾ The PHP file needs an identifying header, just like a theme’s style.css does so that Word-
Press can recognize it as a plugin.

Then you can expand by adding even more functionality outside of the main plugin PHP file
if you want, just as you add template files to the child theme’s style.css.

Free download pdf