Check if there is anything to add to notices first.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Oct 2018 15:12:19 +0000 (11:12 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Oct 2018 15:12:19 +0000 (11:12 -0400)
If empty then don't add.

setup/adminHooks.php
views/glmInfoNotifications.html

index 91f01be..7e2f826 100644 (file)
@@ -152,28 +152,35 @@ if ( $user_is_admin || $user_is_editor ) {
         }
     );
 
-    if ( empty( get_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS ) ) ) {
-        add_action(
-            'admin_notices',
-            function(){
-                $page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
-                if ( $page === 'glm-info-main-menu' ) {
-                    return false;
-                }
-                echo '<div class="glm-serverstatus-notice updated notice is-dismissible">';
-                // Grab the cached notice.
-                $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
-                $latest_data = unserialize( $latest );
-
-                echo '<div style="display:inline-block;clear: left;">';
-                echo '<p><b>Gaslight Media Notification: </b><br>';
-                echo '<p><b>'.$latest_data['title'].'</b><br>';
-                echo wpautop( $latest_data['dashboard_message'] );
-                echo '</p></div>';
-                echo '<p><a href="' . admin_url( 'admin.php' ) . '?page=glm-info-main-menu">More Details</a></p>';
-                echo '</div>';
-            }, 10, 1
-        );
+    $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
+    if ( $latest ) {
+        $latest_data = unserialize( $latest );
+        if ( $latest_data['title'] && $latest_data['dashboard_message'] ) {
+            if ( empty( get_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS ) ) ) {
+                add_action(
+                    'admin_notices',
+                    function(){
+                        $page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
+                        if ( $page === 'glm-info-main-menu' ) {
+                            return false;
+                        }
+                        echo '<div class="glm-serverstatus-notice updated notice is-dismissible">';
+                        // Grab the cached notice.
+                        $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
+                        $latest_data = unserialize( $latest );
+
+                        echo '<div style="display:inline-block;clear: left;">';
+                        echo '<p><b>Gaslight Media Notification: </b><br>';
+                        echo '<p><b>'.$latest_data['title'].'</b><br>';
+                        echo wpautop( $latest_data['dashboard_message'] );
+                        echo '</p></div>';
+                        echo '<p><a href="' . admin_url( 'admin.php' ) . '?page=glm-info-main-menu">More Details</a></p>';
+                        echo '</div>';
+                    }, 10, 1
+                );
+            }
+
+        }
     }
 
     add_action( 'admin_enqueue_scripts', function(){
index 9eff792..8f7e750 100644 (file)
@@ -29,6 +29,8 @@
                     </ul>
                 {/foreach}
             {/if}
+        {else}
+            <p>There are currently no messages.</p>
         {/if}
 
     </div>