- Timestamp:
- 01/12/2021 09:30:56 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/patterns/1.0/index.php
r10545 r10572 8 8 * 9 9 * todo 10 * publish caching sysreq once query args settled, etc -- https://make.wordpress.org/systems/wp-admin/post.php?post=1788&action=edit 11 * 12 */ 13 14 15 /* 16 * @todo 17 * 10 * - publish caching sysreq once query args settled, etc -- https://make.wordpress.org/systems/wp-admin/post.php?post=1788&action=edit 11 * - add docs to codex 18 12 */ 19 13 … … 24 18 * Proxy w.org/patterns API endpoints for reliability. 25 19 * 26 * Core needsto send requests to api.w.org, because it has more resources and better caching than w.org.20 * Core clients need to send requests to api.w.org, because it has more resources and better caching than w.org. 27 21 * 28 22 * @param string $query_string … … 31 25 $api_url_base = 'https://wordpress.org/patterns/wp-json'; 32 26 $wp_init_query = true; 27 $endpoint = '/wp/v2/wporg-pattern'; 33 28 29 /* 30 * Core clients should pass params for the desired action: 31 * 32 * @example Browse all: `/patterns/1.0/` 33 * @example Browse a category: `/patterns/1.0/?pattern-categories={id}` 34 * @example Search: `/patterns/1.0/?search={query}` 35 */ 34 36 parse_str( $query_string, $query_args ); 35 37 36 switch ( $query_args['action'] ) { 37 // List all patterns, or all with in category. 38 // To restrict to a category, the client needs to provide `pattern-categories={id}` param. 39 default: 40 case 'get_patterns': 41 $endpoint = '/wp/v2/wporg-pattern'; 38 /* 39 * Filter the returned fields down to only the ones Core uses. 40 * 41 * `_links` is necessary for `wp:term` to be embedded, see https://core.trac.wordpress.org/ticket/49985. 42 * Related https://core.trac.wordpress.org/ticket/49538. 43 */ 44 $query_args['_fields'] = 'id,title,content,meta,_links'; 45 $query_args['_embed'] = 'wp:term'; 42 46 43 // `_links` is a workaround for https://core.trac.wordpress.org/ticket/49985. Related https://core.trac.wordpress.org/ticket/49538. 44 $query_args['_fields'] = 'id,title,content,meta,_links'; 45 $query_args['_embed'] = 'wp:term'; 46 47 break; 48 49 // Search patterns. 50 // Client needs to provide `search={string}` param. 51 case 'query_patterns': 52 $endpoint = '/wp/v2/search'; 53 $query_args['subtype'] = 'wporg-pattern'; 54 55 // `_links` is a workaround for https://core.trac.wordpress.org/ticket/49985. Related https://core.trac.wordpress.org/ticket/49538. 56 $query_args['_fields'] = '_links'; 57 $query_args['_embed'] = 'self'; 58 59 break; 60 } 61 62 unset( $query_args['action'] ); 63 64 $wp_init_host = $api_url_base . $endpoint; 65 66 if ( $query_args ) { 67 $wp_init_host .= '?' . urldecode( http_build_query( $query_args ) ); 68 } 47 $wp_init_host = $api_url_base . $endpoint . '?' . urldecode( http_build_query( $query_args ) ); 69 48 70 49 // Load WordPress to process the request and output the response.
Note: See TracChangeset
for help on using the changeset viewer.