WordPress Dropins Extend the Functionality of WordPress
Join the DZone community and get the full member experience.
Join For FreeTo 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.
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, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
WireMock: The Ridiculously Easy Way (For Spring Microservices)
-
How to Optimize CPU Performance Through Isolation and System Tuning
-
HashMap Performance Improvements in Java 8
-
Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices
Comments