Making WordPress.org


Ignore:
Timestamp:
06/03/2019 02:50:54 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: Search: Use wp_json_encode() to handle non-UTF8 queries better. Don't attempt a search if we can't encode the JSON.

This should reduce the amount of 400 Bad Request's we trigger against the Jetpack Search API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

    r8901 r8904  
    223223        public function search( $es_args ) {
    224224                $service_url  = 'https://public-api.wordpress.com/rest/v1/sites/' . $this->jetpack_blog_id . '/search';
    225                 $json_es_args = json_encode( $es_args );
     225                $json_es_args = wp_json_encode( $es_args );
    226226                $cache_key    = md5( $json_es_args );
    227227                $lock_key     = 'lock-' . $cache_key;
    228228                $count_key    = 'count-' . $cache_key;
    229229
     230                // If the Query args were not able to be encoded, bail.
     231                if ( ! $json_es_args ) {
     232                        return false;
     233                }
     234
    230235                $response = wp_cache_get( $cache_key, self::CACHE_GROUP );
    231 
    232236
    233237                // Use a temporary lock to prevent cache stampedes.
Note: See TracChangeset for help on using the changeset viewer.