Using WordPress ‘enable_post_by_email_configuration’ PHP filter

The enable_post_by_email_configuration WordPress PHP filter allows you to control whether the post-by-email functionality is enabled or not.

Usage

add_filter('enable_post_by_email_configuration', 'your_custom_function');
function your_custom_function($enabled) {
    // your custom code here
    return $enabled;
}

Parameters

  • $enabled (bool): Whether post-by-email configuration is enabled. Default is true.

More information

See WordPress Developer Resources: enable_post_by_email_configuration

Examples

Disable post-by-email functionality

Disable the post-by-email feature completely.

add_filter('enable_post_by_email_configuration', '__return_false');

Enable post-by-email only for administrators

Allow only administrators to use the post-by-email feature.

add_filter('enable_post_by_email_configuration', 'only_admin_post_by_email');
function only_admin_post_by_email($enabled) {
    if (current_user_can('administrator')) {
        return true;
    }
    return false;
}

Enable post-by-email for a specific user

Allow only a specific user (by user ID) to use the post-by-email feature.

add_filter('enable_post_by_email_configuration', 'specific_user_post_by_email');
function specific_user_post_by_email($enabled) {
    $allowed_user_id = 42;
    if (get_current_user_id() == $allowed_user_id) {
        return true;
    }
    return false;
}

Disable post-by-email on weekends

Disable the post-by-email feature on weekends.

add_filter('enable_post_by_email_configuration', 'no_post_by_email_on_weekends');
function no_post_by_email_on_weekends($enabled) {
    $current_day = date('w');
    if ($current_day == 0 || $current_day == 6) {
        return false;
    }
    return true;
}

Enable post-by-email only during business hours

Allow users to use the post-by-email feature only during business hours (9 AM to 5 PM).

add_filter('enable_post_by_email_configuration', 'post_by_email_business_hours');
function post_by_email_business_hours($enabled) {
    $current_hour = date('G');
    if ($current_hour >= 9 && $current_hour <= 17) {
        return true;
    }
    return false;
}