'GET', 'callback' => array( __CLASS__, 'get_report' ), 'permission_callback' => array( __CLASS__, 'can_read' ), ) ); register_rest_route( 'sunsetly/v1', '/scan', array( 'methods' => 'POST', 'callback' => array( __CLASS__, 'scan' ), 'permission_callback' => array( __CLASS__, 'can_read' ), ) ); } /** * Permission check (administrators only; filterable). * * @param WP_REST_Request $request Request. * @return bool */ public static function can_read( $request ) { return (bool) apply_filters( 'sunsetly_rest_permission', current_user_can( 'manage_options' ), $request ); } /** * GET report. * * @return WP_REST_Response */ public static function get_report() { $r = Sunsetly_Scanner::report(); return rest_ensure_response( $r ? $r : array( 'status' => 'pending' ) ); } /** * POST scan. * * @return WP_REST_Response|WP_Error */ public static function scan() { $r = Sunsetly_Scanner::run( array( 'trigger' => 'rest' ) ); return is_wp_error( $r ) ? $r : rest_ensure_response( $r ); } }