HTML5 Zone is brought to you in partnership with:

Paulund is a website dedicated to writing tutorials and code snippets about Web Development, the main subjects are PHP, Wordpress, jQuery, CSS3 and HTML5. Paul is a DZone MVB and is not an employee of DZone and has posted 134 posts at DZone. You can read more from them at their website. View Full User Profile

WordPress Dropins Extend the Functionality of WordPress

10.04.2013
| 1712 views |
  • submit to reddit

To extend the functionality of WordPress, most people have only heard of the use of plugins. Not many people have heard of the term Dropins.

WordPress has its core functionality, which can be added to by the use of plugins that take advantage of multiple WordPress hooks and actions, but it also allows you to replace functionality with the use of Dropin files.

Unlike a plugin, the Dropin file will not need to be activated and will become activated when it is placed in the wp-content folder. This folder will by default be at the root of your WordPress install, but can be defined by changing the constant variable WP_CONTENT_DIR.

// Custom content directory
define( 'WP_CONTENT_DIR',  dirname( __FILE__ ) . '/wp-content' );
define( 'WP_CONTENT_URL',  'http://' . $_SERVER['HTTP_HOST'] . '/wp-content' );

An example of how WordPress will include these Dropin files can be seen in the WordPress core code. Here is an example of displaying the maintenance.php. As you can see, it uses the constant WP_CONTENT_DIR.

if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
	require_once( WP_CONTENT_DIR . '/maintenance.php' );
	die();
}

When you place your Dropin files in the wp-content folder, you can see this from the plugin maintenance screen: /wp-admin/plugins.php?plugin_status=dropins.

dropins

To get a list of available Dropins, there is a function in /wp-admin/includes/plugin.php called _get_dropins(). This will return the following list of Dropins.

Single Site Install

  • advanced-cache.php - Advanced caching plugin. Allows you to replace the caching functionality of your WordPress site. Activated by defining a constant variable WP_CACHE in the wp-config.php file.
  • db.php - Custom database class. Used to create you own database class. Activated on load.
  • db-error.php - Custom database error message. Used to display your own custom database error message. Activated on load.
  • install.php - Custom install script. Used to customise your own WordPress install script. Activated on load.
  • maintenance.php - Custom maintenance message. Used to create your own WordPress custom message. Activated on load.
  • object-cache.php - External object cache. Used to create your own object caching class. Activated on load.

Additional Multisite Dropins

  • sunrise.php - Executed before Multisite is loaded. Used to change the way Multisite functionality is loaded. Activated by placing a constant variable in wp-config.php file.
  • blog-deleted.php - Custom site deleted message. Activated on load.
  • blog-inactive.php - Custom site inactive message. Activated on load.
  • blog-suspended.php - Custom site suspended message. Activated on load.
Published at DZone with permission of Paul Underwood, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)