Drop-ins

WordPress drop-ins are special PHP files placed directly in the wp-content directory that override or extend specific WordPress core functionality. Unlike regular plugins, they are automatically loaded by WordPress if the file exists.

Key characteristics:

  • Stored in wp-content/

  • Automatically detected and loaded

  • Cannot be activated or deactivated via the admin panel

  • Used to replace or extend core behavior

  • Visible under Plugins → Drop-ins in the admin area

Default WordPress drop-ins:

  • advanced-cache.php

  • db.php

  • db-error.php

  • install.php

  • maintenance.php

  • object-cache.php

  • php-error.php

  • fatal-error-handler.php

Multisite-only drop-ins:

  • sunrise.php

  • blog-deleted.php

  • blog-inactive.php

  • blog-suspended.php

Example directory structure:

wp-content/
    advanced-cache.php
    db.php
    object-cache.php
    plugins/
    themes/

advanced-cache.php

This drop-in enables advanced caching mechanisms and loads very early during WordPress initialization.

Requirements:

  • WP_CACHE constant must be true

  • enable_loading_advanced_cache_dropin filter must return true

Enable caching in wp-config.php:

define('WP_CACHE', true);

Simple example:

<?php

$cache_file = __DIR__ . '/cache/home.html';

if (file_exists($cache_file)) {
    readfile($cache_file);
    exit;
}

db.php

db.php allows developers to replace or extend the wpdb database class.

Typical uses:

  • Database query monitoring

  • Custom database drivers

  • Replication setups

Example:

<?php

class Custom_DB extends wpdb {

    public function query($query) {
        error_log($query);
        return parent::query($query);
    }

}

global $wpdb;
$wpdb = new Custom_DB(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

db-error.php

Used to display custom database error pages instead of default WordPress errors.

Example:

<?php
header("HTTP/1.1 500 Internal Server Error");
?>

<h1>Database Error</h1>
<p>Please try again later.</p>

install.php

Allows customization of the WordPress installation process by overriding functions in wp-admin/includes/upgrade.php.

Example overriding wp_install():

<?php

function wp_install($blog_title, $user_name, $user_email) {
    error_log("Custom install process");
}

maintenance.php

Used to create a custom maintenance mode page when WordPress is updating.

Example:

<?php
header("HTTP/1.1 503 Service Unavailable");
?>

<h1>Maintenance Mode</h1>
<p>We will be back shortly.</p>

object-cache.php

Implements external object caching. When present, WordPress will not load its default WP_Object_Cache class.

Used for systems like:

  • Redis

  • Memcached

Example simplified cache:

<?php

class WP_Object_Cache {

    private $cache = [];

    function get($key) {
        return $this->cache[$key] ?? false;
    }

    function set($key, $value) {
        $this->cache[$key] = $value;
    }

}

$GLOBALS['wp_object_cache'] = new WP_Object_Cache();

Example Redis implementation:

<?php

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

function wp_cache_get($key) {
    global $redis;
    return $redis->get($key);
}

function wp_cache_set($key, $value) {
    global $redis;
    return $redis->set($key, $value);
}

php-error.php and fatal-error-handler.php

These drop-ins support WordPress Fatal Error Recovery Mode introduced in WordPress 5.2.

They allow:

  • Custom PHP error handling

  • Logging

  • Custom error pages

Example:

<?php

set_exception_handler(function($error){
    error_log(print_r($error, true));
});

sunrise.php (Multisite)

Loaded before multisite initialization when the SUNRISE constant is enabled.

Enable in wp-config.php:

define('SUNRISE', true);

Used for:

  • Domain mapping

  • Early configuration

Example:

<?php

if ($_SERVER['HTTP_HOST'] === 'example.com') {
    define('BLOG_ID_CURRENT_SITE', 2);
}

blog-deleted.php, blog-inactive.php, blog-suspended.php

These multisite drop-ins display custom messages for specific site states.

Examples:

Deleted site:

<?php
echo "<h1>This site has been deleted.</h1>";

Inactive site:

<?php
echo "<h1>This site is inactive.</h1>";

Suspended site:

<?php
echo "<h1>This site is suspended.</h1>";

Optimization

WordPress optimization improves performance, speed, and resource efficiency.

Key factors affecting performance:

  • Web hosting configuration

  • Theme and plugin quality

  • Media file sizes

  • Database size and unused data


Caching

Caching reduces database queries and speeds up page delivery.

Types:

  • Page caching

  • Object caching

  • Browser caching

  • Opcode caching

Example using Transients API:

function get_popular_posts() {

    $posts = get_transient('popular_posts');

    if ($posts !== false) {
        return $posts;
    }

    $posts = get_posts([
        'posts_per_page' => 5
    ]);

    set_transient('popular_posts', $posts, HOUR_IN_SECONDS);

    return $posts;
}

Optimizing Database Queries

Reduce unnecessary database operations.

Example optimized WP_Query:

$query = new WP_Query([
    'posts_per_page' => 5,
    'no_found_rows' => true,
    'update_post_meta_cache' => false,
    'update_post_term_cache' => false
]);

Limiting Post Revisions

Too many revisions increase database size.

Example:

define('WP_POST_REVISIONS', 5);

Conditional Script Loading

Load assets only when needed.

function load_contact_script() {

    if (is_page('contact')) {
        wp_enqueue_script('contact-form-js');
    }

}

add_action('wp_enqueue_scripts', 'load_contact_script');

Image Optimization

Large images slow down websites. Best practices include:

  • Compress images

  • Use responsive sizes

  • Use modern formats (WebP)

Example custom image size:

add_image_size('custom-thumb', 400, 300, true);