post_table( $filter_args ); ?>
' . esc_html( $label ), array( $this, 'settings' ), esc_attr( ABPET_Function::get_cpt() ), 'normal', 'high' ); } //=============================// public function post_table( $filter_args ): void { //echo '
';print_r($filter_args);echo '
'; $status = $filter_args['status'] ?? ''; if ( empty( $status ) || $status == 'all' ) { $status = [ 'publish', 'draft', 'private', 'trash' ]; } $page_number = absint( $filter_args['page_number'] ?? 1 ) ?: 1; $limit = absint( ( $filter_args['page_item'] ?? 0 ) ?: ABPET_Function::get_option( 'abpet_per_page_item', 20 ) ); $count = ( $page_number - 1 ) * $limit + 1; $cpt = ABPET_Function::get_cpt(); $filters['status'] = $status; $filters['posts_per_page'] = $limit; $filters['paged'] = $page_number; //echo '
';print_r($filters);echo '
'; $post_ids = ABPET_Query::get_post_id( $filters ); if ( ! empty( $post_ids ) && sizeof( $post_ids ) > 0 ) { $total_post = sizeof( ABPET_Query::get_post_id( [ 'status' => $status ] ) ); $new_post_url = admin_url( 'post-new.php?post_type=' . $cpt ); ?> $post_id, '_abpet_nonce' => wp_create_nonce( 'abpet_copy_post_action' ), ), $new_post_url ); ?>
.
[abpet-post post_id=""]
$limit, 'page_number' => $page_number, 'total' => $total_post, 'style' => 'ajax' ] ); } else { ABPET_Layout::layout_warning_info( 'not_found' ); } } public function settings(): void { $post_id = get_the_id(); $copy_post_id = isset( $_GET['copy_post'] ) ? absint( $_GET['copy_post'] ) : ''; if ( ! empty( $copy_post_id ) && isset( $_GET['_abpet_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_abpet_nonce'] ) ), 'abpet_copy_post_action' ) && current_user_can( 'edit_post', $copy_post_id ) ) { ?>
  • 🎫
  • 🗓️
  • 💰
  • 📋
  • 📚
general_configuration( $post_infos ); do_action( 'abpet_post_content', $post_infos ); ?>

*
isset( $_POST[ $key ] ) ? absint( $_POST[ $key ] ) : $default; $post_val = fn( $key, $default = '' ) => isset( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) : $default; $post_textarea = fn( $key, $default = '' ) => isset( $_POST[ $key ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $key ] ) ) : $default; $post_html = fn( $key, $default = '' ) => isset( $_POST[ $key ] ) ? wp_kses_post( wp_unslash( $_POST[ $key ] ) ) : $default; $post_int_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'absint', wp_unslash( $_POST[ $key ] ) ) : []; $post_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST[ $key ] ) ) : []; $post_textarea_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_textarea_field', wp_unslash( $_POST[ $key ] ) ) : []; $post_deep = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? map_deep( wp_unslash( $_POST[ $key ] ), 'sanitize_text_field' ) : []; $format_date = fn( $date ) => $date ? gmdate( 'Y-m-d', strtotime( $date ) ) : ''; $date_infos = []; $time_info = []; //$post_html_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'wp_kses_post', wp_unslash( $_POST[ $key ] ) ) : []; /***********************************/ $seat_type = $post_val( 'seat_type' ); $display_ticket_type = $post_val( 'display_ticket_type' ); $ticket_infos = []; $sp_infos = []; $all_ticket_types = []; if ( $display_ticket_type == 'off' ) { $all_ticket_types[] = 'price'; } $ticket_ids = $post_array( 'ticket_name' ); $price_data = $post_array( 'ticket_price' ); if ( ! empty( $ticket_ids ) ) { foreach ( $ticket_ids as $key => $id ) { if ( ! empty( $id ) ) { if ( $display_ticket_type == 'on' ) { $all_ticket_types[] = $id; } $ticket_infos[ $id ]['price'] = $price_data[ $key ] ?? 0; } } } if ( $seat_type == 'ticket' ) { $ticket_qty = $post_array( 'ticket_qty' ); $reserve_qty = $post_array( 'reserve_qty' ); $ticket_min_qty = $post_array( 'ticket_min_qty' ); $ticket_max_qty = $post_array( 'ticket_max_qty' ); $ticket_description = $post_textarea_array( 'ticket_description' ); if ( ! empty( $ticket_ids ) ) { foreach ( $ticket_ids as $key => $id ) { if ( ! empty( $id ) ) { if ( $display_ticket_type == 'on' ) { $all_ticket_types[] = $id; } $ticket_infos[ $id ] = [ 'qty' => $ticket_qty[ $key ] ?? 10, 'price' => $price_data[ $key ] ?? 0, 'reserve' => $reserve_qty[ $key ] ?? 0, 'min_qty' => $ticket_min_qty[ $key ] ?? 1, 'max_qty' => $ticket_max_qty[ $key ] ?? '', 'description' => $ticket_description[ $key ] ?? '', ]; } } } } else { $sp_ids = $post_int_array( 'sp_id' ); $sp_names = $post_array( 'sp_name' ); $all_sp_id = []; if ( ! empty( $sp_ids ) ) { foreach ( $sp_ids as $key => $id ) { if ( ! empty( $id ) ) { $all_sp_id[] = $id; $sp_infos[] = [ 'id' => $id, 'name' => $sp_names[ $key ] ?? '', ]; } } } if ( $display_ticket_type == 'on' ) { $all_ticket_types = ABPET_Function::get_sp_ticket( $all_sp_id ); } } /***********************************/ $date_infos['date_type'] = $post_val( 'date_type', 'periodic_date' ); $date_infos['periodic_start_date'] = $format_date( $post_val( 'periodic_start_date' ) ); $date_infos['periodic_end_date'] = $format_date( $post_val( 'periodic_end_date' ) ); $date_infos['periodic_after'] = $post_val( 'periodic_after', '1' ); $date_rule = $post_val( 'date_rule' ); $date_infos['date_rule'] = $post_val( 'date_rule' ); $date_rule_array = $date_rule ? explode( ',', $date_rule ) : []; if ( in_array( 'weekend', $date_rule_array ) ) { $date_infos['weekend'] = $post_val( 'weekend' ); } if ( in_array( 'specific_off_dates', $date_rule_array ) ) { $specific_off_dates = array_filter( $post_array( 'specific_off_dates' ) ); $date_infos['specific_off_dates'] = array_unique( array_map( fn( $d ) => gmdate( 'Y-m-d', strtotime( $d ) ), $specific_off_dates ) ); } if ( in_array( 'off_date_range', $date_rule_array ) ) { $off_schedules = []; $from_dates = $post_array( 'abpet_off_from' ); $to_dates = $post_array( 'abpet_off_to' ); foreach ( $from_dates as $key => $from_date ) { if ( $from_date && ! empty( $to_dates[ $key ] ) ) { $off_schedules[] = [ 'from' => $from_date, 'to' => $to_dates[ $key ] ]; } } $date_infos['off_date_range'] = $off_schedules; } if ( in_array( 'special_on_dates', $date_rule_array ) ) { $special_on_dates = $post_array( 'special_on_dates' ); $on_start = $post_array( 'special_on_time_start' ); $on_end = $post_array( 'special_on_time_end' ); $specific_on = []; foreach ( $special_on_dates as $key => $date ) { if ( $date ) { $specific_on[ $key ] = [ 'date' => $format_date( $date ), 'start' => $on_start[ $key ] ?? '', 'end' => $on_end[ $key ] ?? '' ]; } } $date_infos['special_on_dates'] = $specific_on; } $off_schedules = []; $from_dates = $post_array( 'abpet_off_from' ); $to_dates = $post_array( 'abpet_off_to' ); foreach ( $from_dates as $key => $from_date ) { if ( $from_date && ! empty( $to_dates[ $key ] ) ) { $off_schedules[] = [ 'from' => $from_date, 'to' => $to_dates[ $key ] ]; } } $date_infos['off_date_range'] = $off_schedules; /****************/ $specific_dates = $post_array( 'specific_dates' ); $specific_dates = ! empty( $specific_dates ) ? array_values( array_unique( array_filter( $specific_dates ) ) ) : []; sort( $specific_dates ); $date_infos['specific_dates'] = $specific_dates; $operation_time = []; $operation_times = $post_array( 'operation_time' ); if ( ! empty( $operation_times ) ) { $operation_time = array_values( array_unique( array_filter( $operation_times ) ) ); sort( $operation_time ); } $time_info['time'] = ! empty( $operation_time ) ? $operation_time : [ '00:00' ]; $opt_time = $post_val( 'operation_time_optional' ); $opt_time = ! empty( $opt_time ) ? explode( ',', $opt_time ) : []; if ( in_array( 'day_wise_time', $opt_time ) ) { foreach ( ABPET_Layout::week_day() as $key => $day ) { $times = $post_array( $key . '_time' ); $times = array_filter( $times ); if ( ! empty( $times ) ) { sort( $times ); $time_info['day_time'][ $key ] = array_values( array_unique( $times ) ); } } } if ( in_array( 'date_wise_time', $opt_time ) ) { $date_time_ids = $post_array( 'date_wise_time_id' ); $all_dates = $post_deep( 'date_wise_date' ); $all_times = $post_deep( 'date_wise_time' ); if ( ! empty( $date_time_ids ) ) { foreach ( $date_time_ids as $time_id ) { $date_wise_dates = $all_dates[ $time_id ] ?? []; $date_wise_time = $all_times[ $time_id ] ?? []; if ( ! empty( $date_wise_dates ) && ! empty( $date_wise_time ) ) { $clean_dates = array_filter( $date_wise_dates ); $clean_dates = reset( $clean_dates ); $clean_times = array_filter( $date_wise_time ); if ( ! empty( $clean_dates ) && ! empty( $clean_times ) ) { sort( $clean_times ); $time_info['date_times'][ $time_id ]['date'] = $clean_dates; $time_info['date_times'][ $time_id ]['time'] = array_values( array_unique( $clean_times ) ); } } } } }; if ( $date_infos['date_type'] === 'specific_date' && empty( $date_infos['specific_dates'] ) ) { $date_infos['date_type'] = 'periodic_date'; } /***********************************/ $display_additional_services = $post_val( 'display_additional_services', 'off' ); $active_global_additional = $display_additional_services == 'on' ? $post_val( 'active_global_additional', 'on' ) : 'off'; $additional_services = ( $active_global_additional == 'on' || $display_additional_services == 'off' ) ? [] : apply_filters( 'abpet_get_additional_array', [] ); $display_client_form = $post_val( 'display_client_form', 'off' ); $active_global_form = $display_client_form == 'on' ? $post_val( 'active_global_form', 'on' ) : 'off'; $abpet_form = ( $active_global_form == 'on' || $display_client_form == 'off' ) ? [] : apply_filters( 'abpet_get_form_array', [] ); $display_faq = $post_val( 'display_faq', 'off' ); $active_global_faq = $display_faq == 'on' ? $post_val( 'active_global_faq', 'on' ) : 'off'; $abpet_faq = ( $active_global_faq == 'on' || $display_faq == 'off' ) ? [] : apply_filters( 'abpet_get_faq_array', [] ); $display_tc = $post_val( 'display_tc', 'off' ); $active_global_tc = $display_tc == 'on' ? $post_val( 'active_global_tc', 'on' ) : 'off'; $abpet_tc = ( $active_global_tc == 'on' || $display_tc == 'off' ) ? [] : $post_html( 'tc_content' ); $meta_info = [ 'sale_continue' => $post_val( 'sale_continue', 'on' ), 'abpet_template' => $post_val( 'abpet_template', 'default' ), 'display_sku' => $post_val( 'display_sku', 'off' ), 'post_sku' => $post_val( 'post_sku' ), 'post_icon' => $post_val( 'post_icon' ), 'sub_title' => $post_textarea( 'sub_title' ), 'post_description' => $post_textarea( 'post_description' ), 'display_organizer' => $post_val( 'display_organizer', 'off' ), 'event_type' => $post_val( 'event_type' ), 'abpet_organizer' => $post_val( 'abpet_organizer' ), 'display_brand' => $post_val( 'display_brand', 'off' ), 'abpet_brand' => $post_val( 'abpet_brand' ), 'display_capacity' => $post_val( 'display_capacity', 'on' ), 'display_category' => $post_val( 'display_category', 'on' ), 'abpet_category' => $post_val( 'abpet_category' ), 'display_location' => $post_val( 'display_location', 'on' ), 'abpet_location' => $post_val( 'abpet_location' ), 'related_item' => $post_val( 'related_item' ), 'post_feature' => $post_val( 'post_feature' ), 'abpet_slider' => $post_val( 'abpet_slider' ), //================// 'seat_type' => $seat_type, 'display_ticket_type' => $display_ticket_type, 'min_qty' => $post_int( 'min_qty' ), 'max_qty' => $post_int( 'max_qty' ), 'ticket_infos' => $ticket_infos, 'sp_infos' => $sp_infos, 'all_ticket_type' => $all_ticket_types, //================// 'abpet_dates' => $date_infos, 'time_infos' => $time_info, 'display_additional_services' => $display_additional_services, 'active_global_additional' => $active_global_additional, 'additional_services' => $additional_services, 'display_client_form' => $display_client_form, 'active_global_form' => $active_global_form, 'display_single_form' => $post_val( 'display_single_form', 'on' ), 'abpet_form' => $abpet_form, 'display_faq' => $display_faq, 'active_global_faq' => $active_global_faq, 'abpet_faq' => $abpet_faq, 'display_tc' => $display_tc, 'active_global_tc' => $active_global_tc, 'abpet_tc' => $abpet_tc, //================// 'speaker' => $post_val( 'speaker' ), 'display_speaker' => isset( $_POST['display_speaker'] ) ? sanitize_text_field( wp_unslash( $_POST['display_speaker'] ) ) : 'on', ]; $validation_errors = $this->validate_event_configuration( $post_id, $seat_type, $ticket_infos, $sp_infos, $date_infos, $time_info ); if ( get_post_status( $post_id ) === 'publish' && ! empty( $validation_errors ) && ! $validating_status ) { $validating_status = true; wp_update_post( [ 'ID' => $post_id, 'post_status' => 'draft' ] ); $validating_status = false; set_transient( 'abpet_event_configuration_errors_' . get_current_user_id(), $validation_errors, MINUTE_IN_SECONDS ); } //=============tax================// if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) { $meta_info['_tax_status'] = $post_val( '_tax_status', 'none' ); $meta_info['_tax_class'] = $post_val( '_tax_class' ); } //=============================// $meta_info = apply_filters( 'abpet_meta_info_update', $meta_info, $post_id ); if ( sizeof( $meta_info ) > 0 ) { foreach ( $meta_info as $key => $value ) { update_post_meta( $post_id, sanitize_key( $key ), $value ); } } foreach ( [ 'abpet_category' => 'abpet_category', 'abpet_location' => 'abpet_location', 'abpet_organizer' => 'abpet_organizer', 'abpet_brand' => 'abpet_brand', 'speaker' => 'abpet_speaker', ] as $meta_key => $taxonomy ) { if ( taxonomy_exists( $taxonomy ) ) { $value = $meta_info[ $meta_key ] ?? ''; $ids = is_array( $value ) ? $value : explode( ',', (string) $value ); $ids = array_values( array_filter( array_map( 'absint', $ids ) ) ); wp_set_object_terms( $post_id, $ids, $taxonomy, false ); } } } } public function validate_event_configuration( $post_id, $seat_type, $ticket_infos, $sp_infos, $date_infos, $time_info ): array { $errors = []; if ( ! get_the_title( $post_id ) ) { $errors[] = __( 'Add an event title before publishing.', 'abp-event-ticket' ); } $date_type = $date_infos['date_type'] ?? 'periodic_date'; $dates = []; if ( $date_type === 'specific_date' ) { $dates = $date_infos['specific_dates'] ?? []; } elseif ( ! empty( $date_infos['periodic_start_date'] ) ) { $dates[] = $date_infos['periodic_start_date']; if ( ! empty( $date_infos['periodic_end_date'] ) ) { $dates[] = $date_infos['periodic_end_date']; } } else { $dates[] = current_time( 'Y-m-d' ); } $dates = array_filter( $dates, static function ( $date ) { return $date && strtotime( $date ) !== false; } ); if ( empty( $dates ) ) { $errors[] = __( 'Configure at least one valid event date.', 'abp-event-ticket' ); } $times = array_filter( $time_info['time'] ?? [], static function ( $time ) { return (bool) preg_match( '/^(?:[01]\d|2[0-3]):[0-5]\d$/', (string) $time ); } ); foreach ( $time_info['day_time'] ?? [] as $day_times ) { $times = array_merge( $times, array_filter( (array) $day_times ) ); } foreach ( $time_info['date_times'] ?? [] as $date_time ) { $times = array_merge( $times, array_filter( (array) ( $date_time['time'] ?? [] ) ) ); } // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified in the caller save_settings() before validation runs. if ( empty( $times ) || ( count( $times ) === 1 && reset( $times ) === '00:00' && empty( $_POST['operation_time'] ) ) ) { $errors[] = __( 'Configure at least one valid event session time.', 'abp-event-ticket' ); } if ( $seat_type === 'ticket' ) { $valid_tickets = array_filter( $ticket_infos, static function ( $ticket ) { return isset( $ticket['price'], $ticket['qty'] ) && (float) $ticket['price'] >= 0 && (int) $ticket['qty'] > 0; } ); if ( empty( $valid_tickets ) ) { $errors[] = __( 'Add at least one ticket type with a valid price and quantity.', 'abp-event-ticket' ); } } elseif ( empty( $sp_infos ) ) { $errors[] = __( 'Assign at least one seat plan to this event.', 'abp-event-ticket' ); } if ( empty( ABPET_Function::get_post_info( $post_id, 'link_wc_id' ) ) ) { $errors[] = __( 'The WooCommerce product could not be linked to this event.', 'abp-event-ticket' ); } return array_unique( $errors ); } public function configuration_notice(): void { $errors = get_transient( 'abpet_event_configuration_errors_' . get_current_user_id() ); if ( empty( $errors ) || ! is_array( $errors ) ) { return; } delete_transient( 'abpet_event_configuration_errors_' . get_current_user_id() ); echo '

' . esc_html__( 'Event was saved as draft because its configuration is incomplete:', 'abp-event-ticket' ) . '

'; } public function post_permanent_remove(): void { if ( ! check_ajax_referer( 'abpet_admin_ajax_nonce', 'nonce', false ) || ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'msg' => __( 'Invalid security token or Insufficient permissions.', 'abp-event-ticket' ), 'type' => 'warn' ], 403 ); } $post_id = isset( $_POST['post_id'] ) ? absint( wp_unslash( $_POST['post_id'] ) ) : 0; if ( $post_id <= 0 ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Invalid ID ..... !! ', 'abp-event-ticket' ), 'type' => 'warn' ], 400 ); } $title = get_the_title( $post_id ); $link_wc_id = absint( ABPET_Function::get_post_info( $post_id, 'link_wc_id' ) ); if ( $link_wc_id > 0 ) { wp_delete_post( $link_wc_id, true ); } wp_delete_post( $post_id, true ); wp_send_json_success( [ 'html' => '', 'msg' => $title . ' : ' . __( 'Permanently removed. ..... !! ', 'abp-event-ticket' ), 'type' => 'error' ] ); } public function post_move_trash(): void { if ( ! check_ajax_referer( 'abpet_admin_ajax_nonce', 'nonce', false ) || ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'msg' => __( 'Invalid security token or Insufficient permissions.', 'abp-event-ticket' ), 'type' => 'warn' ], 403 ); } $post_id = isset( $_POST['post_id'] ) ? absint( wp_unslash( $_POST['post_id'] ) ) : 0; if ( $post_id > 0 ) { $title = get_the_title( $post_id ); $link_wc_id = absint( ABPET_Function::get_post_info( $post_id, 'link_wc_id' ) ); if ( $link_wc_id > 0 ) { wp_trash_post( $link_wc_id ); } wp_trash_post( $post_id ); wp_send_json_success( [ 'html' => '', 'msg' => $title . ' : ' . __( 'Moved to trash successfully...... !! ', 'abp-event-ticket' ), 'type' => 'warn' ] ); } wp_send_json_error( [ 'html' => '', 'msg' => __( 'Invalid ID ..... !! ', 'abp-event-ticket' ), 'type' => 'warn' ], 400 ); } public function post_restore(): void { if ( ! check_ajax_referer( 'abpet_admin_ajax_nonce', 'nonce', false ) || ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'msg' => __( 'Invalid security token or Insufficient permissions.', 'abp-event-ticket' ), 'type' => 'warn' ], 403 ); } $post_id = isset( $_POST['post_id'] ) ? absint( wp_unslash( $_POST['post_id'] ) ) : 0; if ( $post_id > 0 ) { $link_wc_id = absint( ABPET_Function::get_post_info( $post_id, 'link_wc_id' ) ); if ( $link_wc_id > 0 ) { wp_untrash_post( $link_wc_id ); } wp_untrash_post( $post_id ); $updated_post = [ 'ID' => $post_id, 'post_status' => 'publish', ]; wp_update_post( $updated_post ); $title = get_the_title( $post_id ); wp_send_json_success( [ 'html' => '', 'msg' => $title . ' : ' . __( 'Restored successfully...... !! ', 'abp-event-ticket' ), 'type' => 'success' ] ); } wp_send_json_error( [ 'html' => '', 'msg' => __( 'Invalid ID ..... !! ', 'abp-event-ticket' ), 'type' => 'warn' ], 400 ); } public function reload_post_list(): void { if ( ! check_ajax_referer( 'abpet_admin_ajax_nonce', 'nonce', false ) || ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'msg' => __( 'Invalid security token or Insufficient permissions.', 'abp-event-ticket' ), 'type' => 'warn' ], 403 ); } $post_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST[ $key ] ) ) : []; $filter_args = $post_array( 'filter_args' ); ob_start(); $this->post_table( $filter_args ); $table_html = ob_get_clean(); wp_send_json_success( [ 'html' => $table_html, 'type' => 'success', 'msg' => __( 'Post List Loaded successfully...... !! ', 'abp-event-ticket' ) ] ); } } new ABPET_Post(); }