WordPress.org

Making WordPress.org

Changeset 2743


Ignore:
Timestamp:
03/11/2016 11:53:09 PM (5 years ago)
Author:
iandunn
Message:

WordCamp.org: Centralize user fetching functionality.

Previously wordcamp-participation-notifier and wc-post-types were using slightly different code to get the same data, which resulted in a bug where wc-post-types would find the user, but wordcamp-participation-notifier wouldn't. That led to some profile badges being removed when the speaker/organizer post was updated, because the notifier would think the username was removed from the field, and send a command to remove the badge.

Because the two plugins are interdependent, they need to use a common function to guarantee identical results.

get_saved_wporg_user_id() doesn't need to use the new function, because tix_username is always set from user_login, rather than being entered as user-input.

See #977

Location:
sites/trunk/wordcamp.org/public_html/wp-content
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/helper-functions.php

    r2418 r2743  
    127127    return isset( $flags[ $flag ] );
    128128}
     129
     130/**
     131 * Get a user by the username or nicename
     132 *
     133 * Note: This intentionally doesn't lookup users by the display name or nickname, because those can be set by the
     134 * user, which could result in false-positive matches.
     135 *
     136 * @param string $name
     137 *
     138 * @return false|WP_User
     139 */
     140function wcorg_get_user_by_canonical_names( $name ) {
     141    if ( ! $user = get_user_by( 'login', $name ) ) {    // user_login
     142        $user = get_user_by( 'slug', $name );           // user_nicename
     143    }
     144
     145    return $user;
     146}
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    r2602 r2743  
    15231523
    15241524        $available_countries = array( 'Abkhazia', 'Afghanistan', 'Aland', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Ascension', 'Ashmore and Cartier Islands', 'Australia', 'Australian Antarctic Territory', 'Austria', 'Azerbaijan', 'Bahamas, The', 'Bahrain', 'Baker Island', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Antarctic Territory', 'British Indian Ocean Territory', 'British Sovereign Base Areas', 'British Virgin Islands', 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', "China, People's Republic of", 'China, Republic of (Taiwan)', 'Christmas Island', 'Clipperton Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo, (Congo – Brazzaville)', 'Congo, (Congo – Kinshasa)', 'Cook Islands', 'Coral Sea Islands', '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', 'Falkland Islands (Islas Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern and Antarctic Lands', 'Gabon', 'Gambia, The', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard Island and McDonald Islands', 'Honduras', 'Hong Kong', 'Howland Island', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Isle of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jarvis Island', 'Jersey', 'Johnston Atoll', 'Jordan', 'Kazakhstan', 'Kenya', 'Kingman Reef', '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', 'Midway Islands', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar (Burma)', 'Nagorno-Karabakh', 'Namibia', 'Nauru', 'Navassa Island', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Cyprus', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palmyra Atoll', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Peter I Island', 'Philippines', 'Pitcairn Islands', 'Poland', 'Portugal', 'Pridnestrovie (Transnistria)', 'Puerto Rico', 'Qatar', 'Queen Maud Land', 'Reunion', 'Romania', 'Ross Dependency', 'Russia', 'Rwanda', 'Saint Barthelemy', 'Saint Helena', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Martin', 'Saint Pierre and Miquelon', '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', 'Somaliland', 'South Africa', 'South Georgia & South Sandwich Islands', 'South Ossetia', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Svalbard', 'Swaziland', 'Sweden', 'Switzerland', 'Syria', 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste (East Timor)', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tristan da Cunha', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'U.S. Virgin Islands', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Vietnam', 'Wake Island', 'Wallis and Futuna', 'Yemen', 'Zambia', 'Zimbabwe' );
     1525        // todo use WordCamp_Budgets::get_valid_countries_iso3166() instead. need to switch multi-event sponsors at same time.
    15251526
    15261527        wp_nonce_field( 'edit-sponsor-info', 'wcpt-meta-sponsor-info' );
     
    15781579            $email          = sanitize_text_field( $_POST['wcpt-gravatar-email'] );
    15791580            $wporg_username = sanitize_text_field( $_POST['wcpt-wporg-username'] );
    1580             $wporg_user     = $this->get_wporg_user( $wporg_username );
     1581            $wporg_user     = wcorg_get_user_by_canonical_names( $wporg_username );
    15811582
    15821583            if ( empty( $email ) )
     
    15931594
    15941595    /**
    1595      * Get WordPress.org User
    1596      *
    1597      * Give it login or slug, will return a WP_User object if found.
    1598      */
    1599     function get_wporg_user( $login_or_slug ) {
    1600         $wporg_user = get_user_by( 'slug', $login_or_slug );
    1601 
    1602         // Try again by login.
    1603         if ( ! $wporg_user )
    1604             $wporg_user = get_user_by( 'login', $login_or_slug );
    1605 
    1606         return $wporg_user;
    1607     }
    1608 
    1609     /**
    16101596     * When an Organizer post is saved, update some meta data.
    16111597     */
     
    16161602        if ( isset( $_POST['wcpt-meta-organizer-info'] ) && wp_verify_nonce( $_POST['wcpt-meta-organizer-info'], 'edit-organizer-info' ) ) {
    16171603            $wporg_username = sanitize_text_field( $_POST['wcpt-wporg-username'] );
    1618             $wporg_user = $this->get_wporg_user( $wporg_username );
     1604            $wporg_user = wcorg_get_user_by_canonical_names( $wporg_username );
    16191605
    16201606            if ( ! $wporg_user )
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-participation-notifier/wordcamp-participation-notifier.php

    r2742 r2743  
    311311
    312312        if ( in_array( $post->post_type, array( 'wcb_speaker', 'wcb_organizer' ) ) && isset( $_POST['wcpt-wporg-username'] ) ) {
    313             $user = get_user_by( 'login', $_POST['wcpt-wporg-username'] );
     313            $user = wcorg_get_user_by_canonical_names( $_POST['wcpt-wporg-username'] );
    314314        }
    315315
Note: See TracChangeset for help on using the changeset viewer.