Halloween Sale 15% off Ends in See the plans
PHP

Weekly Security Summary Email

Emails the administrator a short security summary every week: pending WordPress, plugin and theme updates, administrator accounts, new users of the week, inactive plugins and whether debug mode is on.

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

Code

add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'wpide_weekly_security_summary' ) ) {
        wp_schedule_event( strtotime( 'next monday 08:00' ), 'weekly', 'wpide_weekly_security_summary' );
    }
} );

add_action( 'wpide_weekly_security_summary', function () {
    if ( ! function_exists( 'get_plugins' ) ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }

    $core    = get_site_transient( 'update_core' );
    $plugins = get_site_transient( 'update_plugins' );
    $themes  = get_site_transient( 'update_themes' );
    $core_up = ! empty( $core->updates[0]->response ) && 'upgrade' === $core->updates[0]->response;
    $admins  = get_users( array( 'role' => 'administrator', 'fields' => array( 'user_login' ) ) );
    $new     = get_users( array( 'date_query' => array( array( 'after' => '1 week ago' ) ), 'fields' => 'ID', 'number' => 500 ) );
    $active  = (array) get_option( 'active_plugins', array() );

    $lines = array(
        'WordPress update available: ' . ( $core_up ? 'yes (' . $core->updates[0]->current . ')' : 'no' ),
        'Plugin updates pending: ' . ( empty( $plugins->response ) ? 0 : count( $plugins->response ) ),
        'Theme updates pending: ' . ( empty( $themes->response ) ? 0 : count( $themes->response ) ),
        'Inactive plugins installed: ' . max( 0, count( get_plugins() ) - count( $active ) ),
        'Administrator accounts (' . count( $admins ) . '): ' . implode( ', ', wp_list_pluck( $admins, 'user_login' ) ),
        'New users this week: ' . count( $new ),
        'Debug mode: ' . ( defined( 'WP_DEBUG' ) && WP_DEBUG ? 'ON - turn it off on a live site' : 'off' ),
    );

    if ( ! empty( $plugins->response ) ) {
        $lines[] = '';
        $lines[] = 'Plugins to update:';
        foreach ( $plugins->response as $file => $data ) {
            $lines[] = '  ' . $file . ' -> ' . ( isset( $data->new_version ) ? $data->new_version : '?' );
        }
    }

    wp_mail( get_option( 'admin_email' ), sprintf( '[%s] Weekly security summary', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ), implode( "\n", $lines ) . "\n\nManage updates: " . admin_url( 'update-core.php' ) );
} );

Notes

Update counts come from WordPress's own update checks, so no extra requests are made.

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.