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

(avery) #1

184 PART III • Using Plugins with WordPress


doing the deployment yourself, it really doesn’t matter. However, if the end user will have to
fiddle with the plugin’s position or perhaps will need to pass parameters to it, then it is
probably a better idea to look at other solutions.

At other times, just adding functionality using template tags won’t cut it, and you need
to overwrite parts of the core WordPress functionality. That’s when you turn to the
pluggable functions.

THE PLUGGABLE FUNCTIONS
Sometimes you may need to alter how WordPress normally does things, perhaps to replace
some functionality with your own or just because your particular use of WordPress differs from
the intended one. Maybe you don’t want localizations to work in the WordPress admin, for
example, in which case you’d need to get rid of load_textdomain, or perhaps you want to
replace the admin footer with your own. Just removing a hook won’t do it. That’s when you turn
to pluggable.php, located in wp-includes. Naturally, you won’t hack it because that would be a
tedious thing to manage with updates; instead you’ll write a plugin that does the override. Now
this is dangerous stuff. First of all, you can perform an override only once, so if two plugins have
different overrides on the same pluggable function, the site will misbehave (at best) or break
(at worst). This means that two plugins both relying on overriding the same pluggable function
can’t be installed at the same time, which is a serious drawback. Therefore, you should probably
only use your pluggable functions on sites that you have complete control of.

Also, to avoid unnecessary errors, you may want to wrap any code pertaining to a plugin
relying on these things in a check to see if the function exists:

<?php if (! function_exists( 'function_name' ) ); ?>

There are, naturally, times when the pluggable functions can come in handy. You can see the
most up-to-date list of these functions in the Codex at http://codex.wordpress.org/
Pluggable_Functions.

Use pluggable functions with caution, obviously. Just writing the plugin in the correct way
isn’t enough when you’re nulling out parts of the WordPress core. Don’t be surprised when
things stop working or conflicts come out of nowhere if you dive into these things. After all,
the WordPress functionality you’re bypassing is there for a reason.

CUSTOM TAXONOMIES AND CUSTOM POST TYPES


Custom taxonomies and custom post types are powerful tools, especially when you want to
use WordPress beyond straightforward blogs. In Chapter 14, you’ll do some creative stuff with
both custom taxonomies and custom post types, in case you need a little bit of inspiration for
what you can do with these tools.

Just to recap: Custom taxonomies let you add additional ways to organize your content. The
default tags and categories are in fact nonhierarchical and hierarchical taxonomies, respec-
tively, and the actual tags and categories are terms in said taxonomies. Custom post types,
Free download pdf