650, 'show_legend' => 'yes', ), $atts, 'yacht_calendar_all' ); // Lazy-load widget class for the View helper. if ( ! class_exists( '\YachtBooking\Calendar_All_View' ) ) { require_once YACHT_BOOKING_PLUGIN_DIR . 'frontend/class-calendar-widget-all.php'; } $dom_id = 'yacht-calendar-all-' . wp_rand( 1000, 9999 ); $height = (int) $atts['height']; $show_legend = 'yes' === strtolower( (string) $atts['show_legend'] ); return Calendar_All_View::render( $dom_id, $height, $show_legend ); } /** * Get yachts for quick switcher. * * @return array> */ private function get_yacht_switcher_items() { $yachts = get_posts( array( 'post_type' => 'yacht', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ) ); $items = array(); foreach ( $yachts as $yacht ) { $items[] = array( 'id' => (int) $yacht->ID, 'title' => get_the_title( $yacht ), 'description' => wp_kses_post( wpautop( $yacht->post_content ) ), ); } return $items; } /** * Render quick yacht switcher. * * @param array> $yachts Yacht items. * @param int $active_id Active yacht ID. * @return void */ private function render_yacht_switcher( $yachts, $active_id ) { $other_yachts = array_filter( $yachts, static function( $yacht_item ) use ( $active_id ) { return (int) $yacht_item['id'] !== (int) $active_id; } ); if ( empty( $other_yachts ) ) { return; } ?>
0, 'show_form' => 'yes', 'height' => 600, 'primary_color' => '#2271b1', 'available_color' => '#35b56a', 'booked_color' => '#e53935', ), $atts, 'yacht_calendar' ); $yacht_id = (int) $atts['yacht_id']; // If no yacht_id provided, get first yacht if ( ! $yacht_id ) { $yachts = get_posts( array( 'post_type' => 'yacht', 'posts_per_page' => 1, 'orderby' => 'ID', 'order' => 'ASC', 'fields' => 'ids', ) ); if ( empty( $yachts ) ) { return '
' . '

' . esc_html__( 'Błąd:', 'yacht-booking' ) . ' ' . esc_html__( 'Brak jachtów w systemie. Dodaj przynajmniej jeden jacht w panelu administratora.', 'yacht-booking' ) . '

'; } $yacht_id = $yachts[0]; } $yacht = get_post( $yacht_id ); if ( ! $yacht || 'yacht' !== $yacht->post_type ) { return '
' . '

' . esc_html__( 'Błąd:', 'yacht-booking' ) . ' ' . esc_html__( 'Nie znaleziono jachtu o podanym ID.', 'yacht-booking' ) . '

'; } $booking_enabled = Settings::is_booking_enabled(); $yacht_switcher = $this->get_yacht_switcher_items(); $show_form = $booking_enabled && 'yes' === strtolower( $atts['show_form'] ); $height = (int) $atts['height']; $primary_color = sanitize_hex_color( $atts['primary_color'] ); $available_bg = sanitize_hex_color( $atts['available_color'] ); $booked_bg = sanitize_hex_color( $atts['booked_color'] ); $calendar_id = 'yacht-calendar-' . wp_rand( 1000, 9999 ); $terms_url = Settings::get_terms_page_url(); ob_start(); ?>
render_yacht_switcher( $yacht_switcher, $yacht_id ); ?>

post_title ) ); ?> post_title ) ); ?>

post_content ? '' : ' style="display: none;"'; ?>> post_content ) ); ?>

' . esc_html__( 'regulamin', 'yacht-booking' ) . '' ); ?>