'Rp', 'USD' => '$', 'SGD' => 'S$', 'MYR' => 'RM', 'PHP' => '₱', 'EUR' => '€', 'AUD' => 'A$', 'JPY' => '¥', ); public static function init() { add_action( 'admin_menu', array( __CLASS__, 'menu' ), 40 ); add_action( 'admin_post_seatt_setup_dismiss', array( __CLASS__, 'dismiss' ) ); add_action( 'admin_post_seatt_setup_save', array( __CLASS__, 'save' ) ); add_action( 'admin_notices', array( __CLASS__, 'notice' ) ); } /** * Kept for backward compatibility with the activation hook. The * wizard no longer takes over the admin after install (it blocked * access to every other screen until finished or skipped) — it is * only offered through a dismissible notice. */ public static function flag_redirect() { delete_option( 'seatt_setup_redirect' ); } public static function url( $step = 1 ) { return admin_url( 'admin.php?page=seatt-setup&step=' . intval( $step ) ); } /** Registered without a parent: reachable from the notice, but no * "Setup" item in the admin sidebar. */ public static function menu() { add_submenu_page( 'options.php', __( 'Setup', 'seathive' ), __( 'Setup', 'seathive' ), 'manage_options', 'seatt-setup', array( __CLASS__, 'render' ) ); } public static function dismiss() { if ( ! current_user_can( 'manage_options' ) || ! check_admin_referer( 'seatt_setup_dismiss' ) ) { wp_die( esc_html__( 'Not allowed.', 'seathive' ) ); } update_option( 'seatt_setup_done', 1 ); wp_safe_redirect( wp_get_referer() ?: admin_url( 'admin.php?page=seatt-main' ) ); exit; } public static function notice() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( get_option( 'seatt_setup_done' ) || ! current_user_can( 'manage_options' ) || ! $screen || false === strpos( (string) $screen->id, 'seatt' ) || false !== strpos( (string) $screen->id, 'seatt-setup' ) ) { return; } // Only while the site has no events yet — once anything exists, // the admin clearly knows their way around. if ( get_posts( array( 'post_type' => 'seatt_event', 'post_status' => 'any', 'numberposts' => 1, 'fields' => 'ids' ) ) ) { return; } printf( '
', esc_html__( 'New to SeatHive? The 2-minute setup creates your first event and booking page for you.', 'seathive' ), esc_url( self::url( 1 ) ), esc_html__( 'Start setup', 'seathive' ), esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=seatt_setup_dismiss' ), 'seatt_setup_dismiss' ) ), esc_html__( 'No thanks', 'seathive' ) ); } /* ---------------- saving ---------------- */ public static function save() { if ( ! current_user_can( 'manage_options' ) || ! check_admin_referer( 'seatt_setup' ) ) { wp_die( esc_html__( 'Not allowed.', 'seathive' ) ); } $step = intval( $_POST['step'] ?? 1 ); if ( 1 === $step ) { $code = strtoupper( sanitize_text_field( wp_unslash( $_POST['currency'] ?? 'IDR' ) ) ); if ( ! isset( self::CURRENCIES[ $code ] ) ) { $code = 'IDR'; } update_option( 'seatt_currency_code', $code ); update_option( 'seatt_currency_symbol', self::CURRENCIES[ $code ] ); wp_safe_redirect( self::url( 2 ) ); exit; } if ( 2 === $step ) { $gw = sanitize_key( $_POST['gateway'] ?? 'manual' ); if ( ! in_array( $gw, array( 'manual', 'doku', 'xendit', 'stripe', 'paypal', 'mollie' ), true ) ) { $gw = 'manual'; } update_option( 'seatt_payment_gateway', $gw ); wp_safe_redirect( self::url( 3 ) ); exit; } if ( 3 === $step ) { $result = self::create_event( sanitize_text_field( wp_unslash( $_POST['title'] ?? '' ) ), sanitize_text_field( wp_unslash( $_POST['date'] ?? '' ) ), 'free' === sanitize_key( wp_unslash( $_POST['booking_type'] ?? '' ) ) ? 'free' : 'paid', floatval( $_POST['price_standard'] ?? 0 ), floatval( $_POST['price_vip'] ?? 0 ) ); if ( is_wp_error( $result ) ) { wp_safe_redirect( add_query_arg( 'seatt_err', rawurlencode( $result->get_error_message() ), self::url( 3 ) ) ); exit; } update_option( 'seatt_setup_event', $result, false ); update_option( 'seatt_setup_done', 1 ); wp_safe_redirect( self::url( 4 ) ); exit; } if ( isset( $_POST['skip'] ) ) { update_option( 'seatt_setup_done', 1 ); } wp_safe_redirect( admin_url( 'admin.php?page=seatt-main' ) ); exit; } /** * Creates a published event plus a published page carrying its * booking shortcode. Returns array( event_id, page_id ) or WP_Error. */ public static function create_event( $title, $date, $type, $price_std, $price_vip ) { if ( '' === $title ) { return new WP_Error( 'seatt_setup', __( 'Please give the event a name.', 'seathive' ) ); } if ( $date && ! preg_match( '/^\d{4}-\d{2}-\d{2}$/', $date ) ) { return new WP_Error( 'seatt_setup', __( 'Please pick a valid date.', 'seathive' ) ); } $event_id = wp_insert_post( array( 'post_type' => 'seatt_event', 'post_status' => 'publish', 'post_title' => $title ), true ); if ( is_wp_error( $event_id ) ) { return $event_id; } update_post_meta( $event_id, '_seatt_event_date', $date ); update_post_meta( $event_id, '_seatt_booking_type', $type ); update_post_meta( $event_id, '_seatt_price_standard', max( 0, $price_std ) ); update_post_meta( $event_id, '_seatt_price_vip', max( 0, $price_vip ) ); if ( ! seatt_seatmap_enabled() && class_exists( 'SEATT_Tickets' ) ) { SEATT_Tickets::save( $event_id, 'tickets', array( array( 'name' => __( 'Standard', 'seathive' ), 'price' => 'free' === $type ? 0 : max( 0, $price_std ), 'quota' => 100, 'max' => 10 ), array( 'name' => __( 'VIP', 'seathive' ), 'price' => 'free' === $type ? 0 : max( 0, $price_vip ), 'quota' => 50, 'max' => 10 ), ) ); } $page_id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => $title, 'post_content' => '[seatt_booking event_id="' . intval( $event_id ) . '"]', ), true ); if ( is_wp_error( $page_id ) ) { return $page_id; } return array( 'event_id' => (int) $event_id, 'page_id' => (int) $page_id ); } /* ---------------- rendering ---------------- */ public static function render() { $step = max( 1, min( 4, intval( $_GET['step'] ?? 1 ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only: chooses what to display $names = array( 1 => __( 'Currency', 'seathive' ), 2 => __( 'Payment', 'seathive' ), 3 => __( 'First event', 'seathive' ), 4 => __( 'Done', 'seathive' ) ); ?>