Tests if plugins are outdated, or unnecessary.
Description
The test checks if your plugins are up to date, and encourages you to remove any that are not in use.
Source
public function get_test_plugin_version() {
$result = array(
'label' => __( 'Your plugins are all up to date' ),
'status' => 'good',
'badge' => array(
'label' => __( 'Security' ),
'color' => 'blue',
),
'description' => sprintf(
'<p>%s</p>',
__( 'Plugins extend your site’s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it’s vital to keep them up to date.' )
),
'actions' => sprintf(
'<p><a href="%s">%s</a></p>',
esc_url( admin_url( 'plugins.php' ) ),
__( 'Manage your plugins' )
),
'test' => 'plugin_version',
);
$plugins = get_plugins();
$plugin_updates = get_plugin_updates();
$plugins_active = 0;
$plugins_total = 0;
$plugins_need_update = 0;
// Loop over the available plugins and check their versions and active state.
foreach ( $plugins as $plugin_path => $plugin ) {
++$plugins_total;
if ( is_plugin_active( $plugin_path ) ) {
++$plugins_active;
}
if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
++$plugins_need_update;
}
}
// Add a notice if there are outdated plugins.
if ( $plugins_need_update > 0 ) {
$result['status'] = 'critical';
$result['label'] = __( 'You have plugins waiting to be updated' );
$result['description'] .= sprintf(
'<p>%s</p>',
sprintf(
/* translators: %d: The number of outdated plugins. */
_n(
'Your site has %d plugin waiting to be updated.',
'Your site has %d plugins waiting to be updated.',
$plugins_need_update
),
$plugins_need_update
)
);
$result['actions'] .= sprintf(
'<p><a href="%s">%s</a></p>',
esc_url( network_admin_url( 'plugins.php?plugin_status=upgrade' ) ),
__( 'Update your plugins' )
);
} else {
if ( 1 === $plugins_active ) {
$result['description'] .= sprintf(
'<p>%s</p>',
__( 'Your site has 1 active plugin, and it is up to date.' )
);
} elseif ( $plugins_active > 0 ) {
$result['description'] .= sprintf(
'<p>%s</p>',
sprintf(
/* translators: %d: The number of active plugins. */
_n(
'Your site has %d active plugin, and it is up to date.',
'Your site has %d active plugins, and they are all up to date.',
$plugins_active
),
$plugins_active
)
);
} else {
$result['description'] .= sprintf(
'<p>%s</p>',
__( 'Your site does not have any active plugins.' )
);
}
}
// Check if there are inactive plugins.
if ( $plugins_total > $plugins_active && ! is_multisite() ) {
$unused_plugins = $plugins_total - $plugins_active;
$result['status'] = 'recommended';
$result['label'] = __( 'You should remove inactive plugins' );
$result['description'] .= sprintf(
'<p>%s %s</p>',
sprintf(
/* translators: %d: The number of inactive plugins. */
_n(
'Your site has %d inactive plugin.',
'Your site has %d inactive plugins.',
$unused_plugins
),
$unused_plugins
),
__( 'Inactive plugins are tempting targets for attackers. If you are not going to use a plugin, you should consider removing it.' )
);
$result['actions'] .= sprintf(
'<p><a href="%s">%s</a></p>',
esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
__( 'Manage inactive plugins' )
);
}
return $result;
}
Changelog
Version | Description |
---|---|
5.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.