Skip to content

Commit

Permalink
Move function to class file, not template file.
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-bernhardt committed May 14, 2024
1 parent 080605a commit 7ad5aef
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="location-alert">';
echo wp_kses( $alert_frontpage, $allowed_html );
echo '</div>';
}
}
}

/**
* Sanitize widget form values as they are saved.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="location-alert">';
echo wp_kses( $alert_frontpage, $allowed_html );
echo '</div>';
}
}
}
?>

<div class="location">
Expand All @@ -51,7 +16,7 @@ function location_alert( $location_id ) {
</div>
<?php
// Load location alerts for Barker (post 322).
location_alert( 322 );
$this->location_alert( 322 );
?>
<div class="location">
<a href="/dewey" aria-labelledby="dewey" class="img-loc dewey"><span class="sr" id="dewey">Dewey Library</span></a>
Expand All @@ -61,7 +26,7 @@ function location_alert( $location_id ) {
</div>
<?php
// Load location alerts for Dewey (post 313).
location_alert( 313 );
$this->location_alert( 313 );
?>
<div class="location">
<a href="/hayden" aria-labelledby="hayden" class="img-loc hayden"><span class="sr" id="hayden">Hayden Library</span></a>
Expand All @@ -71,7 +36,7 @@ function location_alert( $location_id ) {
</div>
<?php
// Load location alerts for Hayden (post 452).
location_alert( 452 );
$this->location_alert( 452 );
?>
<a href="#0" class="show-more hidden-non-mobile">
<svg class="icon-arrow-down" version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="16.3" height="9.4" viewBox="2.7 8.3 16.3 9.4" enable-background="new 2.7 8.3 16.3 9.4" xml:space="preserve"><path d="M18.982 9.538l-8.159 8.159L2.665 9.538l1.284-1.283 6.875 6.875 6.875-6.875L18.982 9.538z"/></svg>Show 3 More
Expand All @@ -84,7 +49,7 @@ function location_alert( $location_id ) {
</div>
<?php
// Load location alerts for Rotch (post 359).
location_alert( 359 );
$this->location_alert( 359 );
?>
<div class="location hidden-mobile inactive-mobile">
<a href="/distinctive-collections" aria-labelledby="dc" class="img-loc archives"><span class="sr" id="dc">Distinctive Collections Reading Room</span></a>
Expand All @@ -94,7 +59,7 @@ function location_alert( $location_id ) {
</div>
<?php
// Load location alerts for Distinctive Collections (post 504).
location_alert( 504 );
$this->location_alert( 504 );
?>
<div class="location hidden-mobile inactive-mobile">
<a href="/music" aria-labelledby="lewis" class="img-loc lewis"><span class="sr" id="lewis">Lewis Music Library</span></a>
Expand All @@ -104,6 +69,6 @@ function location_alert( $location_id ) {
</div>
<?php
// Load location alerts for Lewis (post 473).
location_alert( 473 );
$this->location_alert( 473 );
?>
<a href="/hours" class="button-primary--green full add-margin link-hours">All hours &amp; locations</a>

0 comments on commit 7ad5aef

Please sign in to comment.