get_option( 'airy_wishlist_page_layout', 'table' ), 'columns' => '3', ), $atts ); $data = Airy_Wishlist_Data::instance(); // Detect a shared wishlist view via public token. // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only public view keyed by an unguessable token, no state change. $token = isset( $_GET['airy_wid'] ) ? sanitize_text_field( wp_unslash( $_GET['airy_wid'] ) ) : ''; // Guests can't use the wishlist when guest wishlists are disabled (shared views are still allowed). if ( '' === $token && ! $data->is_enabled_for_visitor() ) { return $this->get_guest_disabled_notice(); } $is_shared = false; $wishlists = array(); $active_id = 0; // Reset render context. $this->ctx_multiple = false; $this->ctx_wishlists = array(); $this->ctx_active_id = 0; if ( '' !== $token ) { $shared = $data->get_shared_wishlist( $token ); if ( null === $shared ) { return $this->get_shared_not_found(); } $is_shared = true; $items = $shared['items']; } else { // Owner view contains personalised data; prevent full-page caches from serving it to others. if ( ! defined( 'DONOTCACHEPAGE' ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Standard WordPress / cache-plugin no-cache constant. define( 'DONOTCACHEPAGE', true ); } if ( $data->is_multiple_enabled() ) { $wishlists = $data->get_wishlists(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list selection; ownership is validated below. $active_id = isset( $_GET['airy_list'] ) ? absint( $_GET['airy_list'] ) : 0; if ( ! $active_id || ! $data->owns_wishlist( $active_id ) ) { $active_id = ! empty( $wishlists ) ? (int) $wishlists[0]->id : 0; } // Expose context to the item renderers (move dropdown, sharing). $this->ctx_multiple = true; $this->ctx_wishlists = $wishlists; $this->ctx_active_id = $active_id; $items = $active_id ? $data->get_items_for( $active_id ) : array(); } else { $items = $data->get_items(); } } ob_start(); do_action( 'airy_wishlist_before_table', $is_shared ); if ( $is_shared ) { $this->render_shared_heading(); } if ( ! $is_shared && $data->is_multiple_enabled() ) { $this->render_wishlist_switcher( $wishlists, $active_id ); } // Stock/price notification opt-in (shown when the feature is enabled). if ( ! $is_shared && 'yes' === get_option( 'airy_wishlist_notify_enabled', 'no' ) ) { if ( is_user_logged_in() ) { // Logged-in customers get the per-wishlist opt-in toggle. $current = null; if ( $data->is_multiple_enabled() ) { foreach ( $wishlists as $wishlist ) { if ( (int) $wishlist->id === (int) $active_id ) { $current = $wishlist; break; } } } else { $current = $data->get_wishlist(); } if ( $current ) { $this->render_notify_toggle( $current ); } } else { // Guests can't receive notifications (no account email); prompt to log in. $this->render_notify_login_prompt(); } } if ( empty( $items ) ) { $this->render_empty_wishlist(); } elseif ( 'grid' === $atts['layout'] ) { $this->render_grid_layout( $items, $atts['columns'], $is_shared ); } else { $this->render_table_layout( $items, $is_shared ); } do_action( 'airy_wishlist_after_table', $is_shared ); return ob_get_clean(); } /** * Message shown when a shared wishlist token is invalid or expired. * * @return string HTML output. */ private function get_shared_not_found() { ob_start(); ?>