• Bri

    (@tinnyfusion)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Johannes

    (@wpdocde)

    Thank you for the suggestion. I will have a look at it when I get the chance. The plugin is a spare time project.

    Showing just the one plugin in the plugin overview seems like a good idea. The button in the admin bar certainly has the advantage that it can also be seen when the frontend is viewed. On the other hand, I would not like to include a hardcoded button. There may be a suitable WordPress function for this.

    As I said, I’ll see if I can find the time.

    Thread Starter Bri

    (@tinnyfusion)

    No worries. It’s up to you if you use it or not.

    To clarify, it’s not a hard coded button but text with a bit of CSS and is only there while the plugin is active. Works in exactly the same way as it did before but just shows in a different (more prominent) location.

    Also, because it’s no longer using the notification method, I could also use it as a link too, meaning we could do away with the extra link you had to take you to the plugins list.

    As I said, include it or not.

    Have a good day.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Feature Suggestion: Remove admin notice and replace with…’ is closed to new replies.