Changeset 49109 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 10/08/2020 10:12:02 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r49108 r49109 210 210 211 211 add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 ); 212 add_filter( 'rest_index', 'rest_add_application_passwords_to_index' ); 212 213 } 213 214 … … 263 264 // Users. 264 265 $controller = new WP_REST_Users_Controller; 266 $controller->register_routes(); 267 268 // Application Passwords 269 $controller = new WP_REST_Application_Passwords_Controller(); 265 270 $controller->register_routes(); 266 271 … … 311 316 $controller = new WP_REST_Block_Directory_Controller(); 312 317 $controller->register_routes(); 313 314 318 } 315 319 … … 1033 1037 1034 1038 $wp_rest_auth_cookie = true; 1039 } 1040 1041 /** 1042 * Collects the status of authenticating with an application password. 1043 * 1044 * @since 5.6.0 1045 * 1046 * @global WP_User|WP_Error|null $wp_rest_application_password_status 1047 * 1048 * @param WP_Error $user_or_error The authenticated user or error instance. 1049 */ 1050 function rest_application_password_collect_status( $user_or_error ) { 1051 global $wp_rest_application_password_status; 1052 1053 $wp_rest_application_password_status = $user_or_error; 1054 } 1055 1056 /** 1057 * Checks for errors when using application password-based authentication. 1058 * 1059 * @since 5.6.0 1060 * 1061 * @global WP_User|WP_Error|null $wp_rest_application_password_status 1062 * 1063 * @param WP_Error|null|true $result Error from another authentication handler, 1064 * null if we should handle it, or another value if not. 1065 * @return WP_Error|null|true WP_Error if the application password is invalid, the $result, otherwise true. 1066 */ 1067 function rest_application_password_check_errors( $result ) { 1068 global $wp_rest_application_password_status; 1069 1070 if ( ! empty( $result ) ) { 1071 return $result; 1072 } 1073 1074 if ( is_wp_error( $wp_rest_application_password_status ) ) { 1075 $data = $wp_rest_application_password_status->get_error_data(); 1076 1077 if ( ! isset( $data['status'] ) ) { 1078 $data['status'] = 401; 1079 } 1080 1081 $wp_rest_application_password_status->add_data( $data ); 1082 1083 return $wp_rest_application_password_status; 1084 } 1085 1086 if ( $wp_rest_application_password_status instanceof WP_User ) { 1087 return true; 1088 } 1089 1090 return $result; 1091 } 1092 1093 /** 1094 * Adds Application Passwords info to the REST API index. 1095 * 1096 * @since 5.6.0 1097 * 1098 * @param WP_REST_Response $response The index response object. 1099 * @return WP_REST_Response 1100 */ 1101 function rest_add_application_passwords_to_index( $response ) { 1102 if ( ! wp_is_application_passwords_available() ) { 1103 return $response; 1104 } 1105 1106 $response->data['authentication']['application-passwords'] = array( 1107 'endpoints' => array( 1108 'authorization' => admin_url( 'authorize-application.php' ), 1109 ), 1110 ); 1111 1112 return $response; 1035 1113 } 1036 1114
Note: See TracChangeset
for help on using the changeset viewer.