AnsPress_API()
Description #
AnsPress REST endpoint class.
Source #
File: includes/api.php
class AnsPress_API { /** * Register REST route. */ public static function register() { register_rest_route( 'anspress', '/user/avatar', array( 'methods' => 'GET', 'callback' => array( 'AnsPress_API', 'avatar' ), ) ); } /** * Callback for route `/anspress/user/avatar/`. * * @param WP_REST_Request $request Request data. * @return WP_REST_Response|WP_Error */ public static function avatar( $request ) { $args = $request->get_query_params(); if ( isset( $args['id'] ) ) { $size = isset( $args['size'] ) ? (int) $args['size'] : 90; $avatar = get_avatar_url( (int) $args['id'], $size ); return new WP_REST_Response( $avatar, 200 ); } return new WP_Error( 'wrongData', __( 'Wrong data supplied', 'anspress-question-answer' ) ); } }
Expand full source code Collapse full source code View on GitHub: includes/api.php:20
Add your comment