| | 14 | add_action( 'camptix_notices', array( $this, 'ticket_form_message' ), 8 ); |
| | 15 | add_action( 'camptix_attendee_form_additional_info', array( $this, 'get_attendee_form_username_field' ), 10, 3 ); |
| | 16 | add_filter( 'camptix_form_register_complete_attendee_object', array( $this, 'add_username_to_attendee_object' ), 10, 2 ); |
| | 17 | add_action( 'camptix_checkout_update_post_meta', array( $this, 'save_checkout_unsername_meta' ), 10, 2 ); |
| | 18 | add_filter( 'camptix_save_attendee_post_add_search_meta', array( $this, 'get_attendee_search_meta' ) ); |
| | 19 | add_filter( 'camptix_attendee_report_extra_columns', array( $this, 'get_attendee_report_extra_columns' ) ); |
| | 20 | add_filter( 'camptix_attendee_report_column_value_username', array( $this, 'get_attendee_username_meta' ), 10, 2 ); |
| | 21 | add_filter( 'camptix_metabox_attendee_info_additional_rows', array( $this, 'get_attendee_metabox_rows' ), 10, 2 ); |
| | 22 | add_action( 'camptix_form_edit_attendee_update_post_meta', array( $this, 'update_attendee_post_meta' ), 10, 2 ); |
| | 23 | add_action( 'camptix_form_edit_attendee_additional_info', array( $this, 'get_edit_attendee_username_field' ) ); |
| 42 | | wp_safe_redirect( wp_login_url( site_url( $_SERVER['REQUEST_URI'] ) ) ); |
| | 54 | // merge the _post and _get for passing after successful login. |
| | 55 | // new array should contain tix_action, tix_tickets_selected, and tix_coupon |
| | 56 | // the 3 need to be passed to continue the purchase process after login |
| | 57 | $urlData = array_merge( $_POST, $_GET ); |
| | 58 | |
| | 59 | // had an issue with site_url( $_SERVER['REQUEST_URI'] ) when WP is in a subdirectory |
| | 60 | // switched to $GLOBALS['camptix']->get_tickets_url() and appending the query vars to pass on after login |
| | 61 | wp_safe_redirect( wp_login_url( $GLOBALS['camptix']->get_tickets_url() . '?' . http_build_query( $urlData ) ) ); |
| | 71 | } else if ( is_user_logged_in() && isset( $_REQUEST['tix_action'] ) && isset( $_GET['tix_tickets_selected'] ) ) { |
| | 72 | |
| | 73 | // if the ticket(s) requested are in the url, put them in _post so camptix can pick up and run after login |
| | 74 | $_POST['tix_tickets_selected'] = $_GET['tix_tickets_selected']; |
| | 75 | } |
| | 76 | } |
| | 77 | |
| | 78 | public function ticket_form_message() { |
| | 79 | // add message to top of tickets initial form to alert them that they will have to login |
| | 80 | if ( ! is_user_logged_in() ) { |
| | 81 | $GLOBALS['camptix']->notice( __( 'You will be prompted to login after clicking register.', 'camptix' ) ); |
| | 82 | } |
| | 83 | } |
| | 84 | |
| | 85 | public function get_attendee_form_username_field( $form_data, $currentIteration, $totalCount ) { |
| | 86 | ?> |
| | 87 | <tr class="tix-row-username"> |
| | 88 | <td class="tix-required tix-left"><?php _e( 'Username', 'camptix' ); ?> <span class="tix-required-star">*</span></td> |
| | 89 | <?php |
| | 90 | $value = ''; |
| | 91 | if ( isset( $form_data['tix_attendee_info'][$currentIteration]['username'] ) ) { |
| | 92 | $value = $form_data['tix_attendee_info'][$currentIteration]['username']; |
| | 93 | } else if ( $currentIteration == 1 ) { |
| | 94 | $current_user = wp_get_current_user(); |
| | 95 | $value = $current_user->user_login; |
| | 96 | } |
| | 97 | ?> |
| | 98 | <td class="tix-right"><input name="tix_attendee_info[<?php echo $currentIteration; ?>][username]" type="text" value="<?php echo esc_attr( $value ); ?>" /></td> |
| | 99 | </tr> |
| | 100 | <?php |
| | 101 | } |
| | 102 | |
| | 103 | public function add_username_to_attendee_object( $attendee, $attendee_info ) { |
| | 104 | $attendee->username = sanitize_text_field( $attendee_info['username'] ); |
| | 105 | if ( empty( $attendee->username ) ) { |
| | 106 | $GLOBALS['camptix']->error_flag( 'required_fields' ); |
| | 108 | /* Need a way to send a better error message for when the provided username doesn't exist */ |
| | 109 | $testUsername = username_exists( $attendee->username ); |
| | 110 | if ( empty( $testUsername ) ) { |
| | 111 | $GLOBALS['camptix']->error_flag( 'required_fields' ); |
| | 112 | } |
| | 113 | return $attendee; |
| | 114 | } |
| | 115 | |
| | 116 | public function save_checkout_unsername_meta( $post_id, $attendee ) { |
| | 117 | update_post_meta( $post_id, 'tix_username', $attendee->username ); |
| | 118 | } |
| | 119 | |
| | 120 | public function get_attendee_search_meta( $attendee_search_meta ) { |
| | 121 | $attendee_search_meta[] = 'tix_username'; |
| | 122 | return $attendee_search_meta; |
| | 123 | } |
| | 124 | |
| | 125 | public function get_attendee_report_extra_columns( $extra_columns ) { |
| | 126 | $extra_columns['username'] = __( 'User Name', 'camptix' ); |
| | 127 | } |
| | 128 | |
| | 129 | public function get_attendee_username_meta( $data, $attendee ) { |
| | 130 | return get_post_meta( $attendee->ID, 'tix_username', true ); |
| | 131 | } |
| | 132 | |
| | 133 | public function get_attendee_metabox_rows( $rows, $post ) { |
| | 134 | $rows[] = array( __( 'User Name', 'camptix' ), esc_html( get_post_meta( $post->ID, 'tix_username', true ) ) ); |
| | 135 | return $rows; |
| | 136 | } |
| | 137 | |
| | 138 | public function update_attendee_post_meta( $new_ticket_info, $attendee ) { |
| | 139 | update_post_meta( $attendee->ID, 'tix_username', sanitize_text_field( $new_ticket_info['username'] ) ); |
| | 140 | } |
| | 141 | |
| | 142 | public function get_edit_attendee_username_field( $attendee ) { |
| | 143 | ?> |
| | 144 | <tr> |
| | 145 | <td class="tix-required tix-left"><?php _e( 'Username', 'camptix' ); ?> <span class="tix-required-star">*</span></td> |
| | 146 | <td class="tix-right"><input name="tix_ticket_info[username]" type="text" value="<?php echo esc_attr( get_post_meta( $attendee->ID, 'tix_username', true ) ); ?>" /></td> |
| | 147 | </tr> |
| | 148 | <?php |