Halloween Sale 15% off Ends in See the plans
PHP

Site Health Check for Must-Have Plugins

Adds a test to Tools > Site Health that turns critical when any plugin you list as essential, such as your backup, security or SEO plugin, is deactivated or missing.

Don’t have WPIDE yet? Install it on your site

Code

// Plugins that must stay active (folder/main-file.php => name).
$wpide_required_plugins = array(
    'wordfence/wordfence.php'         => 'Wordfence Security',
    'updraftplus/updraftplus.php'     => 'UpdraftPlus Backups',
);

add_filter( 'site_status_tests', function ( $tests ) use ( $wpide_required_plugins ) {
    $tests['direct']['wpide_required_plugins'] = array(
        'label' => 'Essential plugins are active',
        'test'  => function () use ( $wpide_required_plugins ) {
            if ( ! function_exists( 'is_plugin_active' ) ) {
                require_once ABSPATH . 'wp-admin/includes/plugin.php';
            }

            $missing = array();
            foreach ( $wpide_required_plugins as $file => $name ) {
                if ( ! is_plugin_active( $file ) ) {
                    $missing[] = $name;
                }
            }

            $result = array(
                'label'       => 'All essential plugins are active',
                'status'      => 'good',
                'badge'       => array( 'label' => 'Maintenance', 'color' => 'blue' ),
                'description' => '<p>The plugins this site depends on are installed and active.</p>',
                'test'        => 'wpide_required_plugins',
            );

            if ( $missing ) {
                $result['label']       = 'Essential plugins are inactive';
                $result['status']      = 'critical';
                $result['badge']['color'] = 'red';
                $result['description'] = '<p>These plugins should always be active: ' . esc_html( implode( ', ', $missing ) ) . '.</p>';
                $result['actions']     = '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">Go to Plugins</a>';
            }

            return $result;
        },
    );

    return $tests;
} );

Notes

List plugin paths as folder/main-file.php in $wpide_required_plugins.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.