diff --git a/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php b/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php index 0500b6ba..61b0e318 100644 --- a/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php +++ b/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php @@ -83,6 +83,43 @@ public static function init() { register_widget( 'Mitlib\PullHours\Display_Widget_Frontpage' ); } + /** + * This function accepts the post ID of a location record, which will be used + * to check if that location has its alert populated. If either of the two + * fields for the location alert (alert_title or alert_content) are populated, + * that content will be shown in a div. + * + * The function does not return anything. + * + * @param string $location_id The ID of a location record to look up. + * + * @return void + */ + public function location_alert( $location_id ) { + $allowed_html = array( + 'a' => array( + 'href' => array(), + ), + ); + + $query_args = array( + 'post_type' => 'location', + 'p' => $location_id, + 'post_status' => 'publish', + ); + $locations = new \WP_Query( $query_args ); + + while ( $locations->have_posts() ) { + $locations->the_post(); + $alert_frontpage = get_field( 'alert_frontpage' ); + if ( $alert_frontpage ) { + echo '
'; + echo wp_kses( $alert_frontpage, $allowed_html ); + echo '
'; + } + } + } + /** * Sanitize widget form values as they are saved. * diff --git a/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php b/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php index 43cd8a17..fc01f848 100644 --- a/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php +++ b/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php @@ -6,41 +6,6 @@ * @since 0.6.0 */ -/** - * This function accepts the post ID of a location record, which will be used - * to check if that location has its alert populated. If either of the two - * fields for the location alert (alert_title or alert_content) are populated, - * that content will be shown in a div. - * - * The function does not return anything. - * - * @param string $location_id The ID of a location record to look up. - * - * @return void - */ -function location_alert( $location_id ) { - $allowed_html = array( - 'a' => array( - 'href' => array(), - ), - ); - - $query_args = array( - 'post_type' => 'location', - 'p' => $location_id, - 'post_status' => 'publish', - ); - $locations = new \WP_Query( $query_args ); - while ( $locations->have_posts() ) { - $locations->the_post(); - $alert_frontpage = get_field( 'alert_frontpage' ); - if ( $alert_frontpage ) { - echo '
'; - echo wp_kses( $alert_frontpage, $allowed_html ); - echo '
'; - } - } -} ?>
@@ -51,7 +16,7 @@ function location_alert( $location_id ) {
location_alert( 322 ); ?>
Dewey Library @@ -61,7 +26,7 @@ function location_alert( $location_id ) {
location_alert( 313 ); ?>
Hayden Library @@ -71,7 +36,7 @@ function location_alert( $location_id ) {
location_alert( 452 ); ?> Show 3 More @@ -84,7 +49,7 @@ function location_alert( $location_id ) { location_alert( 359 ); ?>
Distinctive Collections Reading Room @@ -94,7 +59,7 @@ function location_alert( $location_id ) {
location_alert( 504 ); ?>
Lewis Music Library @@ -104,6 +69,6 @@ function location_alert( $location_id ) {
location_alert( 473 ); ?> All hours & locations