This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Rest endpoint filter to change permission callback of item_permission_check. | |
* | |
* @param type $endpoints return endpoints. | |
*/ | |
public function replace_rest_endpoints_permission_callback( $endpoints ) { | |
if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cached version of count_user_posts, which is uncached but doesn't always need to hit the db | |
* | |
* Count_user_posts is generally fast, but it can be easy to end up with many redundant queries. | |
* if it's called several times per request. This allows bypassing the db queries in favor of | |
* the cache | |
* | |
* @param int $user_id user id to get count. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cached_get_item_permissions_check( $request ) { | |
$error = new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) ); | |
if ( (int) $request['id'] <= 0 ) { | |
return $error; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php#L64 | |
register_rest_route( | |
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', | |
array( | |
'methods' => WP_REST_Server::READABLE, | |
'callback' => array( $this, 'get_item' ), | |
'permission_callback' => array( $this, 'get_item_permissions_check' ), | |
'args' => array( | |
'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
NewerOlder