Reminder to Remove Inactive Plugins
Shows administrators a gentle notice on the Dashboard and Plugins screens when plugins have been left inactive, since unused plugins still need updates and can be a security risk.
Opens WPIDE on
Code
// Plugins that may stay inactive (folder/main-file.php).
$wpide_inactive_allowed = array( 'hello.php' );
add_action( 'admin_notices', function () use ( $wpide_inactive_allowed ) {
$screen = get_current_screen();
if ( ! current_user_can( 'delete_plugins' ) || ! $screen || ! in_array( $screen->id, array( 'dashboard', 'plugins' ), true ) ) {
return;
}
if ( isset( $_GET['wpide_dismiss_inactive'] ) && check_admin_referer( 'wpide_dismiss_inactive' ) ) {
set_transient( 'wpide_inactive_dismissed_' . get_current_user_id(), 1, 30 * DAY_IN_SECONDS );
}
if ( get_transient( 'wpide_inactive_dismissed_' . get_current_user_id() ) ) {
return;
}
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$inactive = array();
foreach ( get_plugins() as $file => $data ) {
if ( ! is_plugin_active( $file ) && ! in_array( $file, $wpide_inactive_allowed, true ) && ! is_plugin_active_for_network( $file ) ) {
$inactive[] = $data['Name'];
}
}
if ( ! $inactive ) {
return;
}
printf(
'<div class="notice notice-info"><p><strong>%d inactive plugin(s):</strong> %s. If you no longer need them, deleting them reduces maintenance and risk. <a href="%s">Review plugins</a> · <a href="%s">Dismiss for 30 days</a></p></div>',
count( $inactive ),
esc_html( implode( ', ', array_slice( $inactive, 0, 8 ) ) . ( count( $inactive ) > 8 ? '...' : '' ) ),
esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
esc_url( wp_nonce_url( add_query_arg( 'wpide_dismiss_inactive', 1 ), 'wpide_dismiss_inactive' ) )
);
} );
Notes
Add plugins you keep inactive on purpose to $wpide_inactive_allowed; the notice can be dismissed for 30 days.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.