Making WordPress.org

Changeset 2241


Ignore:
Timestamp:
12/30/2015 10:55:01 PM (11 years ago)
Author:
iandunn
Message:

WordCamp JSON API: Cache requests with WP Super Cache.

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

Legend:

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

    r2165 r2241  
    304304}
    305305add_action( 'wp_json_server_before_serve', 'wcorg_json_avoid_nested_callback_conflicts', 11 );    // after the default endpoints are added in `json_api_default_filters()`
     306
     307/**
     308 * Tell WP Super Cache to cache API endpoints
     309 *
     310 * @param string $eof_pattern
     311 *
     312 * @return string
     313 */
     314function wcorg_json_cache_requests( $eof_pattern ) {
     315        global $wp_super_cache_comments;
     316
     317        if ( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) {
     318                // Accept a JSON-formatted string as an end-of-file marker, so that the page will be cached
     319                $json_object_pattern     = '^[{].*[}]$';
     320                $json_collection_pattern = '^[\[].*[\]]$';
     321
     322                $eof_pattern = str_replace(
     323                        '<\?xml',
     324                        sprintf( '<\?xml|%s|%s', $json_object_pattern, $json_collection_pattern ),
     325                        $eof_pattern
     326                );
     327
     328                // Don't append HTML comments to the JSON output, because that would invalidate it
     329                $wp_super_cache_comments = false;
     330        }
     331
     332        return $eof_pattern;
     333}
     334add_filter( 'wp_cache_eof_tags', 'wcorg_json_cache_requests' );
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wp-cli-commands/rest-api.php

    r2178 r2241  
    1515                $errors          = false;
    1616                $start_timestamp = microtime( true );
     17
     18                WP_CLI::line();
     19                WP_CLI::warning( "Make sure you clear WP Super Cache on the test sites before running this, to avoid testing old data." );
    1720
    1821                // These calls are not formatted in a more compact way because we don't want to short-circuit any of them if one fails
Note: See TracChangeset for help on using the changeset viewer.