Making WordPress.org

Ticket #558: patch_558_meta.diff

File patch_558_meta.diff, 6.5 KB (added by bansod_deven, 10 years ago)

Patch for #558 Meta

  • addons/field-country.php

     
     1<?php
     2/**
     3 * Country Field Addon for CampTix
     4 *
     5 * @see field-twitter.php
     6 */
     7class CampTix_Addon_Country_Field extends CampTix_Addon {
     8
     9        /**
     10         * Runs during camptix_init, @see CampTix_Addon
     11         */
     12        function camptix_init() {
     13                global $camptix;
     14                add_filter( 'camptix_question_field_types', array( $this, 'question_field_types' ) );
     15                add_action( 'camptix_attendees_shortcode_init', array( $this, 'attendees_shortcode_init' ) );
     16                add_action( 'camptix_question_field_country', array( $camptix, 'question_field_country' ), 10, 3 );
     17                add_action( 'camptix_attendees_shortcode_item', array( $this, 'attendees_shortcode_item' ), 10, 1 );
     18        }
     19
     20        function question_field_types( $types ) {
     21                return array_merge( $types, array(
     22                        'country' => 'Country',
     23                ) );
     24        }
     25
     26
     27        function attendees_shortcode_init() {
     28                global $camptix;
     29                $this->questions = $camptix->get_all_questions();
     30        }
     31
     32        function attendees_shortcode_item( $attendee_id ) {
     33                foreach ( $this->questions as $question ) {
     34                        if ( get_post_meta( $question->ID, 'tix_type', true ) != 'country' )
     35                                continue;
     36
     37                        $answers = (array) get_post_meta( $attendee_id, 'tix_questions', true );
     38                        if ( ! isset( $answers[ $question->ID ] ) )
     39                                continue;
     40
     41                        $country = esc_html( trim( $answers[ $question->ID ] ) );
     42                        // echo $country;
     43                        if ( $country ) {
     44                               
     45                                printf( '<span class="tix-field tix-attendee-country">%s</span>', $country );
     46                        }
     47                }
     48        }
     49}
     50
     51// Register this class as a CampTix Addon.
     52camptix_register_addon( 'CampTix_Addon_Country_Field' );
  • admin.js

     
    186186                                var value = this.$type.val();
    187187                                var $row = this.$( '.tix-add-question-values-row' );
    188188
    189                                 if ( value && value.match( /radio|checkbox|select/ ) )
     189                                if ( value && value.match( /radio|checkbox|select|country/ ) ) {
     190                                       
    190191                                        $row.show();
     192                                       
     193                                        if ( value === 'country' ) {
     194                                                var $all_countries = "Afghanistan ,Albania ,Algeria ,American Samoa ,Andorra ,Angola ,Anguilla ,Antigua & Barbuda ,Argentina ,Armenia ,Aruba ,Australia ,Austria ,Azerbaijan ,Bahamas,The ,Bahrain ,Bangladesh ,Barbados ,Belarus ,Belgium ,Belize ,Benin ,Bermuda ,Bhutan ,Bolivia ,Bosnia & Herzegovina ,Botswana ,Brazil ,British Virgin Is. ,Brunei ,Bulgaria ,Burkina Faso ,Burma ,Burundi ,Cambodia ,Cameroon ,Canada ,Cape Verde ,Cayman Islands ,Central African Rep. ,Chad ,Chile ,China ,Colombia ,Comoros ,Congo,Dem. Rep. ,Congo,Repub. of the ,Cook Islands ,Costa Rica ,Cote d'Ivoire ,Croatia ,Cuba ,Cyprus ,Czech Republic ,Denmark ,Djibouti ,Dominica ,Dominican Republic ,East Timor ,Ecuador ,Egypt ,El Salvador ,Equatorial Guinea ,Eritrea ,Estonia ,Ethiopia ,Faroe Islands ,Fiji ,Finland ,France ,French Guiana ,French Polynesia ,Gabon ,Gambia,The ,Gaza Strip ,Georgia ,Germany ,Ghana ,Gibraltar ,Greece ,Greenland ,Grenada ,Guadeloupe ,Guam ,Guatemala ,Guernsey ,Guinea ,Guinea-Bissau ,Guyana ,Haiti ,Honduras ,Hong Kong ,Hungary ,Iceland ,India ,Indonesia ,Iran ,Iraq ,Ireland ,Isle of Man ,Israel ,Italy ,Jamaica ,Japan ,Jersey ,Jordan ,Kazakhstan ,Kenya ,Kiribati ,Korea,North ,Korea,South ,Kuwait ,Kyrgyzstan ,Laos ,Latvia ,Lebanon ,Lesotho ,Liberia ,Libya ,Liechtenstein ,Lithuania ,Luxembourg ,Macau ,Macedonia ,Madagascar ,Malawi ,Malaysia ,Maldives ,Mali ,Malta ,Marshall Islands ,Martinique ,Mauritania ,Mauritius ,Mayotte ,Mexico ,Micronesia,Fed. St. ,Moldova ,Monaco ,Mongolia ,Montserrat ,Morocco ,Mozambique ,Namibia ,Nauru ,Nepal ,Netherlands ,Netherlands Antilles ,New Caledonia ,New Zealand ,Nicaragua ,Niger ,Nigeria ,N. Mariana Islands ,Norway ,Oman ,Pakistan ,Palau ,Panama ,Papua New Guinea ,Paraguay ,Peru ,Philippines ,Poland ,Portugal ,Puerto Rico ,Qatar ,Reunion ,Romania ,Russia ,Rwanda ,Saint Helena ,Saint Kitts & Nevis ,Saint Lucia ,St Pierre & Miquelon ,Saint Vincent and the Grenadines ,Samoa ,San Marino ,Sao Tome & Principe ,Saudi Arabia ,Senegal ,Serbia ,Seychelles ,Sierra Leone ,Singapore ,Slovakia ,Slovenia ,Solomon Islands ,Somalia ,South Africa ,Spain ,Sri Lanka ,Sudan ,Suriname ,Swaziland ,Sweden ,Switzerland ,Syria ,Taiwan ,Tajikistan ,Tanzania ,Thailand ,Togo ,Tonga ,Trinidad & Tobago ,Tunisia ,Turkey ,Turkmenistan ,Turks & Caicos Is ,Tuvalu ,Uganda ,Ukraine ,United Arab Emirates ,United Kingdom ,United States ,Uruguay ,Uzbekistan ,Vanuatu ,Venezuela ,Vietnam ,Virgin Islands ,Wallis and Futuna ,West Bank ,Western Sahara ,Yemen ,Zambia ,Zimbabwe";
     195                                               
     196                                                this.$( '#tix-add-question-values' ).val( $all_countries );
     197                                               
     198                                                this.$( '#tix-add-question-values' ).prop("readOnly","true");
     199
     200                                        }
     201                                }               
    191202                                else
    192203                                        $row.hide();
    193204
  • camptix.php

     
    35683568                        'select' => __( 'Dropdown select', 'camptix' ),
    35693569                        'radio' => __( 'Radio select', 'camptix' ),
    35703570                        'checkbox' => __( 'Checkbox', 'camptix' ),
     3571                        'country' => __( 'Country' , 'camptix' ),
    35713572                ) );
    35723573        }
    35733574
     
    36063607        }
    36073608
    36083609        /**
     3610         * A drop-down Country Select for a question.
     3611         */
     3612        function question_field_country( $name, $user_value, $question ) {
     3613                $values = get_post_meta( $question->ID, 'tix_values', true );
     3614                ?>
     3615                <select name="<?php echo esc_attr( $name ); ?>" />
     3616                        <?php foreach ( (array) $values as $question_value ) : ?>
     3617                                <option <?php selected( $question_value, $user_value ); ?> value="<?php echo esc_attr( $question_value ); ?>"><?php echo esc_html( $question_value ); ?></option>
     3618                        <?php endforeach; ?>
     3619                </select>
     3620                <?php
     3621        }
     3622
     3623        /**
    36093624         * A single or multiple checkbox for a question.
    36103625         */
    36113626        function question_field_checkbox( $name, $user_value, $question ) {
     
    36213636                <?php
    36223637        }
    36233638
     3639
    36243640        /**
    36253641         * A textarea input for questions.
    36263642         */
     
    69146930                $default_addons = apply_filters( 'camptix_default_addons', array(
    69156931                        'field-twitter'  => $this->get_default_addon_path( 'field-twitter.php' ),
    69166932                        'field-url'      => $this->get_default_addon_path( 'field-url.php' ),
     6933                        'field-country'  => $this->get_default_addon_path( 'field-country.php' ),
    69176934                        'shortcodes'     => $this->get_default_addon_path( 'shortcodes.php' ),
    69186935                        'payment-paypal' => $this->get_default_addon_path( 'payment-paypal.php' ),
    69196936                        'logging-meta'   => $this->get_default_addon_path( 'logging-meta.php' ),