From fc601dc70c78d055f64b60769c425048925c2b22 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 25 Oct 2018 11:12:19 -0400 Subject: [PATCH] Check if there is anything to add to notices first. If empty then don't add. --- setup/adminHooks.php | 51 +++++++++++++++++++-------------- views/glmInfoNotifications.html | 2 ++ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 91f01be..7e2f826 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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 '
'; - // Grab the cached notice. - $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false ); - $latest_data = unserialize( $latest ); - - echo '
'; - echo '

Gaslight Media Notification:
'; - echo '

'.$latest_data['title'].'
'; - echo wpautop( $latest_data['dashboard_message'] ); - echo '

'; - echo '

More Details

'; - echo '
'; - }, 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 '
'; + // Grab the cached notice. + $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false ); + $latest_data = unserialize( $latest ); + + echo '
'; + echo '

Gaslight Media Notification:
'; + echo '

'.$latest_data['title'].'
'; + echo wpautop( $latest_data['dashboard_message'] ); + echo '

'; + echo '

More Details

'; + echo '
'; + }, 10, 1 + ); + } + + } } add_action( 'admin_enqueue_scripts', function(){ diff --git a/views/glmInfoNotifications.html b/views/glmInfoNotifications.html index 9eff792..8f7e750 100644 --- a/views/glmInfoNotifications.html +++ b/views/glmInfoNotifications.html @@ -29,6 +29,8 @@ {/foreach} {/if} + {else} +

There are currently no messages.

{/if} -- 2.17.1