status_manager = $status_manager; $this->scheduler = $scheduler; } /** * Register shortcode. * * @return void */ public function register() { add_shortcode( 'store_status', array( $this, 'render' ) ); add_shortcode( 'abct_next_opening', array( $this, 'render_next_opening' ) ); add_shortcode( 'abct_closed_message', array( $this, 'render_closed_message' ) ); } /** * Render shortcode output. * * @param array $atts Attributes. * @return string */ public function render( $atts ) { $atts = shortcode_atts( array( 'show_next_opening' => '1', ), $atts, 'store_status' ); $state = $this->status_manager->get_state(); $is_online = 'online' === $state; $label = $is_online ? __( 'Online', 'abct-smart-orders' ) : __( 'Offline', 'abct-smart-orders' ); $html = '' . esc_html( $label ) . ''; if ( 'offline_schedule' === $state && '1' === $atts['show_next_opening'] ) { $next = $this->status_manager->get_next_opening_text(); if ( '' !== $next ) { $html .= ' ' . sprintf( /* translators: %s: next opening datetime */ esc_html__( 'Next opening: %s', 'abct-smart-orders' ), esc_html( $next ) ) . ''; } } return $html; } /** * Render the next opening shortcode. * * @return string */ public function render_next_opening() { $next = $this->status_manager->get_next_opening_text( false ); return '' !== $next ? esc_html( $next ) : ''; } /** * Render the final closed message shortcode. * * @return string */ public function render_closed_message() { $message = $this->status_manager->get_closed_message(); return '' !== $message ? nl2br( esc_html( $message ) ) : ''; } }