Making WordPress.org

Ticket #558: patch_558_meta_2.diff

File patch_558_meta_2.diff, 6.1 KB (added by bansod_deven, 10 years ago)

Patch_2 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( $this, '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         * A drop-down Country Select for a question.
     28         */
     29        function question_field_country( $name, $user_value, $question ) {
     30               
     31                $list_of_all_countries = "Afghanistan, Albania, Algeria, Andorra, Angola, Antigua and Barbuda, Argentina, Armenia, Australia, Austria, Azerbaijan, Bahamas, Bahrain, Bangladesh, Barbados, Belarus, Belgium, Belize, Benin, Bhutan, Bolivia, Bosnia and Herzegovina, Botswana, Brazil, Brunei, Bulgaria, Burkina Faso, Burundi, Cambodia, Cameroon, Canada, Cape Verde, Central African Republic, Chad, Chile, China, Colombia, Comoros, Congo (Congo Kinshasa), Congo (Congo Brazzaville), Costa Rica, Cote d'Ivoire (Ivory Coast), Croatia, Cuba, Cyprus, Czech Republic, Denmark, Djibouti, Dominica, Dominican Republic, Ecuador, Egypt, El Salvador, Equatorial Guinea, Eritrea, Estonia, Ethiopia, Fiji, Finland, France, Gabon, Gambia, Georgia, Germany, Ghana, Greece, Grenada, Guatemala, Guinea, Guinea-Bissau, Guyana, Haiti, Honduras, Hungary, Iceland, India, Indonesia, Iran, Iraq, Ireland, Israel, Italy, Jamaica, Japan, Jordan, Kazakhstan, Kenya, Kiribati, North Korea, South Korea, Kuwait, Kyrgyzstan, Laos, Latvia, Lebanon, Lesotho, Liberia, Libya, Liechtenstein, Lithuania, Luxembourg, Macedonia, Madagascar, Malawi, Malaysia, Maldives, Mali, Malta, Marshall Islands, Mauritania, Mauritius, Mexico, Micronesia, Moldova, Monaco, Mongolia, Montenegro, Morocco, Mozambique, Myanmar (Burma), Namibia, Nauru, Nepal, Netherlands, New Zealand, Nicaragua, Niger, Nigeria, Norway, Oman, Pakistan, Palau, Panama, Papua New Guinea, Paraguay, Peru, Philippines, Poland, Portugal, Qatar, Romania, Russia, Rwanda, Saint Kitts and Nevis, Saint Lucia, Saint Vincent and the Grenadines, Samoa, San Marino, Sao Tome and 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, Tajikistan, Tanzania, Thailand, Timor-Leste (East Timor), Togo, Tonga, Trinidad and Tobago, Tunisia, Turkey, Turkmenistan, Tuvalu, Uganda, Ukraine, United Arab Emirates, United Kingdom, United States, Uruguay, Uzbekistan, Vanuatu, Vatican City, Venezuela, Vietnam, Yemen, Zambia, Zimbabwe, Abkhazia, Taiwan, Nagorno-Karabakh, Northern Cyprus, Pridnestrovie (Transnistria), Somaliland, South Ossetia, Ashmore and Cartier Islands, Christmas Island, Cocos (Keeling) Islands, Coral Sea Islands, Heard Island and McDonald Islands, Norfolk Island, New Caledonia, French Polynesia, Mayotte, Saint Barthelemy, Saint Martin, Saint Pierre and Miquelon, Wallis and Futuna, French Southern and Antarctic Lands, Clipperton Island, Bouvet Island, Cook Islands, Niue, Tokelau, Guernsey, Isle of Man, Jersey, Anguilla, Bermuda, British Indian Ocean Territory, British Sovereign Base Areas, British Virgin Islands, Cayman Islands, Falkland Islands (Islas Malvinas), Gibraltar, Montserrat, Pitcairn Islands, Saint Helena, South Georgia & South Sandwich Islands, Turks and Caicos Islands, Northern Mariana Islands, Puerto Rico, American Samoa, Baker Island, Guam, Howland Island, Jarvis Island, Johnston Atoll, Kingman Reef, Midway Islands, Navassa Island, Palmyra Atoll, U.S. Virgin Islands, Wake Island, Hong Kong, Macau, Faroe Islands, Greenland, French Guiana, Guadeloupe, Martinique, Reunion, Aland, Aruba, Netherlands Antilles, Svalbard, Ascension, Tristan da Cunha, Australian Antarctic Territory, Ross Dependency, Peter I Island, Queen Maud Land, British Antarctic Territory";
     32
     33                $countries = explode(", ", $list_of_all_countries);
     34
     35                ?>
     36                <select name="<?php echo esc_attr( $name ); ?>" />
     37                        <?php foreach ( (array) $countries as $country ) : ?>
     38                                <option  value="<?php echo esc_attr( $country ); ?>"><?php echo esc_html( $country ); ?></option>
     39                        <?php endforeach; ?>
     40                </select>
     41                <?php
     42        }
     43
     44
     45        function attendees_shortcode_init() {
     46                global $camptix;
     47                $this->questions = $camptix->get_all_questions();
     48        }
     49
     50        function attendees_shortcode_item( $attendee_id ) {
     51                foreach ( $this->questions as $question ) {
     52                        if ( get_post_meta( $question->ID, 'tix_type', true ) != 'country' )
     53                                continue;
     54
     55                        $answers = (array) get_post_meta( $attendee_id, 'tix_questions', true );
     56                        if ( ! isset( $answers[ $question->ID ] ) )
     57                                continue;
     58
     59                        $country = trim( $answers[ $question->ID ] ) ;
     60                       
     61                        if ( $country )                         
     62                                printf( '<span class="tix-field tix-attendee-country">%s</span>', $country );
     63                       
     64                }
     65        }
     66}
     67
     68// Register this class as a CampTix Addon.
     69camptix_register_addon( 'CampTix_Addon_Country_Field' );
  • camptix.php

     
    69146914                $default_addons = apply_filters( 'camptix_default_addons', array(
    69156915                        'field-twitter'  => $this->get_default_addon_path( 'field-twitter.php' ),
    69166916                        'field-url'      => $this->get_default_addon_path( 'field-url.php' ),
     6917                        'field-country'  => $this->get_default_addon_path( 'field-country.php' ),
    69176918                        'shortcodes'     => $this->get_default_addon_path( 'shortcodes.php' ),
    69186919                        'payment-paypal' => $this->get_default_addon_path( 'payment-paypal.php' ),
    69196920                        'logging-meta'   => $this->get_default_addon_path( 'logging-meta.php' ),