Making WordPress.org


Ignore:
Timestamp:
04/10/2018 12:50:17 AM (8 years ago)
Author:
coreymckrill
Message:

WordCamp tickets: Wording changes, add rows to Attendee Info table

  • Change the wording from "special accommodations" to "accessibility needs" to avoid confusion. Some interpret "accommodations" as referring to lodging.
  • Add the answers to the allergy, accessibility, and Code of Conduct questions to the Attendee Info metabox table.
  • Add the allergy, accessibility, and Code of Conduct fields to the list of default fields in the Questions metabox.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/addons/accommodations.php

    r7040 r7071  
    1313 * Add a non-optional attendee field indicating if they require special accommodations.
    1414 *
     15 * Note that the user-facing wording has been changed to "accessibility needs" to avoid confusion for attendees and translators.
     16 *
    1517 * @package WordCamp\CampTix_Tweaks
    1618 */
     
    1820    const SLUG = 'accommodations';
    1921
     22    public $question = '';
     23
     24    public $options = array();
     25
    2026    /**
    2127     * Hook into WordPress and Camptix.
    2228     */
    2329    public function camptix_init() {
     30        $this->question = __( 'Do you have any accessibility needs, such as a sign language interpreter or wheelchair access, to participate in WordCamp?', 'wordcamporg' );
     31
     32        $this->options = array(
     33            'yes' => _x( 'Yes (we will contact you)', 'ticket registration option', 'wordcamporg' ),
     34            'no'  => _x( 'No', 'ticket registration option', 'wordcamporg' ),
     35        );
     36
    2437        // Registration field
    2538        add_action( 'camptix_attendee_form_after_questions', array( $this, 'render_registration_field' ), 12, 2 );
     
    3346        add_action( 'camptix_form_edit_attendee_update_post_meta', array( $this, 'validate_save_ticket_info_field' ), 10, 2 );
    3447        add_action( 'camptix_form_edit_attendee_after_questions', array( $this, 'render_ticket_info_field' ), 12 );
     48
     49        // Metabox
     50        add_filter( 'camptix_metabox_attendee_info_additional_rows', array( $this, 'add_metabox_row' ), 12, 2 );
    3551    }
    3652
     
    5066        <tr class="tix-row-<?php echo esc_attr( self::SLUG ); ?>">
    5167            <td class="tix-required tix-left">
    52                 <?php esc_html_e( 'Do you require special accommodations, such as a sign language interpreter or wheelchair access, to participate in WordCamp?', 'wordcamporg' ); ?>
     68                <?php echo esc_html( $this->question ); ?>
    5369                <span class="tix-required-star">*</span>
    5470            </td>
     
    168184        <tr class="tix-row-<?php echo esc_attr( self::SLUG ); ?>">
    169185            <td class="tix-required tix-left">
    170                 <?php esc_html_e( 'Do you require special accommodations, such as a sign language interpreter or wheelchair access, to participate in WordCamp?', 'wordcamporg' ); ?>
     186                <?php echo esc_html( $this->question ); ?>
    171187                <span class="tix-required-star">*</span>
    172188            </td>
     
    180196
    181197        <?php
     198    }
     199
     200    /**
     201     * Add a row to the Attendee Info metabox table for the new field and value.
     202     *
     203     * @param array   $rows
     204     * @param WP_Post $post
     205     *
     206     * @return mixed
     207     */
     208    public function add_metabox_row( $rows, $post ) {
     209        $value = get_post_meta( $post->ID, 'tix_' . self::SLUG, true ) ?: '';
     210        if ( $value && isset( $this->options[ $value ] ) ) {
     211            $value = $this->options[ $value ];
     212        }
     213        $new_row = array( $this->question, esc_html( $value ) );
     214
     215        add_filter( 'locale', array( $this, 'set_locale_to_en_US' ) );
     216
     217        $ticket_row = array_filter( $rows, function( $row ) {
     218            if ( 'Ticket' === $row[0] ) {
     219                return true;
     220            }
     221
     222            return false;
     223        } );
     224
     225        remove_filter( 'locale', array( $this, 'set_locale_to_en_US' ) );
     226
     227        if ( ! empty( $ticket_row ) ) {
     228            $ticket_row_key = key( $ticket_row );
     229            $row_indexes    = array_keys( $rows );
     230            $position       = array_search( $ticket_row_key, $row_indexes );
     231
     232            $slice = array_slice( $rows, $position );
     233
     234            array_unshift( $slice, $new_row );
     235            array_splice( $rows, $position, count( $rows ), $slice );
     236        } else {
     237            $rows[] = $new_row;
     238        }
     239
     240        return $rows;
    182241    }
    183242
Note: See TracChangeset for help on using the changeset viewer.