Simple Maintenance Redirect

The Simple Maintenance Redirect plugin has some useful hooks for developers to use to further enhance its functionality.

smredirect_redirect_rules

TYPE ⇢ Filter

This filter allows developers to modify the redirect behavior for maintenance mode by customizing the checks that determine whether a user should be redirected. You can add your own custom conditions to bypass maintenance mode for specific users, roles, request types, or any logic you need.

Example Usage

PHP
/**
 * Allow a specific user or role to bypass maintenance mode.
 *
 * @param array       $checks       → An associative array of boolean checks that must all pass to allow redirect.
 * @param int|null    $page_id      → The ID of the current page if redirecting to page or null if redirecting to external URL.
 * @param string      $request_uri  → The current request URI used to evaluate redirect logic.
 *
 * @return array → Updated array of checks.
 */
add_filter( 'smredirect_redirect_rules', function( $checks, $page_id, $request_uri ) {
    // Allow access to a specific user (user ID 37)
    $checks[ 'not_john_smith' ] = get_current_user_id() !== 37;

    // Allow access to users with the 'editor' role
    $user = wp_get_current_user();
    $checks[ 'not_editor' ] = !in_array( 'editor', (array) $user->roles, true );

    return $checks;
}, 10, 3 );

smredirect_admin_bar_colors

TYPE ⇢ Filter

This filter allows you to customize the colors of the WordPress admin bar when maintenance mode is active. You can change the two stripe colors used in the background gradient to better match your brand or theme or make it more prominent.

Example Usage

PHP
/**
 * Customize the admin bar colors during maintenance mode.
 *
 * @param array $defaults  → An associative array with the default stripe colors:
 *                           - 'color_1' is the first stripe color (default: #870927).
 *                           - 'color_2' is the second stripe color (default: #8B0000).
 *
 * @return array → The modified colors to use.
 */
add_filter( 'smredirect_admin_bar_colors', function( $defaults ) {
    return [
        'color_1' => '#005f73', // Teal
        'color_2' => '#0a9396', // Lighter teal
    ];
} );

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.