Using WordPress ‘maybe_disable_automattic_widgets()’ PHP function

The maybe_disable_automattic_widgets() WordPress PHP function disables the Automattic widgets plugin, which was merged into core.

Usage

To use the maybe_disable_automattic_widgets() function, simply call it within your code:

maybe_disable_automattic_widgets();

Parameters

  • This function has no parameters.

More information

See WordPress Developer Resources: maybe_disable_automattic_widgets

Examples

Disable Automattic widgets in a theme

Disabling the Automattic widgets in your theme’s functions.php file:

add_action('after_setup_theme', 'my_theme_disable_automattic_widgets');

function my_theme_disable_automattic_widgets() {
    maybe_disable_automattic_widgets();
}

Disable Automattic widgets in a plugin

Disable the Automattic widgets within your custom plugin:

add_action('plugins_loaded', 'my_plugin_disable_automattic_widgets');

function my_plugin_disable_automattic_widgets() {
    maybe_disable_automattic_widgets();
}

Disable Automattic widgets on a specific admin page

Disable the Automattic widgets only on a specific admin page:

add_action('admin_init', 'disable_automattic_widgets_on_specific_page');

function disable_automattic_widgets_on_specific_page() {
    $screen = get_current_screen();
    if ($screen->id == 'my_custom_page') {
        maybe_disable_automattic_widgets();
    }
}

Disable Automattic widgets for specific user roles

Disable the Automattic widgets for users with a specific role:

add_action('init', 'disable_automattic_widgets_for_role');

function disable_automattic_widgets_for_role() {
    $user = wp_get_current_user();
    if (in_array('subscriber', $user->roles)) {
        maybe_disable_automattic_widgets();
    }
}

Conditionally disable Automattic widgets

Disable the Automattic widgets based on a custom condition:

add_action('init', 'conditionally_disable_automattic_widgets');

function conditionally_disable_automattic_widgets() {
    $disable_widgets = get_option('my_custom_option_disable_widgets');
    if ($disable_widgets) {
        maybe_disable_automattic_widgets();
    }
}