Changeset 1544
- Timestamp:
- 05/05/2015 11:22:45 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-json-api.php
r1534 r1544 23 23 */ 24 24 function wcorg_json_whitelist_endpoints( $endpoints ) { 25 global $wp_json_server, $wp_json_posts; 26 25 27 $whitelisted_endpoints = array( 26 '/posts' => array( 'get_posts' ), 27 '/posts/(?P<id>\d+)' => array( 'get_post' ), 28 '/' => array( array( $wp_json_server, 'get_index' ), WP_JSON_Server::READABLE ), 29 30 // Posts 31 '/posts' => array( 32 array( array( $wp_json_posts, 'get_posts' ), WP_JSON_Server::READABLE ), 33 ), 34 '/posts/(?P<id>\d+)' => array( 35 array( array( $wp_json_posts, 'get_post' ), WP_JSON_Server::READABLE ), 36 ), 37 28 38 // todo Add /posts/types too, because it's useful for debugging and there's no harm. It has a different array structure than the current ones, though, so this will need some work. 29 39 ); 30 40 31 foreach ( $endpoints as $endpoint => $endpoint_data ) { 32 /* 33 * Don't attempt to scan '/' because it has a different array structure than normal endpoints and is 34 * unlikely to expose anything sensitive. 35 */ 36 if ( '/' == $endpoint ) { 37 continue; 38 } 39 40 if ( array_key_exists( $endpoint, $whitelisted_endpoints ) ) { 41 // Allow the endpoint, but remove any of its callbacks that aren't whitelisted and read-only 42 43 foreach ( $endpoint_data as $callback_index => $callback ) { 44 $callback_name = $callback[0][1]; 45 $callback_permissions = $callback[1]; 46 47 if ( ! in_array( $callback_name, $whitelisted_endpoints[ $endpoint ] ) || WP_JSON_Server::READABLE != $callback_permissions ) { 48 unset( $endpoints[ $endpoint ][ $callback_index ] ); 49 } 50 } 51 } else { 52 // Remove endpoints that aren't whitelisted 53 54 unset( $endpoints[ $endpoint ] ); 55 } 56 } 57 58 return $endpoints; 41 return $whitelisted_endpoints; 59 42 } 60 43 add_filter( 'json_endpoints', 'wcorg_json_whitelist_endpoints', 999 );
Note: See TracChangeset
for help on using the changeset viewer.