Inventory_Presser_Shortcode_Hours_Today::create_sentence( array $days )
create_sentence
On This Page
Description Description
Examines the array of $days and generates the sentence, the core feature of this shortcode.
Parameters Parameters
- $days
-
(array) (Required) An array of Inventory_Presser_Business_Day objects
Return Return
(string) A string like "Open today until 5:00pm" or "Closed until 9:00am on Monday"
Source Source
File: includes/shortcode/class-shortcode-hours-today.php
function create_sentence( $days ) { if ( null === $days || 0 === count( $days ) ) { return ''; } // Find today. It might not be in the array at all. $today = null; $today_weekday = gmdate( 'w', current_time( 'timestamp' ) ); // 0 if today is Sunday foreach ( $days as $day ) { if ( strval( $day->weekday ) === $today_weekday ) { $today = $day; break; } } // are we open right now? if ( null !== $today && $today->open_right_now() ) { // currently open return __( 'Open today until ', 'inventory-presser' ) . $today->close_string(); } elseif ( null != $today && $today->open_later_today() ) { // not yet open today $open_string = $today->open_string(); if ( '' == $open_string ) { return ''; } return __( 'Opening at ', 'inventory-presser' ) . $open_string . __( ' today', 'inventory-presser' ); } // Find the next day we are open. $next_open_day = self::find_next_open_day( $days ); if ( null === $next_open_day ) { return ''; } // closed today, tell them about the next time we are open $str = __( 'Closed until ', 'inventory-presser' ) . $next_open_day->open_string(); // If $next_open_day is tomorrow, output "tomorrow" instead of "on Tuesday" if ( $next_open_day->is_tomorrow() ) { $str .= __( ' tomorrow', 'inventory-presser' ); } else { $str .= __( ' on ', 'inventory-presser' ) . ucfirst( array_keys( INVP::weekdays() )[ $next_open_day->weekday - 1 ] ); } return $str; }
Expand full source codeCollapse full source codeView on Github