Using WordPress ‘mature_blog’ PHP action

The mature_blog WordPress action fires when the ‘mature’ status is added to a site.

Usage

add_action('mature_blog', 'your_custom_function');

function your_custom_function($site_id) {
    // your custom code here
}

Parameters

  • $site_id (int): The site ID.

More information

See WordPress Developer Resources: mature_blog

Examples

Notify the admin when a site becomes mature

Send an email notification to the admin when a site gets the ‘mature’ status.

add_action('mature_blog', 'notify_admin_mature_site');

function notify_admin_mature_site($site_id) {
    $admin_email = get_option('admin_email');
    $subject = 'A site has been marked as mature';
    $message = "Site ID: $site_id has been marked as mature.";
    wp_mail($admin_email, $subject, $message);
}

Log mature sites to a file

Log the site IDs of mature sites in a text file.

add_action('mature_blog', 'log_mature_sites');

function log_mature_sites($site_id) {
    $logfile = '/path/to/your/mature_sites.log';
    $log_entry = "Mature site ID: $site_id" . PHP_EOL;
    file_put_contents($logfile, $log_entry, FILE_APPEND);
}

Add a custom mature site message to the site’s front page

Display a custom message on the front page of mature sites.

add_action('mature_blog', 'add_mature_site_message');

function add_mature_site_message($site_id) {
    switch_to_blog($site_id);
    update_option('mature_site_message', 'This site contains mature content. Viewer discretion is advised.');
    restore_current_blog();
}

Deactivate specific plugins for mature sites

Deactivate a specific plugin for sites that become mature.

add_action('mature_blog', 'deactivate_plugins_for_mature_sites');

function deactivate_plugins_for_mature_sites($site_id) {
    $plugin = 'plugin-folder/plugin-file.php';
    switch_to_blog($site_id);
    deactivate_plugins($plugin);
    restore_current_blog();
}

Remove the default theme for mature sites

Switch to a different theme for mature sites.

add_action('mature_blog', 'change_theme_for_mature_sites');

function change_theme_for_mature_sites($site_id) {
    $new_theme = 'new-theme-folder-name';
    switch_to_blog($site_id);
    switch_theme($new_theme);
    restore_current_blog();
}