Changeset 7071 for sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/addons/allergy.php
- Timestamp:
- 04/10/2018 12:50:17 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/addons/allergy.php
r7040 r7071 18 18 const SLUG = 'allergy'; 19 19 20 public $question = ''; 21 22 public $options = array(); 23 20 24 /** 21 25 * Hook into WordPress and Camptix. 22 26 */ 23 27 public function camptix_init() { 28 $this->question = __( 'Do you have a life-threatening allergy that would affect your experience at WordCamp?', 'wordcamporg' ); 29 30 $this->options = array( 31 'yes' => _x( 'Yes (we will contact you)', 'ticket registration option', 'wordcamporg' ), 32 'no' => _x( 'No', 'ticket registration option', 'wordcamporg' ), 33 ); 34 24 35 // Registration field 25 36 add_action( 'camptix_attendee_form_after_questions', array( $this, 'render_registration_field' ), 11, 2 ); … … 33 44 add_action( 'camptix_form_edit_attendee_update_post_meta', array( $this, 'validate_save_ticket_info_field' ), 10, 2 ); 34 45 add_action( 'camptix_form_edit_attendee_after_questions', array( $this, 'render_ticket_info_field' ), 11 ); 46 47 // Metabox 48 add_filter( 'camptix_metabox_attendee_info_additional_rows', array( $this, 'add_metabox_row' ), 11, 2 ); 35 49 } 36 50 … … 50 64 <tr class="tix-row-<?php echo esc_attr( self::SLUG ); ?>"> 51 65 <td class="tix-required tix-left"> 52 <?php e sc_html_e( 'Do you have a life-threatening allergy that would affect your experience at WordCamp?', 'wordcamporg'); ?>66 <?php echo esc_html( $this->question ); ?> 53 67 <span class="tix-required-star">*</span> 54 68 </td> 55 69 56 70 <td class="tix-right"> 57 <label><input name="tix_attendee_info[<?php echo esc_attr( $i ); ?>][<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="yes" <?php checked( 'yes', $current_data[ self::SLUG ] ); ?> /> <?php e sc_html( _ex( 'Yes (we will contact you)', 'ticket registration option', 'wordcamporg' )); ?></label>71 <label><input name="tix_attendee_info[<?php echo esc_attr( $i ); ?>][<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="yes" <?php checked( 'yes', $current_data[ self::SLUG ] ); ?> /> <?php echo esc_html( $this->options['yes'] ); ?></label> 58 72 <br /> 59 <label><input name="tix_attendee_info[<?php echo esc_attr( $i ); ?>][<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="no" <?php checked( 'no', $current_data[ self::SLUG ] ); ?> /> <?php e sc_html( _ex( 'No', 'ticket registration option', 'wordcamporg' )); ?></label>73 <label><input name="tix_attendee_info[<?php echo esc_attr( $i ); ?>][<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="no" <?php checked( 'no', $current_data[ self::SLUG ] ); ?> /> <?php echo esc_html( $this->options['no'] ); ?></label> 60 74 </td> 61 75 </tr> … … 168 182 <tr class="tix-row-<?php echo esc_attr( self::SLUG ); ?>"> 169 183 <td class="tix-required tix-left"> 170 <?php e sc_html_e( 'Do you have a life-threatening allergy that would affect your experience at WordCamp?', 'wordcamporg'); ?>184 <?php echo esc_html( $this->question ); ?> 171 185 <span class="tix-required-star">*</span> 172 186 </td> 173 187 174 188 <td class="tix-right"> 175 <label><input name="tix_ticket_info[<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="yes" <?php checked( 'yes', $current_data[ self::SLUG ] ); ?> /> <?php e sc_html( _ex( 'Yes (we will contact you)', 'ticket registration option', 'wordcamporg' )); ?></label>189 <label><input name="tix_ticket_info[<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="yes" <?php checked( 'yes', $current_data[ self::SLUG ] ); ?> /> <?php echo esc_html( $this->options['yes'] ); ?></label> 176 190 <br /> 177 <label><input name="tix_ticket_info[<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="no" <?php checked( 'no', $current_data[ self::SLUG ] ); ?> /> <?php e sc_html( _ex( 'No', 'ticket registration option', 'wordcamporg' )); ?></label>191 <label><input name="tix_ticket_info[<?php echo esc_attr( self::SLUG ); ?>]" type="radio" value="no" <?php checked( 'no', $current_data[ self::SLUG ] ); ?> /> <?php echo esc_html( $this->options['no'] ); ?></label> 178 192 </td> 179 193 </tr> 180 194 181 195 <?php 196 } 197 198 /** 199 * Add a row to the Attendee Info metabox table for the new field and value. 200 * 201 * @param array $rows 202 * @param WP_Post $post 203 * 204 * @return mixed 205 */ 206 public function add_metabox_row( $rows, $post ) { 207 $value = get_post_meta( $post->ID, 'tix_' . self::SLUG, true ) ?: ''; 208 if ( $value && isset( $this->options[ $value ] ) ) { 209 $value = $this->options[ $value ]; 210 } 211 $new_row = array( $this->question, esc_html( $value ) ); 212 213 add_filter( 'locale', array( $this, 'set_locale_to_en_US' ) ); 214 215 $ticket_row = array_filter( $rows, function( $row ) { 216 if ( 'Ticket' === $row[0] ) { 217 return true; 218 } 219 220 return false; 221 } ); 222 223 remove_filter( 'locale', array( $this, 'set_locale_to_en_US' ) ); 224 225 if ( ! empty( $ticket_row ) ) { 226 $ticket_row_key = key( $ticket_row ); 227 $row_indexes = array_keys( $rows ); 228 $position = array_search( $ticket_row_key, $row_indexes ); 229 230 $slice = array_slice( $rows, $position ); 231 232 array_unshift( $slice, $new_row ); 233 array_splice( $rows, $position, count( $rows ), $slice ); 234 } else { 235 $rows[] = $new_row; 236 } 237 238 return $rows; 182 239 } 183 240
Note: See TracChangeset
for help on using the changeset viewer.