WordPress.org

Making WordPress.org

Changeset 3749


Ignore:
Timestamp:
07/29/2016 07:34:47 PM (3 years ago)
Author:
iandunn
Message:

WordCamp Helpers: Add wcorg_get_url_part() for easy URL parsing.

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

Legend:

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

    r3284 r3749  
    7676 * Based on https://stackoverflow.com/a/22508709/450127
    7777 *
     78 * @todo It might be just as good to use getmypid(), but need to research/test first
     79 *
    7880 * @return string
    7981 */
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/helper-functions.php

    r2888 r3749  
    147147
    148148/**
     149 * Extract pieces from a WordCamp.org URL
     150 *
     151 * @todo find other code that's doing this same task in an ad-hoc manner, and convert it to use this instead
     152 *
     153 * @param string $url
     154 * @param string $part 'city', 'city-domain' (without the year, e.g. seattle.wordcamp.org), 'year'
     155 *
     156 * @return false|string|int False on errors; an integer for years; a string for city and city-domain
     157 */
     158function wcorg_get_url_part( $url, $part ) {
     159    $url_parts = explode( '.', parse_url( $url, PHP_URL_HOST ) );
     160    $result    = false;
     161
     162    // Make sure it matches the typical year.city.wordcamp.org structure
     163    if ( 4 !== count( $url_parts ) ) {
     164        return $result;
     165    }
     166
     167    switch( $part ) {
     168        case 'city':
     169            $result = $url_parts[1];
     170            break;
     171
     172        case 'city-domain':
     173            $result = ltrim( strstr( $url, '.' ), '.' );
     174            break;
     175
     176        case 'year':
     177            $result = absint( $url_parts[0] );
     178            break;
     179    }
     180
     181    return $result;
     182}
     183
     184/**
    149185 * Get ISO-3166 country names and codes
    150186 *
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wp-cli-commands/miscellaneous.php

    r3273 r3749  
    111111     *
    112112     * wp wc-misc format-log /var/log/php-errors.log
    113      * wp wc-misc format-log "$(grep 'foo' /var/log/php-errors.log -A 10 -B 10)" |less -S
     113     * wp wc-misc format-log "$(grep 'foo' /var/log/php-errors.log --C 10)" |less -S
    114114     * wp wc-misc format-log "$(grep 'bar' /var/log/php-errors.log)" --foreign=ignore
    115115     *
Note: See TracChangeset for help on using the changeset viewer.