PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / _inc / lib / core-api / wpcom-endpoints / class-wpcom-rest-api-v2-endpoint-application-password-extras.php

class-wpcom-rest-api-v2-endpoint-application-password-extras.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at _inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-application-password-extras.php

92 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * REST API endpoint for application password extras abilities.
4 *
5 * @package automattic/jetpack
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit( 0 );
10 }
11
12 /**
13 * Class WPCOM_REST_API_V2_Endpoint_Application_Password_Extras
14 */
15 class WPCOM_REST_API_V2_Endpoint_Application_Password_Extras extends WP_REST_Controller {
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->namespace = 'wpcom/v2';
21 $this->rest_base = 'application-password-extras';
22 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
23 }
24
25 /**
26 * Register routes.
27 */
28 public function register_routes() {
29 register_rest_route(
30 $this->namespace,
31 $this->rest_base . '/abilities',
32 array(
33 array(
34 'methods' => WP_REST_Server::READABLE,
35 'callback' => array( $this, 'get_abilities' ),
36 'permission_callback' => array( $this, 'get_item_permissions_check' ),
37 ),
38 )
39 );
40
41 register_rest_route(
42 $this->namespace,
43 $this->rest_base . '/admin-ajax',
44 array(
45 array(
46 'methods' => WP_REST_Server::READABLE,
47 'callback' => array( $this, 'get_abilities' ),
48 'permission_callback' => array( $this, 'get_item_permissions_check' ),
49 ),
50 )
51 );
52 }
53
54 /**
55 * Checks if a given request has access to application password extras.
56 *
57 * @param WP_REST_Request $request Full details about the request.
58 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
59 */
60 public function get_item_permissions_check( $request ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
61 if ( ! is_user_logged_in() ) {
62 return new WP_Error(
63 'rest_forbidden',
64 __( 'Sorry, you must be logged in to access this endpoint.', 'jetpack' ),
65 array( 'status' => rest_authorization_required_code() )
66 );
67 }
68
69 return true;
70 }
71
72 /**
73 * Retrieves the application password extras abilities.
74 *
75 * @param WP_REST_Request $request Full details about the request.
76 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
77 */
78 public function get_abilities( $request ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
79 if ( ! class_exists( 'Jetpack_Application_Password_Extras' ) ) {
80 return new WP_Error(
81 'rest_application_password_extras_unavailable',
82 __( 'Application password extras functionality is not available.', 'jetpack' ),
83 array( 'status' => 503 )
84 );
85 }
86
87 return rest_ensure_response( Jetpack_Application_Password_Extras::get_abilities() );
88 }
89 }
90
91 wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Application_Password_Extras' );
92