sessions = $sessions; $this->settings = $settings; $this->assets = $assets; } /** * {@inheritdoc} */ public function register(): void { add_shortcode( self::SHORTCODE, array( $this, 'render' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_on_portal_page' ) ); } /** * Loads the style in the on the check-in page, even when a page builder runs the shortcode late. * * @since 0.1.0 * * @return void */ public function maybe_enqueue_on_portal_page(): void { $portal_id = (int) $this->settings->get( 'portal_page', 0 ); if ( $portal_id && is_singular() && get_queried_object_id() === $portal_id ) { $this->assets->enqueue_public(); } } /** * Renders the shortcode. * * @since 0.1.0 * * @param array|string $atts Shortcode attributes. * @return string */ public function render( $atts = array() ): string { $atts = shortcode_atts( array( 'session' => 0 ), (array) $atts, self::SHORTCODE ); $session_id = absint( $atts['session'] ); if ( ! $session_id && isset( $_GET[ PortalUrl::QUERY_ARG ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Public read-only page; the value is cast to an integer. $session_id = absint( wp_unslash( $_GET[ PortalUrl::QUERY_ARG ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } $now = new \DateTimeImmutable( 'now', wp_timezone() ); $session = $session_id ? $this->sessions->find( $session_id ) : $this->sessions->current_or_next( $now->format( 'Y-m-d' ), $now->format( 'H:i:s' ) ); if ( ! $session ) { return '
' . esc_html__( 'No interview sessions are currently open or scheduled. If you received an invitation, please use the exact check-in link provided or contact the recruitment team.', 'interviewnea' ) . '
'; } if ( ! $this->assets->enqueue_public() ) { return '
' . esc_html__( 'The check-in page is not available right now. Please contact the recruitment team.', 'interviewnea' ) . '
'; } $start = \DateTimeImmutable::createFromFormat( '!Y-m-d', $session->session_date, wp_timezone() ); $config = array( 'apiUrl' => esc_url_raw( rest_url( 'interviewnea/v1/' ) ), 'pollSeconds' => Rules::POLL_SECONDS, 'organization' => (string) $this->settings->get( 'organization_name', '' ), 'contactPhone' => (string) $this->settings->get( 'contact_phone', '' ), 'contactEmail' => (string) $this->settings->get( 'contact_email', '' ), 'timezone' => wp_timezone_string(), 'session' => array( 'id' => (int) $session->id, 'title' => $session->title, 'dateLabel' => $start ? wp_date( 'F j, Y', $start->setTime( 12, 0 )->getTimestamp(), wp_timezone() ) : $session->session_date, 'timeLabel' => substr( $session->start_time, 0, 5 ) . '–' . substr( $session->end_time, 0, 5 ), 'checkinBeforeMinutes' => (int) $session->checkin_before_minutes, ), ); return '
' . esc_html__( 'Loading the waiting room…', 'interviewnea' ) . '
'; } }