Making WordPress.org

Changeset 1513


Ignore:
Timestamp:
04/24/2015 01:35:08 AM (10 years ago)
Author:
iandunn
Message:

Official WordPress Events: Use canonical format for post meta.

The JSON API doesn't currently expose post meta for unauthenticated requests, so WordCamp.org extends the API reponse to add it. Previously the data was added in an irregular format, but it is now consistent with the format the API uses when serving authenticated requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php

    r1512 r1513  
    123123        $response  = $this->remote_get( esc_url_raw( add_query_arg( $request_params, self::WORDCAMP_API_BASE_URL . 'posts' ) ) );
    124124        $wordcamps = json_decode( wp_remote_retrieve_body( $response ) );
    125        
     125
    126126        if ( $wordcamps ) {
    127127            foreach ( $wordcamps as $wordcamp ) {
    128                 if ( isset( $wordcamp->post_meta->{'Start Date (YYYY-mm-dd)'}[0] ) && $wordcamp->post_meta->{'Start Date (YYYY-mm-dd)'}[0] < time() ) {
     128                if ( empty( $wordcamp->post_meta ) ) {
    129129                    continue;
    130                    
    131                     // todo if https://github.com/WP-API/WP-API/pull/118 is merged, then finish register_json_query_vars() in WordCamp_Loader and filter this via the url
    132                     // restrict it to just the upcoming month?
    133                 }
    134                    
    135                 $events[] = new Official_WordPress_Event( array(
    136                     'type'            => 'wordcamp',
    137                     'title'           => $wordcamp->title,
    138                     'url'             => $wordcamp->post_meta->URL[0],
    139                     'start_timestamp' => $wordcamp->post_meta->{'Start Date (YYYY-mm-dd)'}[0],
    140                     'end_timestamp'   => $wordcamp->post_meta->{'End Date (YYYY-mm-dd)'}[0],
    141                     'location'        => $wordcamp->post_meta->Location[0],
    142                 ) );
     130                }
     131
     132                $event = array(
     133                    'type'  => 'wordcamp',
     134                    'title' => $wordcamp->title,
     135                );
     136
     137                foreach ( $wordcamp->post_meta as $meta_item ) {
     138                    switch ( $meta_item->key ) {
     139                        case 'Start Date (YYYY-mm-dd)':
     140                            if ( empty( $meta_item->value ) || $meta_item->value < time() ) {
     141                                // todo this can be removed when we're able to filter the request by post meta (see above)
     142
     143                                continue 3;
     144                            } else {
     145                                $event['start_timestamp'] = $meta_item->value;
     146                            }
     147                            break;
     148
     149                        case 'End Date (YYYY-mm-dd)':
     150                            $event['end_timestamp'] = $meta_item->value;
     151                            break;
     152
     153                        case 'URL':
     154                        case 'Location':
     155                            $event[ strtolower( $meta_item->key ) ] = $meta_item->value;
     156                            break;
     157                    }
     158                }
     159
     160                if ( ! empty( $event['url'] ) ) {
     161                    $events[] = new Official_WordPress_Event( $event );
     162                }
    143163            }
    144164        }
Note: See TracChangeset for help on using the changeset viewer.