Making WordPress.org


Ignore:
Timestamp:
08/03/2016 08:07:42 PM (8 years ago)
Author:
iandunn
Message:

Remove REST API caching v1 in favor of v2.

This has been disabled for awhile, and will be replaced by the dedicated WP Super Cache plugin.

See https://github.com/Automattic/wp-super-cache/pull/121

File:
1 edited

Legend:

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

    r3104 r3770  
    1818add_filter( 'json_prepare_post',           'wcorg_json_embed_related_posts',             999, 3 );   // after `wcorg_json_expose_additional_post_data()`
    1919add_action( 'wp_json_server_before_serve', 'wcorg_json_avoid_nested_callback_conflicts', 11     );    // after the default endpoints are added in `json_api_default_filters()`
    20 add_filter( 'wp_cache_eof_tags',           'wcorg_json_cache_requests'                          );
    2120
    2221// Allow some routes to skip the JSON REST API v1 plugin.
     
    315314
    316315/**
    317  * Tell WP Super Cache to cache API endpoints
    318  *
    319  * @param string $eof_pattern
    320  *
    321  * @return string
    322  */
    323 function wcorg_json_cache_requests( $eof_pattern ) {
    324     global $wp_super_cache_comments;
    325 
    326     $api_request = ( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) || ( defined( 'REST_REQUEST' ) && REST_REQUEST );
    327 
    328     if ( $api_request ) {
    329         // Accept a JSON-formatted string as an end-of-file marker, so that the page will be cached
    330         $json_object_pattern     = '^[{].*[}]$';
    331         $json_collection_pattern = '^[\[].*[\]]$';
    332 
    333         /* disabling until can set correct header
    334         $eof_pattern = str_replace(
    335             '<\?xml',
    336             sprintf( '<\?xml|%s|%s', $json_object_pattern, $json_collection_pattern ),
    337             $eof_pattern
    338         );
    339         */
    340 
    341         // Don't append HTML comments to the JSON output, because that would invalidate it
    342         $wp_super_cache_comments = false;
    343     }
    344 
    345     return $eof_pattern;
    346 }
    347 
    348 /**
    349316 * JSON REST API v1 and Core/v2 compatibility.
    350317 *
Note: See TracChangeset for help on using the changeset viewer.