Making WordPress.org


Ignore:
Timestamp:
05/09/2016 12:55:30 PM (9 years ago)
Author:
kovshenin
Message:

WordCamp.org: Fix the WordCamp JSON endpoint.

When querying WordCamps through the JSON endpoint, make
sure we explicitly request our new public statuses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-json-api.php

    r3098 r3101  
    2525// Allow users to read new post statuses.
    2626add_filter( 'json_check_post_read_permission', 'wcorg_json_check_post_read_permission', 10, 2 );
     27
     28// Query the public post statuses when querying WordCamps via the JSON API.
     29add_action( 'pre_get_posts', 'wcorg_json_pre_get_posts' );
    2730
    2831/**
     
    328331        $json_collection_pattern = '^[\[].*[\]]$';
    329332
     333        /* disabling until can set correct header
    330334        $eof_pattern = str_replace(
    331335            '<\?xml',
     
    333337            $eof_pattern
    334338        );
     339        */
    335340
    336341        // Don't append HTML comments to the JSON output, because that would invalidate it
     
    388393    return in_array( $post['post_status'], WordCamp_Loader::get_public_post_statuses() );
    389394}
     395
     396/**
     397 * Query the public post statuses when querying WordCamps via the JSON API.
     398 */
     399function wcorg_json_pre_get_posts( $query ) {
     400    if ( ! defined( 'JSON_REQUEST' ) || ! JSON_REQUEST )
     401        return;
     402
     403    $post_types = $query->get( 'post_type' );
     404    $post_statuses = $query->get( 'post_status' );
     405
     406    if ( $post_types == 'wordcamp' || in_array( 'wordcamp', (array) $post_types ) ) {
     407        if ( empty( $post_statuses ) ) {
     408            $query->set( 'post_status', WordCamp_Loader::get_public_post_statuses() );
     409        }
     410    }
     411}
Note: See TracChangeset for help on using the changeset viewer.