Feature Suggestion: Remove admin notice and replace with…
-
Hi, thank you for your assistance earlier. It was indeed a cache issue my end.
During the above issue I obviously looked through the code to see what may have been the cause. During this I decided to make a minor alteration to the “Maintenance” message shown to the admin as a reminder that the plugin was active.
I changed the following section of code:
/** * Alert message when active */ function slim_maintenance_mode_admin_notices() { echo '<div id="message" class="error fade"><p>' . __( '<strong>Maintenance mode</strong> is <strong>active</strong>!', 'slim-maintenance-mode' ) . ' <a href="plugins.php?s=Slim Maintenance Mode&plugin_status=all">' . __( 'Deactivate it, when work is done.', 'slim-maintenance-mode' ) . '</a></p></div>'; } if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) add_action( 'network_admin_notices', 'slim_maintenance_mode_admin_notices' ); add_action( 'admin_notices', 'slim_maintenance_mode_admin_notices' ); add_filter( 'login_message', function() { return '<div id="login_error">' . __( '<strong>Maintenance mode</strong> is <strong>active</strong>!', 'slim-maintenance-mode' ) . '</div>'; } );
And replaced it with this:
/** * Display maintenance mode enabled message in the admin bar when active */ function slim_maintenance_mode_display_admin_bar() { global $wp_admin_bar; // Get the URL to toggle plugins $toggle_url = admin_url( 'plugins.php?s=Slim+Maintenance+Mode&plugin_status=all' ); // Add the message and link to the admin bar $wp_admin_bar->add_menu( array( 'id' => 'slim-maintenance-mode-enabled', 'title' => '<a href="' . esc_url( $toggle_url ) . '"><span style="background-color: red; color: white; padding: 4px 8px; border-radius: 4px; cursor: pointer;">Maintenance Mode: Enabled</span></a>', 'meta' => array( 'class' => 'slim-maintenance-mode-enabled' ), )); } add_action( 'admin_bar_menu', 'slim_maintenance_mode_display_admin_bar', 999 );
The functionality is exactly the same, you click on the above and it opens the Installed Plugins list showing only your plugin so that the user can then deactivate it.
I originally used ajax to toggle the status with a click turning it green and stating “Maintenance Mode: Disabled”. However, as I started adding more functionality I realised that it detracted from the original intention of the plugin to be light weight and simple so I reverted back to the above change only.
Hope you like it? Think of it as a thank you for your help earlier.
Thank you again for a quick, to the point plugin that is not swamped with features and upsells as seems to be the case these days.
- The topic ‘Feature Suggestion: Remove admin notice and replace with…’ is closed to new replies.