-
diff --git src/wp-includes/rest-api.php src/wp-includes/rest-api.php
index 34e1c591f6..0b503776fa 100644
|
|
|
function register_rest_route( $namespace, $route, $args = array(), $override = f |
| 34 | 34 | * and namespace indexes. If you really need to register a |
| 35 | 35 | * non-namespaced route, call `WP_REST_Server::register_route` directly. |
| 36 | 36 | */ |
| 37 | | _doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' ); |
| | 37 | _doing_it_wrong( 'register_rest_route', _l( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' ); |
| 38 | 38 | return false; |
| 39 | 39 | } else if ( empty( $route ) ) { |
| 40 | | _doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' ); |
| | 40 | _doing_it_wrong( 'register_rest_route', _l( 'Route must be specified.' ), '4.4.0' ); |
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | |
| … |
… |
function rest_handle_deprecated_function( $function, $replacement, $version ) { |
| 491 | 491 | } |
| 492 | 492 | if ( ! empty( $replacement ) ) { |
| 493 | 493 | /* translators: 1: function name, 2: WordPress version number, 3: new function name */ |
| 494 | | $string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement ); |
| | 494 | $string = sprintf( _l( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement ); |
| 495 | 495 | } else { |
| 496 | 496 | /* translators: 1: function name, 2: WordPress version number */ |
| 497 | | $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
| | 497 | $string = sprintf( _l( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) ); |
| … |
… |
function rest_handle_deprecated_argument( $function, $message, $version ) { |
| 515 | 515 | } |
| 516 | 516 | if ( ! empty( $message ) ) { |
| 517 | 517 | /* translators: 1: function name, 2: WordPress version number, 3: error message */ |
| 518 | | $string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function, $version, $message ); |
| | 518 | $string = sprintf( _l( '%1$s (since %2$s; %3$s)' ), $function, $version, $message ); |
| 519 | 519 | } else { |
| 520 | 520 | /* translators: 1: function name, 2: WordPress version number */ |
| 521 | | $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
| | 521 | $string = sprintf( _l( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) ); |
| … |
… |
function rest_cookie_check_errors( $result ) { |
| 737 | 737 | $result = wp_verify_nonce( $nonce, 'wp_rest' ); |
| 738 | 738 | |
| 739 | 739 | if ( ! $result ) { |
| 740 | | return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) ); |
| | 740 | return new WP_Error( 'rest_cookie_invalid_nonce', _l( 'Cookie nonce is invalid' ), array( 'status' => 403 ) ); |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | // Send a refreshed nonce in header. |
| … |
… |
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
| 1042 | 1042 | } |
| 1043 | 1043 | if ( ! wp_is_numeric_array( $value ) ) { |
| 1044 | 1044 | /* translators: 1: parameter, 2: type name */ |
| 1045 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) ); |
| | 1045 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, 'array' ) ); |
| 1046 | 1046 | } |
| 1047 | 1047 | foreach ( $value as $index => $v ) { |
| 1048 | 1048 | $is_valid = rest_validate_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' ); |
| … |
… |
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
| 1076 | 1076 | if ( ! empty( $args['enum'] ) ) { |
| 1077 | 1077 | if ( ! in_array( $value, $args['enum'], true ) ) { |
| 1078 | 1078 | /* translators: 1: parameter, 2: list of valid values */ |
| 1079 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not one of %2$s.' ), $param, implode( ', ', $args['enum'] ) ) ); |
| | 1079 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not one of %2$s.' ), $param, implode( ', ', $args['enum'] ) ) ); |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | if ( in_array( $args['type'], array( 'integer', 'number' ) ) && ! is_numeric( $value ) ) { |
| 1084 | 1084 | /* translators: 1: parameter, 2: type name */ |
| 1085 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); |
| | 1085 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | if ( 'integer' === $args['type'] && round( floatval( $value ) ) !== floatval( $value ) ) { |
| 1089 | 1089 | /* translators: 1: parameter, 2: type name */ |
| 1090 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'integer' ) ); |
| | 1090 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, 'integer' ) ); |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | if ( 'boolean' === $args['type'] && ! rest_is_boolean( $value ) ) { |
| 1094 | 1094 | /* translators: 1: parameter, 2: type name */ |
| 1095 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $value, 'boolean' ) ); |
| | 1095 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $value, 'boolean' ) ); |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | if ( 'string' === $args['type'] && ! is_string( $value ) ) { |
| 1099 | 1099 | /* translators: 1: parameter, 2: type name */ |
| 1100 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'string' ) ); |
| | 1100 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, 'string' ) ); |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | if ( isset( $args['format'] ) ) { |
| 1104 | 1104 | switch ( $args['format'] ) { |
| 1105 | 1105 | case 'date-time' : |
| 1106 | 1106 | if ( ! rest_parse_date( $value ) ) { |
| 1107 | | return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) ); |
| | 1107 | return new WP_Error( 'rest_invalid_date', _l( 'Invalid date.' ) ); |
| 1108 | 1108 | } |
| 1109 | 1109 | break; |
| 1110 | 1110 | |
| 1111 | 1111 | case 'email' : |
| 1112 | 1112 | if ( ! is_email( $value ) ) { |
| 1113 | | return new WP_Error( 'rest_invalid_email', __( 'Invalid email address.' ) ); |
| | 1113 | return new WP_Error( 'rest_invalid_email', _l( 'Invalid email address.' ) ); |
| 1114 | 1114 | } |
| 1115 | 1115 | break; |
| 1116 | 1116 | case 'ip' : |
| 1117 | 1117 | if ( ! rest_is_ip_address( $value ) ) { |
| 1118 | 1118 | /* translators: %s: IP address */ |
| 1119 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) ); |
| | 1119 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%s is not a valid IP address.' ), $value ) ); |
| 1120 | 1120 | } |
| 1121 | 1121 | break; |
| 1122 | 1122 | } |
| … |
… |
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
| 1126 | 1126 | if ( isset( $args['minimum'] ) && ! isset( $args['maximum'] ) ) { |
| 1127 | 1127 | if ( ! empty( $args['exclusiveMinimum'] ) && $value <= $args['minimum'] ) { |
| 1128 | 1128 | /* translators: 1: parameter, 2: minimum number */ |
| 1129 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d' ), $param, $args['minimum'] ) ); |
| | 1129 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be greater than %2$d' ), $param, $args['minimum'] ) ); |
| 1130 | 1130 | } elseif ( empty( $args['exclusiveMinimum'] ) && $value < $args['minimum'] ) { |
| 1131 | 1131 | /* translators: 1: parameter, 2: minimum number */ |
| 1132 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than or equal to %2$d' ), $param, $args['minimum'] ) ); |
| | 1132 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be greater than or equal to %2$d' ), $param, $args['minimum'] ) ); |
| 1133 | 1133 | } |
| 1134 | 1134 | } elseif ( isset( $args['maximum'] ) && ! isset( $args['minimum'] ) ) { |
| 1135 | 1135 | if ( ! empty( $args['exclusiveMaximum'] ) && $value >= $args['maximum'] ) { |
| 1136 | 1136 | /* translators: 1: parameter, 2: maximum number */ |
| 1137 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d' ), $param, $args['maximum'] ) ); |
| | 1137 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be less than %2$d' ), $param, $args['maximum'] ) ); |
| 1138 | 1138 | } elseif ( empty( $args['exclusiveMaximum'] ) && $value > $args['maximum'] ) { |
| 1139 | 1139 | /* translators: 1: parameter, 2: maximum number */ |
| 1140 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than or equal to %2$d' ), $param, $args['maximum'] ) ); |
| | 1140 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be less than or equal to %2$d' ), $param, $args['maximum'] ) ); |
| 1141 | 1141 | } |
| 1142 | 1142 | } elseif ( isset( $args['maximum'] ) && isset( $args['minimum'] ) ) { |
| 1143 | 1143 | if ( ! empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) { |
| 1144 | 1144 | if ( $value >= $args['maximum'] || $value <= $args['minimum'] ) { |
| 1145 | 1145 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
| 1146 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (exclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| | 1146 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be between %2$d (exclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| 1147 | 1147 | } |
| 1148 | 1148 | } elseif ( empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) { |
| 1149 | 1149 | if ( $value >= $args['maximum'] || $value < $args['minimum'] ) { |
| 1150 | 1150 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
| 1151 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (inclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| | 1151 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be between %2$d (inclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| 1152 | 1152 | } |
| 1153 | 1153 | } elseif ( ! empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) { |
| 1154 | 1154 | if ( $value > $args['maximum'] || $value <= $args['minimum'] ) { |
| 1155 | 1155 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
| 1156 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (exclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| | 1156 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be between %2$d (exclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| 1157 | 1157 | } |
| 1158 | 1158 | } elseif ( empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) { |
| 1159 | 1159 | if ( $value > $args['maximum'] || $value < $args['minimum'] ) { |
| 1160 | 1160 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
| 1161 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (inclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| | 1161 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be between %2$d (inclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); |
| 1162 | 1162 | } |
| 1163 | 1163 | } |
| 1164 | 1164 | } |
-
diff --git src/wp-includes/rest-api/class-wp-rest-request.php src/wp-includes/rest-api/class-wp-rest-request.php
index f9c6317896..3f395ca2c2 100644
|
|
|
class WP_REST_Request implements ArrayAccess { |
| 654 | 654 | $error_data['json_error_message'] = json_last_error_msg(); |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | | return new WP_Error( 'rest_invalid_json', __( 'Invalid JSON body passed.' ), $error_data ); |
| | 657 | return new WP_Error( 'rest_invalid_json', _l( 'Invalid JSON body passed.' ), $error_data ); |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | $this->params['JSON'] = $params; |
| … |
… |
class WP_REST_Request implements ArrayAccess { |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | if ( $invalid_params ) { |
| 805 | | return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
| | 805 | return new WP_Error( 'rest_invalid_param', sprintf( _l( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | return true; |
| … |
… |
class WP_REST_Request implements ArrayAccess { |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | if ( ! empty( $required ) ) { |
| 843 | | return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) ); |
| | 843 | return new WP_Error( 'rest_missing_callback_param', sprintf( _l( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) ); |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | /* |
| … |
… |
class WP_REST_Request implements ArrayAccess { |
| 858 | 858 | $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key ); |
| 859 | 859 | |
| 860 | 860 | if ( false === $valid_check ) { |
| 861 | | $invalid_params[ $key ] = __( 'Invalid parameter.' ); |
| | 861 | $invalid_params[ $key ] = _l( 'Invalid parameter.' ); |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | if ( is_wp_error( $valid_check ) ) { |
| … |
… |
class WP_REST_Request implements ArrayAccess { |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | if ( $invalid_params ) { |
| 871 | | return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
| | 871 | return new WP_Error( 'rest_invalid_param', sprintf( _l( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | return true; |
-
diff --git src/wp-includes/rest-api/class-wp-rest-server.php src/wp-includes/rest-api/class-wp-rest-server.php
index c69cb4834c..936d0592dc 100644
|
|
|
class WP_REST_Server { |
| 261 | 261 | * @param bool $rest_enabled Whether the REST API is enabled. Default true. |
| 262 | 262 | */ |
| 263 | 263 | apply_filters_deprecated( 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors', |
| 264 | | __( 'The REST API can no longer be completely disabled, the rest_authentication_errors filter can be used to restrict access to the API, instead.' ) |
| | 264 | _l( 'The REST API can no longer be completely disabled, the rest_authentication_errors filter can be used to restrict access to the API, instead.' ) |
| 265 | 265 | ); |
| 266 | 266 | |
| 267 | 267 | /** |
| … |
… |
class WP_REST_Server { |
| 277 | 277 | |
| 278 | 278 | if ( isset( $_GET['_jsonp'] ) ) { |
| 279 | 279 | if ( ! $jsonp_enabled ) { |
| 280 | | echo $this->json_error( 'rest_callback_disabled', __( 'JSONP support is disabled on this site.' ), 400 ); |
| | 280 | echo $this->json_error( 'rest_callback_disabled', _l( 'JSONP support is disabled on this site.' ), 400 ); |
| 281 | 281 | return false; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $jsonp_callback = $_GET['_jsonp']; |
| 285 | 285 | if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) { |
| 286 | | echo $this->json_error( 'rest_callback_invalid', __( 'Invalid JSONP callback function.' ), 400 ); |
| | 286 | echo $this->json_error( 'rest_callback_invalid', _l( 'Invalid JSONP callback function.' ), 400 ); |
| 287 | 287 | return false; |
| 288 | 288 | } |
| 289 | 289 | } |
| … |
… |
class WP_REST_Server { |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | if ( ! is_callable( $callback ) ) { |
| 854 | | $response = new WP_Error( 'rest_invalid_handler', __( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); |
| | 854 | $response = new WP_Error( 'rest_invalid_handler', _l( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); |
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | if ( ! is_wp_error( $response ) ) { |
| … |
… |
class WP_REST_Server { |
| 908 | 908 | if ( is_wp_error( $permission ) ) { |
| 909 | 909 | $response = $permission; |
| 910 | 910 | } elseif ( false === $permission || null === $permission ) { |
| 911 | | $response = new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( 'status' => 403 ) ); |
| | 911 | $response = new WP_Error( 'rest_forbidden', _l( 'Sorry, you are not allowed to do that.' ), array( 'status' => 403 ) ); |
| 912 | 912 | } |
| 913 | 913 | } |
| 914 | 914 | } |
| … |
… |
class WP_REST_Server { |
| 972 | 972 | } |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | | return $this->error_to_response( new WP_Error( 'rest_no_route', __( 'No route was found matching the URL and request method' ), array( 'status' => 404 ) ) ); |
| | 975 | return $this->error_to_response( new WP_Error( 'rest_no_route', _l( 'No route was found matching the URL and request method' ), array( 'status' => 404 ) ) ); |
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | /** |
| … |
… |
class WP_REST_Server { |
| 1059 | 1059 | $namespace = $request['namespace']; |
| 1060 | 1060 | |
| 1061 | 1061 | if ( ! isset( $this->namespaces[ $namespace ] ) ) { |
| 1062 | | return new WP_Error( 'rest_invalid_namespace', __( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); |
| | 1062 | return new WP_Error( 'rest_invalid_namespace', _l( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | $routes = $this->namespaces[ $namespace ]; |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index ed101815a1..8f29b1bce0 100644
|
|
|
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if ( ! current_user_can( 'upload_files' ) ) { |
| 73 | | return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to upload media on this site.' ), array( 'status' => 400 ) ); |
| | 73 | return new WP_Error( 'rest_cannot_create', _l( 'Sorry, you are not allowed to upload media on this site.' ), array( 'status' => 400 ) ); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Attaching media to a post requires ability to edit said post. |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 79 | 79 | $post_parent_type = get_post_type_object( $parent->post_type ); |
| 80 | 80 | |
| 81 | 81 | if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) { |
| 82 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to upload media to this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 82 | return new WP_Error( 'rest_cannot_edit', _l( 'Sorry, you are not allowed to upload media to this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 97 | 97 | public function create_item( $request ) { |
| 98 | 98 | |
| 99 | 99 | if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { |
| 100 | | return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
| | 100 | return new WP_Error( 'rest_invalid_param', _l( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // Get the file via $_FILES or raw data. |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 203 | 203 | */ |
| 204 | 204 | public function update_item( $request ) { |
| 205 | 205 | if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { |
| 206 | | return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
| | 206 | return new WP_Error( 'rest_invalid_param', _l( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | $response = parent::update_item( $request ); |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 377 | 377 | $schema = parent::get_item_schema(); |
| 378 | 378 | |
| 379 | 379 | $schema['properties']['alt_text'] = array( |
| 380 | | 'description' => __( 'Alternative text to display when attachment is not displayed.' ), |
| | 380 | 'description' => _l( 'Alternative text to display when attachment is not displayed.' ), |
| 381 | 381 | 'type' => 'string', |
| 382 | 382 | 'context' => array( 'view', 'edit', 'embed' ), |
| 383 | 383 | 'arg_options' => array( |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 386 | 386 | ); |
| 387 | 387 | |
| 388 | 388 | $schema['properties']['caption'] = array( |
| 389 | | 'description' => __( 'The attachment caption.' ), |
| | 389 | 'description' => _l( 'The attachment caption.' ), |
| 390 | 390 | 'type' => 'object', |
| 391 | 391 | 'context' => array( 'view', 'edit', 'embed' ), |
| 392 | 392 | 'arg_options' => array( |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 395 | 395 | ), |
| 396 | 396 | 'properties' => array( |
| 397 | 397 | 'raw' => array( |
| 398 | | 'description' => __( 'Caption for the attachment, as it exists in the database.' ), |
| | 398 | 'description' => _l( 'Caption for the attachment, as it exists in the database.' ), |
| 399 | 399 | 'type' => 'string', |
| 400 | 400 | 'context' => array( 'edit' ), |
| 401 | 401 | ), |
| 402 | 402 | 'rendered' => array( |
| 403 | | 'description' => __( 'HTML caption for the attachment, transformed for display.' ), |
| | 403 | 'description' => _l( 'HTML caption for the attachment, transformed for display.' ), |
| 404 | 404 | 'type' => 'string', |
| 405 | 405 | 'context' => array( 'view', 'edit', 'embed' ), |
| 406 | 406 | 'readonly' => true, |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 409 | 409 | ); |
| 410 | 410 | |
| 411 | 411 | $schema['properties']['description'] = array( |
| 412 | | 'description' => __( 'The attachment description.' ), |
| | 412 | 'description' => _l( 'The attachment description.' ), |
| 413 | 413 | 'type' => 'object', |
| 414 | 414 | 'context' => array( 'view', 'edit' ), |
| 415 | 415 | 'arg_options' => array( |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 418 | 418 | ), |
| 419 | 419 | 'properties' => array( |
| 420 | 420 | 'raw' => array( |
| 421 | | 'description' => __( 'Description for the object, as it exists in the database.' ), |
| | 421 | 'description' => _l( 'Description for the object, as it exists in the database.' ), |
| 422 | 422 | 'type' => 'string', |
| 423 | 423 | 'context' => array( 'edit' ), |
| 424 | 424 | ), |
| 425 | 425 | 'rendered' => array( |
| 426 | | 'description' => __( 'HTML description for the object, transformed for display.' ), |
| | 426 | 'description' => _l( 'HTML description for the object, transformed for display.' ), |
| 427 | 427 | 'type' => 'string', |
| 428 | 428 | 'context' => array( 'view', 'edit' ), |
| 429 | 429 | 'readonly' => true, |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 432 | 432 | ); |
| 433 | 433 | |
| 434 | 434 | $schema['properties']['media_type'] = array( |
| 435 | | 'description' => __( 'Attachment type.' ), |
| | 435 | 'description' => _l( 'Attachment type.' ), |
| 436 | 436 | 'type' => 'string', |
| 437 | 437 | 'enum' => array( 'image', 'file' ), |
| 438 | 438 | 'context' => array( 'view', 'edit', 'embed' ), |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 440 | 440 | ); |
| 441 | 441 | |
| 442 | 442 | $schema['properties']['mime_type'] = array( |
| 443 | | 'description' => __( 'The attachment MIME type.' ), |
| | 443 | 'description' => _l( 'The attachment MIME type.' ), |
| 444 | 444 | 'type' => 'string', |
| 445 | 445 | 'context' => array( 'view', 'edit', 'embed' ), |
| 446 | 446 | 'readonly' => true, |
| 447 | 447 | ); |
| 448 | 448 | |
| 449 | 449 | $schema['properties']['media_details'] = array( |
| 450 | | 'description' => __( 'Details about the media file, specific to its type.' ), |
| | 450 | 'description' => _l( 'Details about the media file, specific to its type.' ), |
| 451 | 451 | 'type' => 'object', |
| 452 | 452 | 'context' => array( 'view', 'edit', 'embed' ), |
| 453 | 453 | 'readonly' => true, |
| 454 | 454 | ); |
| 455 | 455 | |
| 456 | 456 | $schema['properties']['post'] = array( |
| 457 | | 'description' => __( 'The ID for the associated post of the attachment.' ), |
| | 457 | 'description' => _l( 'The ID for the associated post of the attachment.' ), |
| 458 | 458 | 'type' => 'integer', |
| 459 | 459 | 'context' => array( 'view', 'edit' ), |
| 460 | 460 | ); |
| 461 | 461 | |
| 462 | 462 | $schema['properties']['source_url'] = array( |
| 463 | | 'description' => __( 'URL to the original attachment file.' ), |
| | 463 | 'description' => _l( 'URL to the original attachment file.' ), |
| 464 | 464 | 'type' => 'string', |
| 465 | 465 | 'format' => 'uri', |
| 466 | 466 | 'context' => array( 'view', 'edit', 'embed' ), |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 483 | 483 | */ |
| 484 | 484 | protected function upload_from_data( $data, $headers ) { |
| 485 | 485 | if ( empty( $data ) ) { |
| 486 | | return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); |
| | 486 | return new WP_Error( 'rest_upload_no_data', _l( 'No data supplied.' ), array( 'status' => 400 ) ); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | if ( empty( $headers['content_type'] ) ) { |
| 490 | | return new WP_Error( 'rest_upload_no_content_type', __( 'No Content-Type supplied.' ), array( 'status' => 400 ) ); |
| | 490 | return new WP_Error( 'rest_upload_no_content_type', _l( 'No Content-Type supplied.' ), array( 'status' => 400 ) ); |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | if ( empty( $headers['content_disposition'] ) ) { |
| 494 | | return new WP_Error( 'rest_upload_no_content_disposition', __( 'No Content-Disposition supplied.' ), array( 'status' => 400 ) ); |
| | 494 | return new WP_Error( 'rest_upload_no_content_disposition', _l( 'No Content-Disposition supplied.' ), array( 'status' => 400 ) ); |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | $filename = self::get_filename_from_disposition( $headers['content_disposition'] ); |
| 498 | 498 | |
| 499 | 499 | if ( empty( $filename ) ) { |
| 500 | | return new WP_Error( 'rest_upload_invalid_disposition', __( 'Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.' ), array( 'status' => 400 ) ); |
| | 500 | return new WP_Error( 'rest_upload_invalid_disposition', _l( 'Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.' ), array( 'status' => 400 ) ); |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | if ( ! empty( $headers['content_md5'] ) ) { |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 506 | 506 | $actual = md5( $data ); |
| 507 | 507 | |
| 508 | 508 | if ( $expected !== $actual ) { |
| 509 | | return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
| | 509 | return new WP_Error( 'rest_upload_hash_mismatch', _l( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | 512 | |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 522 | 522 | $fp = fopen( $tmpfname, 'w+' ); |
| 523 | 523 | |
| 524 | 524 | if ( ! $fp ) { |
| 525 | | return new WP_Error( 'rest_upload_file_error', __( 'Could not open file handle.' ), array( 'status' => 500 ) ); |
| | 525 | return new WP_Error( 'rest_upload_file_error', _l( 'Could not open file handle.' ), array( 'status' => 500 ) ); |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | fwrite( $fp, $data ); |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 636 | 636 | |
| 637 | 637 | $params['media_type'] = array( |
| 638 | 638 | 'default' => null, |
| 639 | | 'description' => __( 'Limit result set to attachments of a particular media type.' ), |
| | 639 | 'description' => _l( 'Limit result set to attachments of a particular media type.' ), |
| 640 | 640 | 'type' => 'string', |
| 641 | 641 | 'enum' => array_keys( $media_types ), |
| 642 | 642 | ); |
| 643 | 643 | |
| 644 | 644 | $params['mime_type'] = array( |
| 645 | 645 | 'default' => null, |
| 646 | | 'description' => __( 'Limit result set to attachments of a particular MIME type.' ), |
| | 646 | 'description' => _l( 'Limit result set to attachments of a particular MIME type.' ), |
| 647 | 647 | 'type' => 'string', |
| 648 | 648 | ); |
| 649 | 649 | |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 679 | 679 | */ |
| 680 | 680 | protected function upload_from_file( $files, $headers ) { |
| 681 | 681 | if ( empty( $files ) ) { |
| 682 | | return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); |
| | 682 | return new WP_Error( 'rest_upload_no_data', _l( 'No data supplied.' ), array( 'status' => 400 ) ); |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | // Verify hash, if given. |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 689 | 689 | $actual = md5_file( $files['file']['tmp_name'] ); |
| 690 | 690 | |
| 691 | 691 | if ( $expected !== $actual ) { |
| 692 | | return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
| | 692 | return new WP_Error( 'rest_upload_hash_mismatch', _l( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
| 693 | 693 | } |
| 694 | 694 | } |
| 695 | 695 | |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
index 415ba8e9bc..ff62935da5 100644
|
|
|
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 62 | 62 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
| 63 | 63 | 'args' => array( |
| 64 | 64 | 'id' => array( |
| 65 | | 'description' => __( 'Unique identifier for the object.' ), |
| | 65 | 'description' => _l( 'Unique identifier for the object.' ), |
| 66 | 66 | 'type' => 'integer', |
| 67 | 67 | ), |
| 68 | 68 | ), |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 73 | 73 | 'args' => array( |
| 74 | 74 | 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
| 75 | 75 | 'password' => array( |
| 76 | | 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), |
| | 76 | 'description' => _l( 'The password for the parent post of the comment (if the post is password protected).' ), |
| 77 | 77 | 'type' => 'string', |
| 78 | 78 | ), |
| 79 | 79 | ), |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 92 | 92 | 'force' => array( |
| 93 | 93 | 'type' => 'boolean', |
| 94 | 94 | 'default' => false, |
| 95 | | 'description' => __( 'Whether to bypass trash and force deletion.' ), |
| | 95 | 'description' => _l( 'Whether to bypass trash and force deletion.' ), |
| 96 | 96 | ), |
| 97 | 97 | 'password' => array( |
| 98 | | 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), |
| | 98 | 'description' => _l( 'The password for the parent post of the comment (if the post is password protected).' ), |
| 99 | 99 | 'type' => 'string', |
| 100 | 100 | ), |
| 101 | 101 | ), |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 119 | 119 | $post = get_post( $post_id ); |
| 120 | 120 | |
| 121 | 121 | if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post, $request ) ) { |
| 122 | | return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 122 | return new WP_Error( 'rest_cannot_read_post', _l( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 123 | 123 | } elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) { |
| 124 | | return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 124 | return new WP_Error( 'rest_cannot_read', _l( 'Sorry, you are not allowed to read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { |
| 130 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 130 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if ( ! current_user_can( 'edit_posts' ) ) { |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if ( ! empty( $forbidden_params ) ) { |
| 152 | | return new WP_Error( 'rest_forbidden_param', sprintf( __( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) ); |
| | 152 | return new WP_Error( 'rest_forbidden_param', sprintf( _l( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) ); |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 309 | 309 | * @return WP_Comment|WP_Error Comment object if ID is valid, WP_Error otherwise. |
| 310 | 310 | */ |
| 311 | 311 | protected function get_comment( $id ) { |
| 312 | | $error = new WP_Error( 'rest_comment_invalid_id', __( 'Invalid comment ID.' ), array( 'status' => 404 ) ); |
| | 312 | $error = new WP_Error( 'rest_comment_invalid_id', _l( 'Invalid comment ID.' ), array( 'status' => 404 ) ); |
| 313 | 313 | if ( (int) $id <= 0 ) { |
| 314 | 314 | return $error; |
| 315 | 315 | } |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 323 | 323 | if ( ! empty( $comment->comment_post_ID ) ) { |
| 324 | 324 | $post = get_post( (int) $comment->comment_post_ID ); |
| 325 | 325 | if ( empty( $post ) ) { |
| 326 | | return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
| | 326 | return new WP_Error( 'rest_post_invalid_id', _l( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { |
| 348 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 348 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | $post = get_post( $comment->comment_post_ID ); |
| 352 | 352 | |
| 353 | 353 | if ( ! $this->check_read_permission( $comment, $request ) ) { |
| 354 | | return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 354 | return new WP_Error( 'rest_cannot_read', _l( 'Sorry, you are not allowed to read this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | if ( $post && ! $this->check_read_post_permission( $post, $request ) ) { |
| 358 | | return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 358 | return new WP_Error( 'rest_cannot_read_post', _l( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | return true; |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 392 | 392 | public function create_item_permissions_check( $request ) { |
| 393 | 393 | if ( ! is_user_logged_in() ) { |
| 394 | 394 | if ( get_option( 'comment_registration' ) ) { |
| 395 | | return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
| | 395 | return new WP_Error( 'rest_comment_login_required', _l( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 409 | 409 | */ |
| 410 | 410 | $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request ); |
| 411 | 411 | if ( ! $allow_anonymous ) { |
| 412 | | return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
| | 412 | return new WP_Error( 'rest_comment_login_required', _l( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 417 | 417 | if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { |
| 418 | 418 | return new WP_Error( 'rest_comment_invalid_author', |
| 419 | 419 | /* translators: %s: request parameter */ |
| 420 | | sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), |
| | 420 | sprintf( _l( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), |
| 421 | 421 | array( 'status' => rest_authorization_required_code() ) |
| 422 | 422 | ); |
| 423 | 423 | } |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 426 | 426 | if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) { |
| 427 | 427 | return new WP_Error( 'rest_comment_invalid_author_ip', |
| 428 | 428 | /* translators: %s: request parameter */ |
| 429 | | sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ), |
| | 429 | sprintf( _l( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ), |
| 430 | 430 | array( 'status' => rest_authorization_required_code() ) |
| 431 | 431 | ); |
| 432 | 432 | } |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 435 | 435 | if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) { |
| 436 | 436 | return new WP_Error( 'rest_comment_invalid_status', |
| 437 | 437 | /* translators: %s: request parameter */ |
| 438 | | sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ), |
| | 438 | sprintf( _l( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ), |
| 439 | 439 | array( 'status' => rest_authorization_required_code() ) |
| 440 | 440 | ); |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | if ( empty( $request['post'] ) ) { |
| 444 | | return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); |
| | 444 | return new WP_Error( 'rest_comment_invalid_post_id', _l( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | $post = get_post( (int) $request['post'] ); |
| 448 | 448 | if ( ! $post ) { |
| 449 | | return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); |
| | 449 | return new WP_Error( 'rest_comment_invalid_post_id', _l( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | if ( 'draft' === $post->post_status ) { |
| 453 | | return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
| | 453 | return new WP_Error( 'rest_comment_draft_post', _l( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | if ( 'trash' === $post->post_status ) { |
| 457 | | return new WP_Error( 'rest_comment_trash_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
| | 457 | return new WP_Error( 'rest_comment_trash_post', _l( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | if ( ! $this->check_read_post_permission( $post, $request ) ) { |
| 461 | | return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 461 | return new WP_Error( 'rest_cannot_read_post', _l( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | if ( ! comments_open( $post->ID ) ) { |
| 465 | | return new WP_Error( 'rest_comment_closed', __( 'Sorry, comments are closed for this item.' ), array( 'status' => 403 ) ); |
| | 465 | return new WP_Error( 'rest_comment_closed', _l( 'Sorry, comments are closed for this item.' ), array( 'status' => 403 ) ); |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | return true; |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 478 | 478 | */ |
| 479 | 479 | public function create_item( $request ) { |
| 480 | 480 | if ( ! empty( $request['id'] ) ) { |
| 481 | | return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) ); |
| | 481 | return new WP_Error( 'rest_comment_exists', _l( 'Cannot create existing comment.' ), array( 'status' => 400 ) ); |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | // Do not allow comments to be created with a non-default type. |
| 485 | 485 | if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) { |
| 486 | | return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); |
| | 486 | return new WP_Error( 'rest_invalid_comment_type', _l( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | $prepared_comment = $this->prepare_item_for_database( $request ); |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 498 | 498 | * comment_content. See wp_handle_comment_submission(). |
| 499 | 499 | */ |
| 500 | 500 | if ( empty( $prepared_comment['comment_content'] ) ) { |
| 501 | | return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
| | 501 | return new WP_Error( 'rest_comment_content_invalid', _l( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 524 | 524 | // Honor the discussion setting that requires a name and email address of the comment author. |
| 525 | 525 | if ( get_option( 'require_name_email' ) ) { |
| 526 | 526 | if ( empty( $prepared_comment['comment_author'] ) || empty( $prepared_comment['comment_author_email'] ) ) { |
| 527 | | return new WP_Error( 'rest_comment_author_data_required', __( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) ); |
| | 527 | return new WP_Error( 'rest_comment_author_data_required', _l( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) ); |
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 543 | 543 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_comment ); |
| 544 | 544 | if ( is_wp_error( $check_comment_lengths ) ) { |
| 545 | 545 | $error_code = $check_comment_lengths->get_error_code(); |
| 546 | | return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
| | 546 | return new WP_Error( $error_code, _l( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | $prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true ); |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 584 | 584 | $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) ); |
| 585 | 585 | |
| 586 | 586 | if ( ! $comment_id ) { |
| 587 | | return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) ); |
| | 587 | return new WP_Error( 'rest_comment_failed_create', _l( 'Creating comment failed.' ), array( 'status' => 500 ) ); |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | if ( isset( $request['status'] ) ) { |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | if ( ! $this->check_edit_permission( $comment ) ) { |
| 653 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 653 | return new WP_Error( 'rest_cannot_edit', _l( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | return true; |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 673 | 673 | $id = $comment->comment_ID; |
| 674 | 674 | |
| 675 | 675 | if ( isset( $request['type'] ) && get_comment_type( $id ) !== $request['type'] ) { |
| 676 | | return new WP_Error( 'rest_comment_invalid_type', __( 'Sorry, you are not allowed to change the comment type.' ), array( 'status' => 404 ) ); |
| | 676 | return new WP_Error( 'rest_comment_invalid_type', _l( 'Sorry, you are not allowed to change the comment type.' ), array( 'status' => 404 ) ); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | $prepared_args = $this->prepare_item_for_database( $request ); |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 685 | 685 | if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
| 686 | 686 | $post = get_post( $prepared_args['comment_post_ID'] ); |
| 687 | 687 | if ( empty( $post ) ) { |
| 688 | | return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) ); |
| | 688 | return new WP_Error( 'rest_comment_invalid_post_id', _l( 'Invalid post ID.' ), array( 'status' => 403 ) ); |
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | 691 | |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 694 | 694 | $change = $this->handle_status_param( $request['status'], $id ); |
| 695 | 695 | |
| 696 | 696 | if ( ! $change ) { |
| 697 | | return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment status failed.' ), array( 'status' => 500 ) ); |
| | 697 | return new WP_Error( 'rest_comment_failed_edit', _l( 'Updating comment status failed.' ), array( 'status' => 500 ) ); |
| 698 | 698 | } |
| 699 | 699 | } elseif ( ! empty( $prepared_args ) ) { |
| 700 | 700 | if ( is_wp_error( $prepared_args ) ) { |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
| 705 | | return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
| | 705 | return new WP_Error( 'rest_comment_content_invalid', _l( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | $prepared_args['comment_ID'] = $id; |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 710 | 710 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
| 711 | 711 | if ( is_wp_error( $check_comment_lengths ) ) { |
| 712 | 712 | $error_code = $check_comment_lengths->get_error_code(); |
| 713 | | return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
| | 713 | return new WP_Error( $error_code, _l( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); |
| 717 | 717 | |
| 718 | 718 | if ( false === $updated ) { |
| 719 | | return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); |
| | 719 | return new WP_Error( 'rest_comment_failed_edit', _l( 'Updating comment failed.' ), array( 'status' => 500 ) ); |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | if ( isset( $request['status'] ) ) { |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | if ( ! $this->check_edit_permission( $comment ) ) { |
| 770 | | return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 770 | return new WP_Error( 'rest_cannot_delete', _l( 'Sorry, you are not allowed to delete this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 771 | 771 | } |
| 772 | 772 | return true; |
| 773 | 773 | } |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 811 | 811 | // If this type doesn't support trashing, error out. |
| 812 | 812 | if ( ! $supports_trash ) { |
| 813 | 813 | /* translators: %s: force=true */ |
| 814 | | return new WP_Error( 'rest_trash_not_supported', sprintf( __( "The comment does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| | 814 | return new WP_Error( 'rest_trash_not_supported', sprintf( _l( "The comment does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | if ( 'trash' === $comment->comment_approved ) { |
| 818 | | return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) ); |
| | 818 | return new WP_Error( 'rest_already_trashed', _l( 'The comment has already been trashed.' ), array( 'status' => 410 ) ); |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | $result = wp_trash_comment( $comment->comment_ID ); |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | if ( ! $result ) { |
| 827 | | return new WP_Error( 'rest_cannot_delete', __( 'The comment cannot be deleted.' ), array( 'status' => 500 ) ); |
| | 827 | return new WP_Error( 'rest_cannot_delete', _l( 'The comment cannot be deleted.' ), array( 'status' => 500 ) ); |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1075 | 1075 | $prepared_comment['comment_author_email'] = $user->user_email; |
| 1076 | 1076 | $prepared_comment['comment_author_url'] = $user->user_url; |
| 1077 | 1077 | } else { |
| 1078 | | return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); |
| | 1078 | return new WP_Error( 'rest_comment_author_invalid', _l( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); |
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1146 | 1146 | 'type' => 'object', |
| 1147 | 1147 | 'properties' => array( |
| 1148 | 1148 | 'id' => array( |
| 1149 | | 'description' => __( 'Unique identifier for the object.' ), |
| | 1149 | 'description' => _l( 'Unique identifier for the object.' ), |
| 1150 | 1150 | 'type' => 'integer', |
| 1151 | 1151 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1152 | 1152 | 'readonly' => true, |
| 1153 | 1153 | ), |
| 1154 | 1154 | 'author' => array( |
| 1155 | | 'description' => __( 'The ID of the user object, if author was a user.' ), |
| | 1155 | 'description' => _l( 'The ID of the user object, if author was a user.' ), |
| 1156 | 1156 | 'type' => 'integer', |
| 1157 | 1157 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1158 | 1158 | ), |
| 1159 | 1159 | 'author_email' => array( |
| 1160 | | 'description' => __( 'Email address for the object author.' ), |
| | 1160 | 'description' => _l( 'Email address for the object author.' ), |
| 1161 | 1161 | 'type' => 'string', |
| 1162 | 1162 | 'format' => 'email', |
| 1163 | 1163 | 'context' => array( 'edit' ), |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1167 | 1167 | ), |
| 1168 | 1168 | ), |
| 1169 | 1169 | 'author_ip' => array( |
| 1170 | | 'description' => __( 'IP address for the object author.' ), |
| | 1170 | 'description' => _l( 'IP address for the object author.' ), |
| 1171 | 1171 | 'type' => 'string', |
| 1172 | 1172 | 'format' => 'ip', |
| 1173 | 1173 | 'context' => array( 'edit' ), |
| 1174 | 1174 | ), |
| 1175 | 1175 | 'author_name' => array( |
| 1176 | | 'description' => __( 'Display name for the object author.' ), |
| | 1176 | 'description' => _l( 'Display name for the object author.' ), |
| 1177 | 1177 | 'type' => 'string', |
| 1178 | 1178 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1179 | 1179 | 'arg_options' => array( |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1181 | 1181 | ), |
| 1182 | 1182 | ), |
| 1183 | 1183 | 'author_url' => array( |
| 1184 | | 'description' => __( 'URL for the object author.' ), |
| | 1184 | 'description' => _l( 'URL for the object author.' ), |
| 1185 | 1185 | 'type' => 'string', |
| 1186 | 1186 | 'format' => 'uri', |
| 1187 | 1187 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1188 | 1188 | ), |
| 1189 | 1189 | 'author_user_agent' => array( |
| 1190 | | 'description' => __( 'User agent for the object author.' ), |
| | 1190 | 'description' => _l( 'User agent for the object author.' ), |
| 1191 | 1191 | 'type' => 'string', |
| 1192 | 1192 | 'context' => array( 'edit' ), |
| 1193 | 1193 | 'arg_options' => array( |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1195 | 1195 | ), |
| 1196 | 1196 | ), |
| 1197 | 1197 | 'content' => array( |
| 1198 | | 'description' => __( 'The content for the object.' ), |
| | 1198 | 'description' => _l( 'The content for the object.' ), |
| 1199 | 1199 | 'type' => 'object', |
| 1200 | 1200 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1201 | 1201 | 'arg_options' => array( |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1204 | 1204 | ), |
| 1205 | 1205 | 'properties' => array( |
| 1206 | 1206 | 'raw' => array( |
| 1207 | | 'description' => __( 'Content for the object, as it exists in the database.' ), |
| | 1207 | 'description' => _l( 'Content for the object, as it exists in the database.' ), |
| 1208 | 1208 | 'type' => 'string', |
| 1209 | 1209 | 'context' => array( 'edit' ), |
| 1210 | 1210 | ), |
| 1211 | 1211 | 'rendered' => array( |
| 1212 | | 'description' => __( 'HTML content for the object, transformed for display.' ), |
| | 1212 | 'description' => _l( 'HTML content for the object, transformed for display.' ), |
| 1213 | 1213 | 'type' => 'string', |
| 1214 | 1214 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1215 | 1215 | 'readonly' => true, |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1217 | 1217 | ), |
| 1218 | 1218 | ), |
| 1219 | 1219 | 'date' => array( |
| 1220 | | 'description' => __( "The date the object was published, in the site's timezone." ), |
| | 1220 | 'description' => _l( "The date the object was published, in the site's timezone." ), |
| 1221 | 1221 | 'type' => 'string', |
| 1222 | 1222 | 'format' => 'date-time', |
| 1223 | 1223 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1224 | 1224 | ), |
| 1225 | 1225 | 'date_gmt' => array( |
| 1226 | | 'description' => __( 'The date the object was published, as GMT.' ), |
| | 1226 | 'description' => _l( 'The date the object was published, as GMT.' ), |
| 1227 | 1227 | 'type' => 'string', |
| 1228 | 1228 | 'format' => 'date-time', |
| 1229 | 1229 | 'context' => array( 'view', 'edit' ), |
| 1230 | 1230 | ), |
| 1231 | 1231 | 'link' => array( |
| 1232 | | 'description' => __( 'URL to the object.' ), |
| | 1232 | 'description' => _l( 'URL to the object.' ), |
| 1233 | 1233 | 'type' => 'string', |
| 1234 | 1234 | 'format' => 'uri', |
| 1235 | 1235 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1236 | 1236 | 'readonly' => true, |
| 1237 | 1237 | ), |
| 1238 | 1238 | 'parent' => array( |
| 1239 | | 'description' => __( 'The ID for the parent of the object.' ), |
| | 1239 | 'description' => _l( 'The ID for the parent of the object.' ), |
| 1240 | 1240 | 'type' => 'integer', |
| 1241 | 1241 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1242 | 1242 | 'default' => 0, |
| 1243 | 1243 | ), |
| 1244 | 1244 | 'post' => array( |
| 1245 | | 'description' => __( 'The ID of the associated post object.' ), |
| | 1245 | 'description' => _l( 'The ID of the associated post object.' ), |
| 1246 | 1246 | 'type' => 'integer', |
| 1247 | 1247 | 'context' => array( 'view', 'edit' ), |
| 1248 | 1248 | 'default' => 0, |
| 1249 | 1249 | ), |
| 1250 | 1250 | 'status' => array( |
| 1251 | | 'description' => __( 'State of the object.' ), |
| | 1251 | 'description' => _l( 'State of the object.' ), |
| 1252 | 1252 | 'type' => 'string', |
| 1253 | 1253 | 'context' => array( 'view', 'edit' ), |
| 1254 | 1254 | 'arg_options' => array( |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1256 | 1256 | ), |
| 1257 | 1257 | ), |
| 1258 | 1258 | 'type' => array( |
| 1259 | | 'description' => __( 'Type of Comment for the object.' ), |
| | 1259 | 'description' => _l( 'Type of Comment for the object.' ), |
| 1260 | 1260 | 'type' => 'string', |
| 1261 | 1261 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1262 | 1262 | 'readonly' => true, |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1271 | 1271 | foreach ( $avatar_sizes as $size ) { |
| 1272 | 1272 | $avatar_properties[ $size ] = array( |
| 1273 | 1273 | /* translators: %d: avatar image size in pixels */ |
| 1274 | | 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ), |
| | 1274 | 'description' => sprintf( _l( 'Avatar URL with image size of %d pixels.' ), $size ), |
| 1275 | 1275 | 'type' => 'string', |
| 1276 | 1276 | 'format' => 'uri', |
| 1277 | 1277 | 'context' => array( 'embed', 'view', 'edit' ), |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1279 | 1279 | } |
| 1280 | 1280 | |
| 1281 | 1281 | $schema['properties']['author_avatar_urls'] = array( |
| 1282 | | 'description' => __( 'Avatar URLs for the object author.' ), |
| | 1282 | 'description' => _l( 'Avatar URLs for the object author.' ), |
| 1283 | 1283 | 'type' => 'object', |
| 1284 | 1284 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1285 | 1285 | 'readonly' => true, |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1305 | 1305 | $query_params['context']['default'] = 'view'; |
| 1306 | 1306 | |
| 1307 | 1307 | $query_params['after'] = array( |
| 1308 | | 'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ), |
| | 1308 | 'description' => _l( 'Limit response to comments published after a given ISO8601 compliant date.' ), |
| 1309 | 1309 | 'type' => 'string', |
| 1310 | 1310 | 'format' => 'date-time', |
| 1311 | 1311 | ); |
| 1312 | 1312 | |
| 1313 | 1313 | $query_params['author'] = array( |
| 1314 | | 'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), |
| | 1314 | 'description' => _l( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), |
| 1315 | 1315 | 'type' => 'array', |
| 1316 | 1316 | 'items' => array( |
| 1317 | 1317 | 'type' => 'integer', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1319 | 1319 | ); |
| 1320 | 1320 | |
| 1321 | 1321 | $query_params['author_exclude'] = array( |
| 1322 | | 'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), |
| | 1322 | 'description' => _l( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), |
| 1323 | 1323 | 'type' => 'array', |
| 1324 | 1324 | 'items' => array( |
| 1325 | 1325 | 'type' => 'integer', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1328 | 1328 | |
| 1329 | 1329 | $query_params['author_email'] = array( |
| 1330 | 1330 | 'default' => null, |
| 1331 | | 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), |
| | 1331 | 'description' => _l( 'Limit result set to that from a specific author email. Requires authorization.' ), |
| 1332 | 1332 | 'format' => 'email', |
| 1333 | 1333 | 'type' => 'string', |
| 1334 | 1334 | ); |
| 1335 | 1335 | |
| 1336 | 1336 | $query_params['before'] = array( |
| 1337 | | 'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ), |
| | 1337 | 'description' => _l( 'Limit response to comments published before a given ISO8601 compliant date.' ), |
| 1338 | 1338 | 'type' => 'string', |
| 1339 | 1339 | 'format' => 'date-time', |
| 1340 | 1340 | ); |
| 1341 | 1341 | |
| 1342 | 1342 | $query_params['exclude'] = array( |
| 1343 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| | 1343 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
| 1344 | 1344 | 'type' => 'array', |
| 1345 | 1345 | 'items' => array( |
| 1346 | 1346 | 'type' => 'integer', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1349 | 1349 | ); |
| 1350 | 1350 | |
| 1351 | 1351 | $query_params['include'] = array( |
| 1352 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| | 1352 | 'description' => _l( 'Limit result set to specific IDs.' ), |
| 1353 | 1353 | 'type' => 'array', |
| 1354 | 1354 | 'items' => array( |
| 1355 | 1355 | 'type' => 'integer', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1358 | 1358 | ); |
| 1359 | 1359 | |
| 1360 | 1360 | $query_params['offset'] = array( |
| 1361 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| | 1361 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
| 1362 | 1362 | 'type' => 'integer', |
| 1363 | 1363 | ); |
| 1364 | 1364 | |
| 1365 | 1365 | $query_params['order'] = array( |
| 1366 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| | 1366 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
| 1367 | 1367 | 'type' => 'string', |
| 1368 | 1368 | 'default' => 'desc', |
| 1369 | 1369 | 'enum' => array( |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1373 | 1373 | ); |
| 1374 | 1374 | |
| 1375 | 1375 | $query_params['orderby'] = array( |
| 1376 | | 'description' => __( 'Sort collection by object attribute.' ), |
| | 1376 | 'description' => _l( 'Sort collection by object attribute.' ), |
| 1377 | 1377 | 'type' => 'string', |
| 1378 | 1378 | 'default' => 'date_gmt', |
| 1379 | 1379 | 'enum' => array( |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1389 | 1389 | |
| 1390 | 1390 | $query_params['parent'] = array( |
| 1391 | 1391 | 'default' => array(), |
| 1392 | | 'description' => __( 'Limit result set to comments of specific parent IDs.' ), |
| | 1392 | 'description' => _l( 'Limit result set to comments of specific parent IDs.' ), |
| 1393 | 1393 | 'type' => 'array', |
| 1394 | 1394 | 'items' => array( |
| 1395 | 1395 | 'type' => 'integer', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1398 | 1398 | |
| 1399 | 1399 | $query_params['parent_exclude'] = array( |
| 1400 | 1400 | 'default' => array(), |
| 1401 | | 'description' => __( 'Ensure result set excludes specific parent IDs.' ), |
| | 1401 | 'description' => _l( 'Ensure result set excludes specific parent IDs.' ), |
| 1402 | 1402 | 'type' => 'array', |
| 1403 | 1403 | 'items' => array( |
| 1404 | 1404 | 'type' => 'integer', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1407 | 1407 | |
| 1408 | 1408 | $query_params['post'] = array( |
| 1409 | 1409 | 'default' => array(), |
| 1410 | | 'description' => __( 'Limit result set to comments assigned to specific post IDs.' ), |
| | 1410 | 'description' => _l( 'Limit result set to comments assigned to specific post IDs.' ), |
| 1411 | 1411 | 'type' => 'array', |
| 1412 | 1412 | 'items' => array( |
| 1413 | 1413 | 'type' => 'integer', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1416 | 1416 | |
| 1417 | 1417 | $query_params['status'] = array( |
| 1418 | 1418 | 'default' => 'approve', |
| 1419 | | 'description' => __( 'Limit result set to comments assigned a specific status. Requires authorization.' ), |
| | 1419 | 'description' => _l( 'Limit result set to comments assigned a specific status. Requires authorization.' ), |
| 1420 | 1420 | 'sanitize_callback' => 'sanitize_key', |
| 1421 | 1421 | 'type' => 'string', |
| 1422 | 1422 | 'validate_callback' => 'rest_validate_request_arg', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
| 1424 | 1424 | |
| 1425 | 1425 | $query_params['type'] = array( |
| 1426 | 1426 | 'default' => 'comment', |
| 1427 | | 'description' => __( 'Limit result set to comments assigned a specific type. Requires authorization.' ), |
| | 1427 | 'description' => _l( 'Limit result set to comments assigned a specific type. Requires authorization.' ), |
| 1428 | 1428 | 'sanitize_callback' => 'sanitize_key', |
| 1429 | 1429 | 'type' => 'string', |
| 1430 | 1430 | 'validate_callback' => 'rest_validate_request_arg', |
| 1431 | 1431 | ); |
| 1432 | 1432 | |
| 1433 | 1433 | $query_params['password'] = array( |
| 1434 | | 'description' => __( 'The password for the post if it is password protected.' ), |
| | 1434 | 'description' => _l( 'The password for the post if it is password protected.' ), |
| 1435 | 1435 | 'type' => 'string', |
| 1436 | 1436 | ); |
| 1437 | 1437 | |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
index 78c3567147..c93b2b53b3 100644
|
|
|
abstract class WP_REST_Controller { |
| 37 | 37 | */ |
| 38 | 38 | public function register_routes() { |
| 39 | 39 | /* translators: %s: register_routes() */ |
| 40 | | _doing_it_wrong( 'WP_REST_Controller::register_routes', sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), '4.7' ); |
| | 40 | _doing_it_wrong( 'WP_REST_Controller::register_routes', sprintf( _l( "Method '%s' must be overridden." ), __METHOD__ ), '4.7' ); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 50 | 50 | */ |
| 51 | 51 | public function get_items_permissions_check( $request ) { |
| 52 | 52 | /* translators: %s: method name */ |
| 53 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 53 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 63 | 63 | */ |
| 64 | 64 | public function get_items( $request ) { |
| 65 | 65 | /* translators: %s: method name */ |
| 66 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 66 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 76 | 76 | */ |
| 77 | 77 | public function get_item_permissions_check( $request ) { |
| 78 | 78 | /* translators: %s: method name */ |
| 79 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 79 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 89 | 89 | */ |
| 90 | 90 | public function get_item( $request ) { |
| 91 | 91 | /* translators: %s: method name */ |
| 92 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 92 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 102 | 102 | */ |
| 103 | 103 | public function create_item_permissions_check( $request ) { |
| 104 | 104 | /* translators: %s: method name */ |
| 105 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 105 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 115 | 115 | */ |
| 116 | 116 | public function create_item( $request ) { |
| 117 | 117 | /* translators: %s: method name */ |
| 118 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 118 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 128 | 128 | */ |
| 129 | 129 | public function update_item_permissions_check( $request ) { |
| 130 | 130 | /* translators: %s: method name */ |
| 131 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 131 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 141 | 141 | */ |
| 142 | 142 | public function update_item( $request ) { |
| 143 | 143 | /* translators: %s: method name */ |
| 144 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 144 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 154 | 154 | */ |
| 155 | 155 | public function delete_item_permissions_check( $request ) { |
| 156 | 156 | /* translators: %s: method name */ |
| 157 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 157 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 167 | 167 | */ |
| 168 | 168 | public function delete_item( $request ) { |
| 169 | 169 | /* translators: %s: method name */ |
| 170 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 170 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 180 | 180 | */ |
| 181 | 181 | protected function prepare_item_for_database( $request ) { |
| 182 | 182 | /* translators: %s: method name */ |
| 183 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 183 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 194 | 194 | */ |
| 195 | 195 | public function prepare_item_for_response( $item, $request ) { |
| 196 | 196 | /* translators: %s: method name */ |
| 197 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| | 197 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
| … |
… |
abstract class WP_REST_Controller { |
| 307 | 307 | return array( |
| 308 | 308 | 'context' => $this->get_context_param(), |
| 309 | 309 | 'page' => array( |
| 310 | | 'description' => __( 'Current page of the collection.' ), |
| | 310 | 'description' => _l( 'Current page of the collection.' ), |
| 311 | 311 | 'type' => 'integer', |
| 312 | 312 | 'default' => 1, |
| 313 | 313 | 'sanitize_callback' => 'absint', |
| … |
… |
abstract class WP_REST_Controller { |
| 315 | 315 | 'minimum' => 1, |
| 316 | 316 | ), |
| 317 | 317 | 'per_page' => array( |
| 318 | | 'description' => __( 'Maximum number of items to be returned in result set.' ), |
| | 318 | 'description' => _l( 'Maximum number of items to be returned in result set.' ), |
| 319 | 319 | 'type' => 'integer', |
| 320 | 320 | 'default' => 10, |
| 321 | 321 | 'minimum' => 1, |
| … |
… |
abstract class WP_REST_Controller { |
| 324 | 324 | 'validate_callback' => 'rest_validate_request_arg', |
| 325 | 325 | ), |
| 326 | 326 | 'search' => array( |
| 327 | | 'description' => __( 'Limit results to those matching a string.' ), |
| | 327 | 'description' => _l( 'Limit results to those matching a string.' ), |
| 328 | 328 | 'type' => 'string', |
| 329 | 329 | 'sanitize_callback' => 'sanitize_text_field', |
| 330 | 330 | 'validate_callback' => 'rest_validate_request_arg', |
| … |
… |
abstract class WP_REST_Controller { |
| 344 | 344 | */ |
| 345 | 345 | public function get_context_param( $args = array() ) { |
| 346 | 346 | $param_details = array( |
| 347 | | 'description' => __( 'Scope under which the request is made; determines fields present in response.' ), |
| | 347 | 'description' => _l( 'Scope under which the request is made; determines fields present in response.' ), |
| 348 | 348 | 'type' => 'string', |
| 349 | 349 | 'sanitize_callback' => 'sanitize_key', |
| 350 | 350 | 'validate_callback' => 'rest_validate_request_arg', |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php
index 369cf3c757..27afb7c703 100644
|
|
|
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
| 48 | 48 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<status>[\w-]+)', array( |
| 49 | 49 | 'args' => array( |
| 50 | 50 | 'status' => array( |
| 51 | | 'description' => __( 'An alphanumeric identifier for the status.' ), |
| | 51 | 'description' => _l( 'An alphanumeric identifier for the status.' ), |
| 52 | 52 | 'type' => 'string', |
| 53 | 53 | ), |
| 54 | 54 | ), |
| … |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
| 81 | 81 | return true; |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | | return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 84 | return new WP_Error( 'rest_cannot_view', _l( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | return true; |
| … |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
| 126 | 126 | $status = get_post_status_object( $request['status'] ); |
| 127 | 127 | |
| 128 | 128 | if ( empty( $status ) ) { |
| 129 | | return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); |
| | 129 | return new WP_Error( 'rest_status_invalid', _l( 'Invalid status.' ), array( 'status' => 404 ) ); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $check = $this->check_read_permission( $status ); |
| 133 | 133 | |
| 134 | 134 | if ( ! $check ) { |
| 135 | | return new WP_Error( 'rest_cannot_read_status', __( 'Cannot view status.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 135 | return new WP_Error( 'rest_cannot_read_status', _l( 'Cannot view status.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | return true; |
| … |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
| 176 | 176 | $obj = get_post_status_object( $request['status'] ); |
| 177 | 177 | |
| 178 | 178 | if ( empty( $obj ) ) { |
| 179 | | return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); |
| | 179 | return new WP_Error( 'rest_status_invalid', _l( 'Invalid status.' ), array( 'status' => 404 ) ); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $data = $this->prepare_item_for_response( $obj, $request ); |
| … |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
| 245 | 245 | 'type' => 'object', |
| 246 | 246 | 'properties' => array( |
| 247 | 247 | 'name' => array( |
| 248 | | 'description' => __( 'The title for the status.' ), |
| | 248 | 'description' => _l( 'The title for the status.' ), |
| 249 | 249 | 'type' => 'string', |
| 250 | 250 | 'context' => array( 'embed', 'view', 'edit' ), |
| 251 | 251 | 'readonly' => true, |
| 252 | 252 | ), |
| 253 | 253 | 'private' => array( |
| 254 | | 'description' => __( 'Whether posts with this status should be private.' ), |
| | 254 | 'description' => _l( 'Whether posts with this status should be private.' ), |
| 255 | 255 | 'type' => 'boolean', |
| 256 | 256 | 'context' => array( 'edit' ), |
| 257 | 257 | 'readonly' => true, |
| 258 | 258 | ), |
| 259 | 259 | 'protected' => array( |
| 260 | | 'description' => __( 'Whether posts with this status should be protected.' ), |
| | 260 | 'description' => _l( 'Whether posts with this status should be protected.' ), |
| 261 | 261 | 'type' => 'boolean', |
| 262 | 262 | 'context' => array( 'edit' ), |
| 263 | 263 | 'readonly' => true, |
| 264 | 264 | ), |
| 265 | 265 | 'public' => array( |
| 266 | | 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ), |
| | 266 | 'description' => _l( 'Whether posts of this status should be shown in the front end of the site.' ), |
| 267 | 267 | 'type' => 'boolean', |
| 268 | 268 | 'context' => array( 'view', 'edit' ), |
| 269 | 269 | 'readonly' => true, |
| 270 | 270 | ), |
| 271 | 271 | 'queryable' => array( |
| 272 | | 'description' => __( 'Whether posts with this status should be publicly-queryable.' ), |
| | 272 | 'description' => _l( 'Whether posts with this status should be publicly-queryable.' ), |
| 273 | 273 | 'type' => 'boolean', |
| 274 | 274 | 'context' => array( 'view', 'edit' ), |
| 275 | 275 | 'readonly' => true, |
| 276 | 276 | ), |
| 277 | 277 | 'show_in_list' => array( |
| 278 | | 'description' => __( 'Whether to include posts in the edit listing for their post type.' ), |
| | 278 | 'description' => _l( 'Whether to include posts in the edit listing for their post type.' ), |
| 279 | 279 | 'type' => 'boolean', |
| 280 | 280 | 'context' => array( 'edit' ), |
| 281 | 281 | 'readonly' => true, |
| 282 | 282 | ), |
| 283 | 283 | 'slug' => array( |
| 284 | | 'description' => __( 'An alphanumeric identifier for the status.' ), |
| | 284 | 'description' => _l( 'An alphanumeric identifier for the status.' ), |
| 285 | 285 | 'type' => 'string', |
| 286 | 286 | 'context' => array( 'embed', 'view', 'edit' ), |
| 287 | 287 | 'readonly' => true, |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
index c4571d9721..6840fd1de7 100644
|
|
|
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
| 48 | 48 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<type>[\w-]+)', array( |
| 49 | 49 | 'args' => array( |
| 50 | 50 | 'type' => array( |
| 51 | | 'description' => __( 'An alphanumeric identifier for the post type.' ), |
| | 51 | 'description' => _l( 'An alphanumeric identifier for the post type.' ), |
| 52 | 52 | 'type' => 'string', |
| 53 | 53 | ), |
| 54 | 54 | ), |
| … |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | | return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 82 | return new WP_Error( 'rest_cannot_view', _l( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | return true; |
| … |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
| 120 | 120 | $obj = get_post_type_object( $request['type'] ); |
| 121 | 121 | |
| 122 | 122 | if ( empty( $obj ) ) { |
| 123 | | return new WP_Error( 'rest_type_invalid', __( 'Invalid post type.' ), array( 'status' => 404 ) ); |
| | 123 | return new WP_Error( 'rest_type_invalid', _l( 'Invalid post type.' ), array( 'status' => 404 ) ); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if ( empty( $obj->show_in_rest ) ) { |
| 127 | | return new WP_Error( 'rest_cannot_read_type', __( 'Cannot view post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 127 | return new WP_Error( 'rest_cannot_read_type', _l( 'Cannot view post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if ( 'edit' === $request['context'] && ! current_user_can( $obj->cap->edit_posts ) ) { |
| 131 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 131 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | $data = $this->prepare_item_for_response( $obj, $request ); |
| … |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
| 206 | 206 | 'type' => 'object', |
| 207 | 207 | 'properties' => array( |
| 208 | 208 | 'capabilities' => array( |
| 209 | | 'description' => __( 'All capabilities used by the post type.' ), |
| | 209 | 'description' => _l( 'All capabilities used by the post type.' ), |
| 210 | 210 | 'type' => 'object', |
| 211 | 211 | 'context' => array( 'edit' ), |
| 212 | 212 | 'readonly' => true, |
| 213 | 213 | ), |
| 214 | 214 | 'description' => array( |
| 215 | | 'description' => __( 'A human-readable description of the post type.' ), |
| | 215 | 'description' => _l( 'A human-readable description of the post type.' ), |
| 216 | 216 | 'type' => 'string', |
| 217 | 217 | 'context' => array( 'view', 'edit' ), |
| 218 | 218 | 'readonly' => true, |
| 219 | 219 | ), |
| 220 | 220 | 'hierarchical' => array( |
| 221 | | 'description' => __( 'Whether or not the post type should have children.' ), |
| | 221 | 'description' => _l( 'Whether or not the post type should have children.' ), |
| 222 | 222 | 'type' => 'boolean', |
| 223 | 223 | 'context' => array( 'view', 'edit' ), |
| 224 | 224 | 'readonly' => true, |
| 225 | 225 | ), |
| 226 | 226 | 'labels' => array( |
| 227 | | 'description' => __( 'Human-readable labels for the post type for various contexts.' ), |
| | 227 | 'description' => _l( 'Human-readable labels for the post type for various contexts.' ), |
| 228 | 228 | 'type' => 'object', |
| 229 | 229 | 'context' => array( 'edit' ), |
| 230 | 230 | 'readonly' => true, |
| 231 | 231 | ), |
| 232 | 232 | 'name' => array( |
| 233 | | 'description' => __( 'The title for the post type.' ), |
| | 233 | 'description' => _l( 'The title for the post type.' ), |
| 234 | 234 | 'type' => 'string', |
| 235 | 235 | 'context' => array( 'view', 'edit', 'embed' ), |
| 236 | 236 | 'readonly' => true, |
| 237 | 237 | ), |
| 238 | 238 | 'slug' => array( |
| 239 | | 'description' => __( 'An alphanumeric identifier for the post type.' ), |
| | 239 | 'description' => _l( 'An alphanumeric identifier for the post type.' ), |
| 240 | 240 | 'type' => 'string', |
| 241 | 241 | 'context' => array( 'view', 'edit', 'embed' ), |
| 242 | 242 | 'readonly' => true, |
| 243 | 243 | ), |
| 244 | 244 | 'supports' => array( |
| 245 | | 'description' => __( 'All features, supported by the post type.' ), |
| | 245 | 'description' => _l( 'All features, supported by the post type.' ), |
| 246 | 246 | 'type' => 'object', |
| 247 | 247 | 'context' => array( 'edit' ), |
| 248 | 248 | 'readonly' => true, |
| 249 | 249 | ), |
| 250 | 250 | 'taxonomies' => array( |
| 251 | | 'description' => __( 'Taxonomies associated with post type.' ), |
| | 251 | 'description' => _l( 'Taxonomies associated with post type.' ), |
| 252 | 252 | 'type' => 'array', |
| 253 | 253 | 'items' => array( |
| 254 | 254 | 'type' => 'string', |
| … |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
| 257 | 257 | 'readonly' => true, |
| 258 | 258 | ), |
| 259 | 259 | 'rest_base' => array( |
| 260 | | 'description' => __( 'REST base route for the post type.' ), |
| | 260 | 'description' => _l( 'REST base route for the post type.' ), |
| 261 | 261 | 'type' => 'string', |
| 262 | 262 | 'context' => array( 'view', 'edit', 'embed' ), |
| 263 | 263 | 'readonly' => true, |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 80027cfea8..4522ef4bf8 100644
|
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 79 | 79 | ); |
| 80 | 80 | if ( isset( $schema['properties']['password'] ) ) { |
| 81 | 81 | $get_item_args['password'] = array( |
| 82 | | 'description' => __( 'The password for the post if it is password protected.' ), |
| | 82 | 'description' => _l( 'The password for the post if it is password protected.' ), |
| 83 | 83 | 'type' => 'string', |
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
| 87 | 87 | 'args' => array( |
| 88 | 88 | 'id' => array( |
| 89 | | 'description' => __( 'Unique identifier for the object.' ), |
| | 89 | 'description' => _l( 'Unique identifier for the object.' ), |
| 90 | 90 | 'type' => 'integer', |
| 91 | 91 | ), |
| 92 | 92 | ), |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 110 | 110 | 'force' => array( |
| 111 | 111 | 'type' => 'boolean', |
| 112 | 112 | 'default' => false, |
| 113 | | 'description' => __( 'Whether to bypass trash and force deletion.' ), |
| | 113 | 'description' => _l( 'Whether to bypass trash and force deletion.' ), |
| 114 | 114 | ), |
| 115 | 115 | ), |
| 116 | 116 | ), |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 131 | 131 | $post_type = get_post_type_object( $this->post_type ); |
| 132 | 132 | |
| 133 | 133 | if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) { |
| 134 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 134 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | return true; |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 149 | 149 | |
| 150 | 150 | // Ensure a search string is set in case the orderby is set to 'relevance'. |
| 151 | 151 | if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) { |
| 152 | | return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); |
| | 152 | return new WP_Error( 'rest_no_search_term_defined', _l( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Ensure an include parameter is set in case the orderby is set to 'include'. |
| 156 | 156 | if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) { |
| 157 | | return new WP_Error( 'rest_orderby_include_missing_include', __( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) ); |
| | 157 | return new WP_Error( 'rest_orderby_include_missing_include', _l( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) ); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Retrieve the list of registered collection query parameters. |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 326 | 326 | $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] ); |
| 327 | 327 | |
| 328 | 328 | if ( $page > $max_pages && $total_posts > 0 ) { |
| 329 | | return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); |
| | 329 | return new WP_Error( 'rest_post_invalid_page_number', _l( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $response = rest_ensure_response( $posts ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 366 | 366 | * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. |
| 367 | 367 | */ |
| 368 | 368 | protected function get_post( $id ) { |
| 369 | | $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
| | 369 | $error = new WP_Error( 'rest_post_invalid_id', _l( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
| 370 | 370 | if ( (int) $id <= 0 ) { |
| 371 | 371 | return $error; |
| 372 | 372 | } |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | if ( 'edit' === $request['context'] && $post && ! $this->check_update_permission( $post ) ) { |
| 397 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 397 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | if ( $post && ! empty( $request['password'] ) ) { |
| 401 | 401 | // Check post password, and return error if invalid. |
| 402 | 402 | if ( ! hash_equals( $post->post_password, $request['password'] ) ) { |
| 403 | | return new WP_Error( 'rest_post_incorrect_password', __( 'Incorrect post password.' ), array( 'status' => 403 ) ); |
| | 403 | return new WP_Error( 'rest_post_incorrect_password', _l( 'Incorrect post password.' ), array( 'status' => 403 ) ); |
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | 406 | |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 482 | 482 | */ |
| 483 | 483 | public function create_item_permissions_check( $request ) { |
| 484 | 484 | if ( ! empty( $request['id'] ) ) { |
| 485 | | return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
| | 485 | return new WP_Error( 'rest_post_exists', _l( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | $post_type = get_post_type_object( $this->post_type ); |
| 489 | 489 | |
| 490 | 490 | if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
| 491 | | return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 491 | return new WP_Error( 'rest_cannot_edit_others', _l( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
| 495 | | return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 495 | return new WP_Error( 'rest_cannot_assign_sticky', _l( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | if ( ! current_user_can( $post_type->cap->create_posts ) ) { |
| 499 | | return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 499 | return new WP_Error( 'rest_cannot_create', _l( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | if ( ! $this->check_assign_terms_permission( $request ) ) { |
| 503 | | return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 503 | return new WP_Error( 'rest_cannot_assign_term', _l( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | return true; |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 516 | 516 | */ |
| 517 | 517 | public function create_item( $request ) { |
| 518 | 518 | if ( ! empty( $request['id'] ) ) { |
| 519 | | return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
| | 519 | return new WP_Error( 'rest_post_exists', _l( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | $prepared_post = $this->prepare_item_for_database( $request ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 626 | 626 | $post_type = get_post_type_object( $this->post_type ); |
| 627 | 627 | |
| 628 | 628 | if ( $post && ! $this->check_update_permission( $post ) ) { |
| 629 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 629 | return new WP_Error( 'rest_cannot_edit', _l( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
| 633 | | return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 633 | return new WP_Error( 'rest_cannot_edit_others', _l( 'Sorry, you are not allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
| 637 | | return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 637 | return new WP_Error( 'rest_cannot_assign_sticky', _l( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | if ( ! $this->check_assign_terms_permission( $request ) ) { |
| 641 | | return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 641 | return new WP_Error( 'rest_cannot_assign_term', _l( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | return true; |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | if ( $post && ! $this->check_delete_permission( $post ) ) { |
| 749 | | return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 749 | return new WP_Error( 'rest_cannot_delete', _l( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | return true; |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 790 | 790 | $supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post ); |
| 791 | 791 | |
| 792 | 792 | if ( ! $this->check_delete_permission( $post ) ) { |
| 793 | | return new WP_Error( 'rest_user_cannot_delete_post', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 793 | return new WP_Error( 'rest_user_cannot_delete_post', _l( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | $request->set_param( 'context', 'edit' ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 806 | 806 | // If we don't support trashing for this type, error out. |
| 807 | 807 | if ( ! $supports_trash ) { |
| 808 | 808 | /* translators: %s: force=true */ |
| 809 | | return new WP_Error( 'rest_trash_not_supported', sprintf( __( "The post does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| | 809 | return new WP_Error( 'rest_trash_not_supported', sprintf( _l( "The post does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | // Otherwise, only trash if we haven't already. |
| 813 | 813 | if ( 'trash' === $post->post_status ) { |
| 814 | | return new WP_Error( 'rest_already_trashed', __( 'The post has already been deleted.' ), array( 'status' => 410 ) ); |
| | 814 | return new WP_Error( 'rest_already_trashed', _l( 'The post has already been deleted.' ), array( 'status' => 410 ) ); |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | // (Note that internally this falls through to `wp_delete_post` if |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | if ( ! $result ) { |
| 825 | | return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
| | 825 | return new WP_Error( 'rest_cannot_delete', _l( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | /** |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1014 | 1014 | $user_obj = get_userdata( $post_author ); |
| 1015 | 1015 | |
| 1016 | 1016 | if ( ! $user_obj ) { |
| 1017 | | return new WP_Error( 'rest_invalid_author', __( 'Invalid author ID.' ), array( 'status' => 400 ) ); |
| | 1017 | return new WP_Error( 'rest_invalid_author', _l( 'Invalid author ID.' ), array( 'status' => 400 ) ); |
| 1018 | 1018 | } |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1027 | 1027 | |
| 1028 | 1028 | if ( '' !== $request['password'] ) { |
| 1029 | 1029 | if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { |
| 1030 | | return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) ); |
| | 1030 | return new WP_Error( 'rest_invalid_field', _l( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) ); |
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) { |
| 1034 | | return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) ); |
| | 1034 | return new WP_Error( 'rest_invalid_field', _l( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) ); |
| 1035 | 1035 | } |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { |
| 1040 | 1040 | if ( ! empty( $prepared_post->ID ) && post_password_required( $prepared_post->ID ) ) { |
| 1041 | | return new WP_Error( 'rest_invalid_field', __( 'A password protected post can not be set to sticky.' ), array( 'status' => 400 ) ); |
| | 1041 | return new WP_Error( 'rest_invalid_field', _l( 'A password protected post can not be set to sticky.' ), array( 'status' => 400 ) ); |
| 1042 | 1042 | } |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1049 | 1049 | } else { |
| 1050 | 1050 | $parent = get_post( (int) $request['parent'] ); |
| 1051 | 1051 | if ( empty( $parent ) ) { |
| 1052 | | return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) ); |
| | 1052 | return new WP_Error( 'rest_post_invalid_id', _l( 'Invalid post parent ID.' ), array( 'status' => 400 ) ); |
| 1053 | 1053 | } |
| 1054 | 1054 | $prepared_post->post_parent = (int) $parent->ID; |
| 1055 | 1055 | } |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1102 | 1102 | break; |
| 1103 | 1103 | case 'private': |
| 1104 | 1104 | if ( ! current_user_can( $post_type->cap->publish_posts ) ) { |
| 1105 | | return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create private posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 1105 | return new WP_Error( 'rest_cannot_publish', _l( 'Sorry, you are not allowed to create private posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 1106 | 1106 | } |
| 1107 | 1107 | break; |
| 1108 | 1108 | case 'publish': |
| 1109 | 1109 | case 'future': |
| 1110 | 1110 | if ( ! current_user_can( $post_type->cap->publish_posts ) ) { |
| 1111 | | return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to publish posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 1111 | return new WP_Error( 'rest_cannot_publish', _l( 'Sorry, you are not allowed to publish posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 1112 | 1112 | } |
| 1113 | 1113 | break; |
| 1114 | 1114 | default: |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1138 | 1138 | if ( $result ) { |
| 1139 | 1139 | return true; |
| 1140 | 1140 | } else { |
| 1141 | | return new WP_Error( 'rest_invalid_featured_media', __( 'Invalid featured media ID.' ), array( 'status' => 400 ) ); |
| | 1141 | return new WP_Error( 'rest_invalid_featured_media', _l( 'Invalid featured media ID.' ), array( 'status' => 400 ) ); |
| 1142 | 1142 | } |
| 1143 | 1143 | } else { |
| 1144 | 1144 | return delete_post_thumbnail( $post_id ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1691 | 1691 | // Base properties for every Post. |
| 1692 | 1692 | 'properties' => array( |
| 1693 | 1693 | 'date' => array( |
| 1694 | | 'description' => __( "The date the object was published, in the site's timezone." ), |
| | 1694 | 'description' => _l( "The date the object was published, in the site's timezone." ), |
| 1695 | 1695 | 'type' => 'string', |
| 1696 | 1696 | 'format' => 'date-time', |
| 1697 | 1697 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1698 | 1698 | ), |
| 1699 | 1699 | 'date_gmt' => array( |
| 1700 | | 'description' => __( 'The date the object was published, as GMT.' ), |
| | 1700 | 'description' => _l( 'The date the object was published, as GMT.' ), |
| 1701 | 1701 | 'type' => 'string', |
| 1702 | 1702 | 'format' => 'date-time', |
| 1703 | 1703 | 'context' => array( 'view', 'edit' ), |
| 1704 | 1704 | ), |
| 1705 | 1705 | 'guid' => array( |
| 1706 | | 'description' => __( 'The globally unique identifier for the object.' ), |
| | 1706 | 'description' => _l( 'The globally unique identifier for the object.' ), |
| 1707 | 1707 | 'type' => 'object', |
| 1708 | 1708 | 'context' => array( 'view', 'edit' ), |
| 1709 | 1709 | 'readonly' => true, |
| 1710 | 1710 | 'properties' => array( |
| 1711 | 1711 | 'raw' => array( |
| 1712 | | 'description' => __( 'GUID for the object, as it exists in the database.' ), |
| | 1712 | 'description' => _l( 'GUID for the object, as it exists in the database.' ), |
| 1713 | 1713 | 'type' => 'string', |
| 1714 | 1714 | 'context' => array( 'edit' ), |
| 1715 | 1715 | 'readonly' => true, |
| 1716 | 1716 | ), |
| 1717 | 1717 | 'rendered' => array( |
| 1718 | | 'description' => __( 'GUID for the object, transformed for display.' ), |
| | 1718 | 'description' => _l( 'GUID for the object, transformed for display.' ), |
| 1719 | 1719 | 'type' => 'string', |
| 1720 | 1720 | 'context' => array( 'view', 'edit' ), |
| 1721 | 1721 | 'readonly' => true, |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1723 | 1723 | ), |
| 1724 | 1724 | ), |
| 1725 | 1725 | 'id' => array( |
| 1726 | | 'description' => __( 'Unique identifier for the object.' ), |
| | 1726 | 'description' => _l( 'Unique identifier for the object.' ), |
| 1727 | 1727 | 'type' => 'integer', |
| 1728 | 1728 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1729 | 1729 | 'readonly' => true, |
| 1730 | 1730 | ), |
| 1731 | 1731 | 'link' => array( |
| 1732 | | 'description' => __( 'URL to the object.' ), |
| | 1732 | 'description' => _l( 'URL to the object.' ), |
| 1733 | 1733 | 'type' => 'string', |
| 1734 | 1734 | 'format' => 'uri', |
| 1735 | 1735 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1736 | 1736 | 'readonly' => true, |
| 1737 | 1737 | ), |
| 1738 | 1738 | 'modified' => array( |
| 1739 | | 'description' => __( "The date the object was last modified, in the site's timezone." ), |
| | 1739 | 'description' => _l( "The date the object was last modified, in the site's timezone." ), |
| 1740 | 1740 | 'type' => 'string', |
| 1741 | 1741 | 'format' => 'date-time', |
| 1742 | 1742 | 'context' => array( 'view', 'edit' ), |
| 1743 | 1743 | 'readonly' => true, |
| 1744 | 1744 | ), |
| 1745 | 1745 | 'modified_gmt' => array( |
| 1746 | | 'description' => __( 'The date the object was last modified, as GMT.' ), |
| | 1746 | 'description' => _l( 'The date the object was last modified, as GMT.' ), |
| 1747 | 1747 | 'type' => 'string', |
| 1748 | 1748 | 'format' => 'date-time', |
| 1749 | 1749 | 'context' => array( 'view', 'edit' ), |
| 1750 | 1750 | 'readonly' => true, |
| 1751 | 1751 | ), |
| 1752 | 1752 | 'slug' => array( |
| 1753 | | 'description' => __( 'An alphanumeric identifier for the object unique to its type.' ), |
| | 1753 | 'description' => _l( 'An alphanumeric identifier for the object unique to its type.' ), |
| 1754 | 1754 | 'type' => 'string', |
| 1755 | 1755 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1756 | 1756 | 'arg_options' => array( |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1758 | 1758 | ), |
| 1759 | 1759 | ), |
| 1760 | 1760 | 'status' => array( |
| 1761 | | 'description' => __( 'A named status for the object.' ), |
| | 1761 | 'description' => _l( 'A named status for the object.' ), |
| 1762 | 1762 | 'type' => 'string', |
| 1763 | 1763 | 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), |
| 1764 | 1764 | 'context' => array( 'view', 'edit' ), |
| 1765 | 1765 | ), |
| 1766 | 1766 | 'type' => array( |
| 1767 | | 'description' => __( 'Type of Post for the object.' ), |
| | 1767 | 'description' => _l( 'Type of Post for the object.' ), |
| 1768 | 1768 | 'type' => 'string', |
| 1769 | 1769 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1770 | 1770 | 'readonly' => true, |
| 1771 | 1771 | ), |
| 1772 | 1772 | 'password' => array( |
| 1773 | | 'description' => __( 'A password to protect access to the content and excerpt.' ), |
| | 1773 | 'description' => _l( 'A password to protect access to the content and excerpt.' ), |
| 1774 | 1774 | 'type' => 'string', |
| 1775 | 1775 | 'context' => array( 'edit' ), |
| 1776 | 1776 | ), |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1781 | 1781 | |
| 1782 | 1782 | if ( $post_type_obj->hierarchical ) { |
| 1783 | 1783 | $schema['properties']['parent'] = array( |
| 1784 | | 'description' => __( 'The ID for the parent of the object.' ), |
| | 1784 | 'description' => _l( 'The ID for the parent of the object.' ), |
| 1785 | 1785 | 'type' => 'integer', |
| 1786 | 1786 | 'context' => array( 'view', 'edit' ), |
| 1787 | 1787 | ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1841 | 1841 | |
| 1842 | 1842 | case 'title': |
| 1843 | 1843 | $schema['properties']['title'] = array( |
| 1844 | | 'description' => __( 'The title for the object.' ), |
| | 1844 | 'description' => _l( 'The title for the object.' ), |
| 1845 | 1845 | 'type' => 'object', |
| 1846 | 1846 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1847 | 1847 | 'arg_options' => array( |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1850 | 1850 | ), |
| 1851 | 1851 | 'properties' => array( |
| 1852 | 1852 | 'raw' => array( |
| 1853 | | 'description' => __( 'Title for the object, as it exists in the database.' ), |
| | 1853 | 'description' => _l( 'Title for the object, as it exists in the database.' ), |
| 1854 | 1854 | 'type' => 'string', |
| 1855 | 1855 | 'context' => array( 'edit' ), |
| 1856 | 1856 | ), |
| 1857 | 1857 | 'rendered' => array( |
| 1858 | | 'description' => __( 'HTML title for the object, transformed for display.' ), |
| | 1858 | 'description' => _l( 'HTML title for the object, transformed for display.' ), |
| 1859 | 1859 | 'type' => 'string', |
| 1860 | 1860 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1861 | 1861 | 'readonly' => true, |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1866 | 1866 | |
| 1867 | 1867 | case 'editor': |
| 1868 | 1868 | $schema['properties']['content'] = array( |
| 1869 | | 'description' => __( 'The content for the object.' ), |
| | 1869 | 'description' => _l( 'The content for the object.' ), |
| 1870 | 1870 | 'type' => 'object', |
| 1871 | 1871 | 'context' => array( 'view', 'edit' ), |
| 1872 | 1872 | 'arg_options' => array( |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1875 | 1875 | ), |
| 1876 | 1876 | 'properties' => array( |
| 1877 | 1877 | 'raw' => array( |
| 1878 | | 'description' => __( 'Content for the object, as it exists in the database.' ), |
| | 1878 | 'description' => _l( 'Content for the object, as it exists in the database.' ), |
| 1879 | 1879 | 'type' => 'string', |
| 1880 | 1880 | 'context' => array( 'edit' ), |
| 1881 | 1881 | ), |
| 1882 | 1882 | 'rendered' => array( |
| 1883 | | 'description' => __( 'HTML content for the object, transformed for display.' ), |
| | 1883 | 'description' => _l( 'HTML content for the object, transformed for display.' ), |
| 1884 | 1884 | 'type' => 'string', |
| 1885 | 1885 | 'context' => array( 'view', 'edit' ), |
| 1886 | 1886 | 'readonly' => true, |
| 1887 | 1887 | ), |
| 1888 | 1888 | 'protected' => array( |
| 1889 | | 'description' => __( 'Whether the content is protected with a password.' ), |
| | 1889 | 'description' => _l( 'Whether the content is protected with a password.' ), |
| 1890 | 1890 | 'type' => 'boolean', |
| 1891 | 1891 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1892 | 1892 | 'readonly' => true, |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1897 | 1897 | |
| 1898 | 1898 | case 'author': |
| 1899 | 1899 | $schema['properties']['author'] = array( |
| 1900 | | 'description' => __( 'The ID for the author of the object.' ), |
| | 1900 | 'description' => _l( 'The ID for the author of the object.' ), |
| 1901 | 1901 | 'type' => 'integer', |
| 1902 | 1902 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1903 | 1903 | ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1905 | 1905 | |
| 1906 | 1906 | case 'excerpt': |
| 1907 | 1907 | $schema['properties']['excerpt'] = array( |
| 1908 | | 'description' => __( 'The excerpt for the object.' ), |
| | 1908 | 'description' => _l( 'The excerpt for the object.' ), |
| 1909 | 1909 | 'type' => 'object', |
| 1910 | 1910 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1911 | 1911 | 'arg_options' => array( |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1914 | 1914 | ), |
| 1915 | 1915 | 'properties' => array( |
| 1916 | 1916 | 'raw' => array( |
| 1917 | | 'description' => __( 'Excerpt for the object, as it exists in the database.' ), |
| | 1917 | 'description' => _l( 'Excerpt for the object, as it exists in the database.' ), |
| 1918 | 1918 | 'type' => 'string', |
| 1919 | 1919 | 'context' => array( 'edit' ), |
| 1920 | 1920 | ), |
| 1921 | 1921 | 'rendered' => array( |
| 1922 | | 'description' => __( 'HTML excerpt for the object, transformed for display.' ), |
| | 1922 | 'description' => _l( 'HTML excerpt for the object, transformed for display.' ), |
| 1923 | 1923 | 'type' => 'string', |
| 1924 | 1924 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1925 | 1925 | 'readonly' => true, |
| 1926 | 1926 | ), |
| 1927 | 1927 | 'protected' => array( |
| 1928 | | 'description' => __( 'Whether the excerpt is protected with a password.' ), |
| | 1928 | 'description' => _l( 'Whether the excerpt is protected with a password.' ), |
| 1929 | 1929 | 'type' => 'boolean', |
| 1930 | 1930 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1931 | 1931 | 'readonly' => true, |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1936 | 1936 | |
| 1937 | 1937 | case 'thumbnail': |
| 1938 | 1938 | $schema['properties']['featured_media'] = array( |
| 1939 | | 'description' => __( 'The ID of the featured media for the object.' ), |
| | 1939 | 'description' => _l( 'The ID of the featured media for the object.' ), |
| 1940 | 1940 | 'type' => 'integer', |
| 1941 | 1941 | 'context' => array( 'view', 'edit', 'embed' ), |
| 1942 | 1942 | ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1944 | 1944 | |
| 1945 | 1945 | case 'comments': |
| 1946 | 1946 | $schema['properties']['comment_status'] = array( |
| 1947 | | 'description' => __( 'Whether or not comments are open on the object.' ), |
| | 1947 | 'description' => _l( 'Whether or not comments are open on the object.' ), |
| 1948 | 1948 | 'type' => 'string', |
| 1949 | 1949 | 'enum' => array( 'open', 'closed' ), |
| 1950 | 1950 | 'context' => array( 'view', 'edit' ), |
| 1951 | 1951 | ); |
| 1952 | 1952 | $schema['properties']['ping_status'] = array( |
| 1953 | | 'description' => __( 'Whether or not the object can be pinged.' ), |
| | 1953 | 'description' => _l( 'Whether or not the object can be pinged.' ), |
| 1954 | 1954 | 'type' => 'string', |
| 1955 | 1955 | 'enum' => array( 'open', 'closed' ), |
| 1956 | 1956 | 'context' => array( 'view', 'edit' ), |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1959 | 1959 | |
| 1960 | 1960 | case 'page-attributes': |
| 1961 | 1961 | $schema['properties']['menu_order'] = array( |
| 1962 | | 'description' => __( 'The order of the object in relation to other object of its type.' ), |
| | 1962 | 'description' => _l( 'The order of the object in relation to other object of its type.' ), |
| 1963 | 1963 | 'type' => 'integer', |
| 1964 | 1964 | 'context' => array( 'view', 'edit' ), |
| 1965 | 1965 | ); |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1970 | 1970 | $formats = array_values( get_post_format_slugs() ); |
| 1971 | 1971 | |
| 1972 | 1972 | $schema['properties']['format'] = array( |
| 1973 | | 'description' => __( 'The format for the object.' ), |
| | 1973 | 'description' => _l( 'The format for the object.' ), |
| 1974 | 1974 | 'type' => 'string', |
| 1975 | 1975 | 'enum' => $formats, |
| 1976 | 1976 | 'context' => array( 'view', 'edit' ), |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 1986 | 1986 | |
| 1987 | 1987 | if ( 'post' === $this->post_type ) { |
| 1988 | 1988 | $schema['properties']['sticky'] = array( |
| 1989 | | 'description' => __( 'Whether or not the object should be treated as sticky.' ), |
| | 1989 | 'description' => _l( 'Whether or not the object should be treated as sticky.' ), |
| 1990 | 1990 | 'type' => 'boolean', |
| 1991 | 1991 | 'context' => array( 'view', 'edit' ), |
| 1992 | 1992 | ); |
| 1993 | 1993 | } |
| 1994 | 1994 | |
| 1995 | 1995 | $schema['properties']['template'] = array( |
| 1996 | | 'description' => __( 'The theme file to use to display the object.' ), |
| | 1996 | 'description' => _l( 'The theme file to use to display the object.' ), |
| 1997 | 1997 | 'type' => 'string', |
| 1998 | 1998 | 'enum' => array_merge( array_keys( wp_get_theme()->get_page_templates( null, $this->post_type ) ), array( '' ) ), |
| 1999 | 1999 | 'context' => array( 'view', 'edit' ), |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2004 | 2004 | $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; |
| 2005 | 2005 | $schema['properties'][ $base ] = array( |
| 2006 | 2006 | /* translators: %s: taxonomy name */ |
| 2007 | | 'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ), |
| | 2007 | 'description' => sprintf( _l( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ), |
| 2008 | 2008 | 'type' => 'array', |
| 2009 | 2009 | 'items' => array( |
| 2010 | 2010 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2029 | 2029 | $query_params['context']['default'] = 'view'; |
| 2030 | 2030 | |
| 2031 | 2031 | $query_params['after'] = array( |
| 2032 | | 'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ), |
| | 2032 | 'description' => _l( 'Limit response to posts published after a given ISO8601 compliant date.' ), |
| 2033 | 2033 | 'type' => 'string', |
| 2034 | 2034 | 'format' => 'date-time', |
| 2035 | 2035 | ); |
| 2036 | 2036 | |
| 2037 | 2037 | if ( post_type_supports( $this->post_type, 'author' ) ) { |
| 2038 | 2038 | $query_params['author'] = array( |
| 2039 | | 'description' => __( 'Limit result set to posts assigned to specific authors.' ), |
| | 2039 | 'description' => _l( 'Limit result set to posts assigned to specific authors.' ), |
| 2040 | 2040 | 'type' => 'array', |
| 2041 | 2041 | 'items' => array( |
| 2042 | 2042 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2044 | 2044 | 'default' => array(), |
| 2045 | 2045 | ); |
| 2046 | 2046 | $query_params['author_exclude'] = array( |
| 2047 | | 'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ), |
| | 2047 | 'description' => _l( 'Ensure result set excludes posts assigned to specific authors.' ), |
| 2048 | 2048 | 'type' => 'array', |
| 2049 | 2049 | 'items' => array( |
| 2050 | 2050 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2054 | 2054 | } |
| 2055 | 2055 | |
| 2056 | 2056 | $query_params['before'] = array( |
| 2057 | | 'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ), |
| | 2057 | 'description' => _l( 'Limit response to posts published before a given ISO8601 compliant date.' ), |
| 2058 | 2058 | 'type' => 'string', |
| 2059 | 2059 | 'format' => 'date-time', |
| 2060 | 2060 | ); |
| 2061 | 2061 | |
| 2062 | 2062 | $query_params['exclude'] = array( |
| 2063 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| | 2063 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
| 2064 | 2064 | 'type' => 'array', |
| 2065 | 2065 | 'items' => array( |
| 2066 | 2066 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2069 | 2069 | ); |
| 2070 | 2070 | |
| 2071 | 2071 | $query_params['include'] = array( |
| 2072 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| | 2072 | 'description' => _l( 'Limit result set to specific IDs.' ), |
| 2073 | 2073 | 'type' => 'array', |
| 2074 | 2074 | 'items' => array( |
| 2075 | 2075 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2079 | 2079 | |
| 2080 | 2080 | if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) { |
| 2081 | 2081 | $query_params['menu_order'] = array( |
| 2082 | | 'description' => __( 'Limit result set to posts with a specific menu_order value.' ), |
| | 2082 | 'description' => _l( 'Limit result set to posts with a specific menu_order value.' ), |
| 2083 | 2083 | 'type' => 'integer', |
| 2084 | 2084 | ); |
| 2085 | 2085 | } |
| 2086 | 2086 | |
| 2087 | 2087 | $query_params['offset'] = array( |
| 2088 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| | 2088 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
| 2089 | 2089 | 'type' => 'integer', |
| 2090 | 2090 | ); |
| 2091 | 2091 | |
| 2092 | 2092 | $query_params['order'] = array( |
| 2093 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| | 2093 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
| 2094 | 2094 | 'type' => 'string', |
| 2095 | 2095 | 'default' => 'desc', |
| 2096 | 2096 | 'enum' => array( 'asc', 'desc' ), |
| 2097 | 2097 | ); |
| 2098 | 2098 | |
| 2099 | 2099 | $query_params['orderby'] = array( |
| 2100 | | 'description' => __( 'Sort collection by object attribute.' ), |
| | 2100 | 'description' => _l( 'Sort collection by object attribute.' ), |
| 2101 | 2101 | 'type' => 'string', |
| 2102 | 2102 | 'default' => 'date', |
| 2103 | 2103 | 'enum' => array( |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2121 | 2121 | |
| 2122 | 2122 | if ( $post_type->hierarchical || 'attachment' === $this->post_type ) { |
| 2123 | 2123 | $query_params['parent'] = array( |
| 2124 | | 'description' => __( 'Limit result set to items with particular parent IDs.' ), |
| | 2124 | 'description' => _l( 'Limit result set to items with particular parent IDs.' ), |
| 2125 | 2125 | 'type' => 'array', |
| 2126 | 2126 | 'items' => array( |
| 2127 | 2127 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2129 | 2129 | 'default' => array(), |
| 2130 | 2130 | ); |
| 2131 | 2131 | $query_params['parent_exclude'] = array( |
| 2132 | | 'description' => __( 'Limit result set to all items except those of a particular parent ID.' ), |
| | 2132 | 'description' => _l( 'Limit result set to all items except those of a particular parent ID.' ), |
| 2133 | 2133 | 'type' => 'array', |
| 2134 | 2134 | 'items' => array( |
| 2135 | 2135 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | $query_params['slug'] = array( |
| 2142 | | 'description' => __( 'Limit result set to posts with one or more specific slugs.' ), |
| | 2142 | 'description' => _l( 'Limit result set to posts with one or more specific slugs.' ), |
| 2143 | 2143 | 'type' => 'array', |
| 2144 | 2144 | 'items' => array( |
| 2145 | 2145 | 'type' => 'string', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2149 | 2149 | |
| 2150 | 2150 | $query_params['status'] = array( |
| 2151 | 2151 | 'default' => 'publish', |
| 2152 | | 'description' => __( 'Limit result set to posts assigned one or more statuses.' ), |
| | 2152 | 'description' => _l( 'Limit result set to posts assigned one or more statuses.' ), |
| 2153 | 2153 | 'type' => 'array', |
| 2154 | 2154 | 'items' => array( |
| 2155 | 2155 | 'enum' => array_merge( array_keys( get_post_stati() ), array( 'any' ) ), |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2165 | 2165 | |
| 2166 | 2166 | $query_params[ $base ] = array( |
| 2167 | 2167 | /* translators: %s: taxonomy name */ |
| 2168 | | 'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), |
| | 2168 | 'description' => sprintf( _l( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), |
| 2169 | 2169 | 'type' => 'array', |
| 2170 | 2170 | 'items' => array( |
| 2171 | 2171 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2175 | 2175 | |
| 2176 | 2176 | $query_params[ $base . '_exclude' ] = array( |
| 2177 | 2177 | /* translators: %s: taxonomy name */ |
| 2178 | | 'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ), |
| | 2178 | 'description' => sprintf( _l( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ), |
| 2179 | 2179 | 'type' => 'array', |
| 2180 | 2180 | 'items' => array( |
| 2181 | 2181 | 'type' => 'integer', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2186 | 2186 | |
| 2187 | 2187 | if ( 'post' === $this->post_type ) { |
| 2188 | 2188 | $query_params['sticky'] = array( |
| 2189 | | 'description' => __( 'Limit result set to items that are sticky.' ), |
| | 2189 | 'description' => _l( 'Limit result set to items that are sticky.' ), |
| 2190 | 2190 | 'type' => 'boolean', |
| 2191 | 2191 | ); |
| 2192 | 2192 | } |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
| 2240 | 2240 | return $result; |
| 2241 | 2241 | } |
| 2242 | 2242 | } else { |
| 2243 | | return new WP_Error( 'rest_forbidden_status', __( 'Status is forbidden.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 2243 | return new WP_Error( 'rest_forbidden_status', _l( 'Status is forbidden.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 2244 | 2244 | } |
| 2245 | 2245 | } |
| 2246 | 2246 | |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
index a648fa2de5..8cc7d94ab9 100644
|
|
|
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 68 | 68 | register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array( |
| 69 | 69 | 'args' => array( |
| 70 | 70 | 'parent' => array( |
| 71 | | 'description' => __( 'The ID for the parent of the object.' ), |
| | 71 | 'description' => _l( 'The ID for the parent of the object.' ), |
| 72 | 72 | 'type' => 'integer', |
| 73 | 73 | ), |
| 74 | 74 | ), |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 84 | 84 | register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
| 85 | 85 | 'args' => array( |
| 86 | 86 | 'parent' => array( |
| 87 | | 'description' => __( 'The ID for the parent of the object.' ), |
| | 87 | 'description' => _l( 'The ID for the parent of the object.' ), |
| 88 | 88 | 'type' => 'integer', |
| 89 | 89 | ), |
| 90 | 90 | 'id' => array( |
| 91 | | 'description' => __( 'Unique identifier for the object.' ), |
| | 91 | 'description' => _l( 'Unique identifier for the object.' ), |
| 92 | 92 | 'type' => 'integer', |
| 93 | 93 | ), |
| 94 | 94 | ), |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 108 | 108 | 'force' => array( |
| 109 | 109 | 'type' => 'boolean', |
| 110 | 110 | 'default' => false, |
| 111 | | 'description' => __( 'Required to be true, as revisions do not support trashing.' ), |
| | 111 | 'description' => _l( 'Required to be true, as revisions do not support trashing.' ), |
| 112 | 112 | ), |
| 113 | 113 | ), |
| 114 | 114 | ), |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 126 | 126 | * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. |
| 127 | 127 | */ |
| 128 | 128 | protected function get_parent( $parent ) { |
| 129 | | $error = new WP_Error( 'rest_post_invalid_parent', __( 'Invalid post parent ID.' ), array( 'status' => 404 ) ); |
| | 129 | $error = new WP_Error( 'rest_post_invalid_parent', _l( 'Invalid post parent ID.' ), array( 'status' => 404 ) ); |
| 130 | 130 | if ( (int) $parent <= 0 ) { |
| 131 | 131 | return $error; |
| 132 | 132 | } |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 155 | 155 | |
| 156 | 156 | $parent_post_type_obj = get_post_type_object( $parent->post_type ); |
| 157 | 157 | if ( ! current_user_can( $parent_post_type_obj->cap->edit_post, $parent->ID ) ) { |
| 158 | | return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to view revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 158 | return new WP_Error( 'rest_cannot_read', _l( 'Sorry, you are not allowed to view revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | return true; |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 170 | 170 | * @return WP_Post|WP_Error Revision post object if ID is valid, WP_Error otherwise. |
| 171 | 171 | */ |
| 172 | 172 | protected function get_revision( $id ) { |
| 173 | | $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid revision ID.' ), array( 'status' => 404 ) ); |
| | 173 | $error = new WP_Error( 'rest_post_invalid_id', _l( 'Invalid revision ID.' ), array( 'status' => 404 ) ); |
| 174 | 174 | if ( (int) $id <= 0 ) { |
| 175 | 175 | return $error; |
| 176 | 176 | } |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 289 | 289 | // We don't support trashing for revisions. |
| 290 | 290 | if ( ! $force ) { |
| 291 | 291 | /* translators: %s: force=true */ |
| 292 | | return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| | 292 | return new WP_Error( 'rest_trash_not_supported', sprintf( _l( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | $previous = $this->prepare_item_for_response( $revision, $request ); |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 309 | 309 | do_action( 'rest_delete_revision', $result, $request ); |
| 310 | 310 | |
| 311 | 311 | if ( ! $result ) { |
| 312 | | return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
| | 312 | return new WP_Error( 'rest_cannot_delete', _l( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | $response = new WP_REST_Response(); |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
| 458 | 458 | // Base properties for every Revision. |
| 459 | 459 | 'properties' => array( |
| 460 | 460 | 'author' => array( |
| 461 | | 'description' => __( 'The ID for the author of the object.' ), |
| | 461 | 'description' => _l( 'The ID for the author of the object.' ), |
| 462 | 462 | 'type' => 'integer', |
| 463 | 463 | 'context' => array( 'view', 'edit', 'embed' ), |
| 464 | 464 | ), |
| 465 | 465 | 'date' => array( |
| 466 | | 'description' => __( "The date the object was published, in the site's timezone." ), |
| | 466 | 'description' => _l( "The date the object was published, in the site's timezone." ), |
| 467 | 467 | 'type' => 'string', |
| 468 | 468 | 'format' => 'date-time', |
| 469 | 469 | 'context' => array( 'view', 'edit', 'embed' ), |
| 470 | 470 | ), |
| 471 | 471 | 'date_gmt' => array( |
| 472 | | 'description' => __( 'The date the object was published, as GMT.' ), |
| | 472 | 'description' => _l( 'The date the object was published, as GMT.' ), |
| 473 | 473 | 'type' => 'string', |
| 474 | 474 | 'format' => 'date-time', |
| 475 | 475 | 'context' => array( 'view', 'edit' ), |
| 476 | 476 | ), |
| 477 | 477 | 'guid' => array( |
| 478 | | 'description' => __( 'GUID for the object, as it exists in the database.' ), |
| | 478 | 'description' => _l( 'GUID for the object, as it exists in the database.' ), |
| 479 | 479 | 'type' => 'string', |
| 480 | 480 | 'context' => array( 'view', 'edit' ), |
| 481 | 481 | ), |
| 482 | 482 | 'id' => array( |
| 483 | | 'description' => __( 'Unique identifier for the object.' ), |
| | 483 | 'description' => _l( 'Unique identifier for the object.' ), |
| 484 | 484 | 'type' => 'integer', |
| 485 | 485 | 'context' => array( 'view', 'edit', 'embed' ), |
| 486 | 486 | ), |
| 487 | 487 | 'modified' => array( |
| 488 | | 'description' => __( "The date the object was last modified, in the site's timezone." ), |
| | 488 | 'description' => _l( "The date the object was last modified, in the site's timezone." ), |
| 489 | 489 | 'type' => 'string', |
| 490 | 490 | 'format' => 'date-time', |
| 491 | 491 | 'context' => array( 'view', 'edit' ), |
| 492 | 492 | ), |
| 493 | 493 | 'modified_gmt' => array( |
| 494 | | 'description' => __( 'The date the object was last modified, as GMT.' ), |
| | 494 | 'description' => _l( 'The date the object was last modified, as GMT.' ), |
| 495 | 495 | 'type' => 'string', |
| 496 | 496 | 'format' => 'date-time', |
| 497 | 497 | 'context' => array( 'view', 'edit' ), |
| 498 | 498 | ), |
| 499 | 499 | 'parent' => array( |
| 500 | | 'description' => __( 'The ID for the parent of the object.' ), |
| | 500 | 'description' => _l( 'The ID for the parent of the object.' ), |
| 501 | 501 | 'type' => 'integer', |
| 502 | 502 | 'context' => array( 'view', 'edit', 'embed' ), |
| 503 | 503 | ), |
| 504 | 504 | 'slug' => array( |
| 505 | | 'description' => __( 'An alphanumeric identifier for the object unique to its type.' ), |
| | 505 | 'description' => _l( 'An alphanumeric identifier for the object unique to its type.' ), |
| 506 | 506 | 'type' => 'string', |
| 507 | 507 | 'context' => array( 'view', 'edit', 'embed' ), |
| 508 | 508 | ), |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
index 17a01b8ba6..82bf524395 100644
|
|
|
class WP_REST_Settings_Controller extends WP_REST_Controller { |
| 194 | 194 | */ |
| 195 | 195 | if ( ! is_scalar( get_option( $args['option_name'], false ) ) ) { |
| 196 | 196 | return new WP_Error( |
| 197 | | 'rest_invalid_stored_value', sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) |
| | 197 | 'rest_invalid_stored_value', sprintf( _l( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) |
| 198 | 198 | ); |
| 199 | 199 | } |
| 200 | 200 | |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
index ea97135677..e3c8d99cd3 100644
|
|
|
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
| 48 | 48 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<taxonomy>[\w-]+)', array( |
| 49 | 49 | 'args' => array( |
| 50 | 50 | 'taxonomy' => array( |
| 51 | | 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), |
| | 51 | 'description' => _l( 'An alphanumeric identifier for the taxonomy.' ), |
| 52 | 52 | 'type' => 'string', |
| 53 | 53 | ), |
| 54 | 54 | ), |
| … |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
| 84 | 84 | return true; |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | | return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 87 | return new WP_Error( 'rest_cannot_view', _l( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 88 | 88 | } |
| 89 | 89 | return true; |
| 90 | 90 | } |
| … |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | 144 | if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->manage_terms ) ) { |
| 145 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 145 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| … |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
| 160 | 160 | public function get_item( $request ) { |
| 161 | 161 | $tax_obj = get_taxonomy( $request['taxonomy'] ); |
| 162 | 162 | if ( empty( $tax_obj ) ) { |
| 163 | | return new WP_Error( 'rest_taxonomy_invalid', __( 'Invalid taxonomy.' ), array( 'status' => 404 ) ); |
| | 163 | return new WP_Error( 'rest_taxonomy_invalid', _l( 'Invalid taxonomy.' ), array( 'status' => 404 ) ); |
| 164 | 164 | } |
| 165 | 165 | $data = $this->prepare_item_for_response( $tax_obj, $request ); |
| 166 | 166 | return rest_ensure_response( $data ); |
| … |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
| 233 | 233 | 'type' => 'object', |
| 234 | 234 | 'properties' => array( |
| 235 | 235 | 'capabilities' => array( |
| 236 | | 'description' => __( 'All capabilities used by the taxonomy.' ), |
| | 236 | 'description' => _l( 'All capabilities used by the taxonomy.' ), |
| 237 | 237 | 'type' => 'object', |
| 238 | 238 | 'context' => array( 'edit' ), |
| 239 | 239 | 'readonly' => true, |
| 240 | 240 | ), |
| 241 | 241 | 'description' => array( |
| 242 | | 'description' => __( 'A human-readable description of the taxonomy.' ), |
| | 242 | 'description' => _l( 'A human-readable description of the taxonomy.' ), |
| 243 | 243 | 'type' => 'string', |
| 244 | 244 | 'context' => array( 'view', 'edit' ), |
| 245 | 245 | 'readonly' => true, |
| 246 | 246 | ), |
| 247 | 247 | 'hierarchical' => array( |
| 248 | | 'description' => __( 'Whether or not the taxonomy should have children.' ), |
| | 248 | 'description' => _l( 'Whether or not the taxonomy should have children.' ), |
| 249 | 249 | 'type' => 'boolean', |
| 250 | 250 | 'context' => array( 'view', 'edit' ), |
| 251 | 251 | 'readonly' => true, |
| 252 | 252 | ), |
| 253 | 253 | 'labels' => array( |
| 254 | | 'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ), |
| | 254 | 'description' => _l( 'Human-readable labels for the taxonomy for various contexts.' ), |
| 255 | 255 | 'type' => 'object', |
| 256 | 256 | 'context' => array( 'edit' ), |
| 257 | 257 | 'readonly' => true, |
| 258 | 258 | ), |
| 259 | 259 | 'name' => array( |
| 260 | | 'description' => __( 'The title for the taxonomy.' ), |
| | 260 | 'description' => _l( 'The title for the taxonomy.' ), |
| 261 | 261 | 'type' => 'string', |
| 262 | 262 | 'context' => array( 'view', 'edit', 'embed' ), |
| 263 | 263 | 'readonly' => true, |
| 264 | 264 | ), |
| 265 | 265 | 'slug' => array( |
| 266 | | 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), |
| | 266 | 'description' => _l( 'An alphanumeric identifier for the taxonomy.' ), |
| 267 | 267 | 'type' => 'string', |
| 268 | 268 | 'context' => array( 'view', 'edit', 'embed' ), |
| 269 | 269 | 'readonly' => true, |
| 270 | 270 | ), |
| 271 | 271 | 'show_cloud' => array( |
| 272 | | 'description' => __( 'Whether or not the term cloud should be displayed.' ), |
| | 272 | 'description' => _l( 'Whether or not the term cloud should be displayed.' ), |
| 273 | 273 | 'type' => 'boolean', |
| 274 | 274 | 'context' => array( 'edit' ), |
| 275 | 275 | 'readonly' => true, |
| 276 | 276 | ), |
| 277 | 277 | 'types' => array( |
| 278 | | 'description' => __( 'Types associated with the taxonomy.' ), |
| | 278 | 'description' => _l( 'Types associated with the taxonomy.' ), |
| 279 | 279 | 'type' => 'array', |
| 280 | 280 | 'items' => array( |
| 281 | 281 | 'type' => 'string', |
| … |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
| 284 | 284 | 'readonly' => true, |
| 285 | 285 | ), |
| 286 | 286 | 'rest_base' => array( |
| 287 | | 'description' => __( 'REST base route for the taxonomy.' ), |
| | 287 | 'description' => _l( 'REST base route for the taxonomy.' ), |
| 288 | 288 | 'type' => 'string', |
| 289 | 289 | 'context' => array( 'view', 'edit', 'embed' ), |
| 290 | 290 | 'readonly' => true, |
| … |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
| 305 | 305 | $new_params = array(); |
| 306 | 306 | $new_params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
| 307 | 307 | $new_params['type'] = array( |
| 308 | | 'description' => __( 'Limit results to taxonomies associated with a specific post type.' ), |
| | 308 | 'description' => _l( 'Limit results to taxonomies associated with a specific post type.' ), |
| 309 | 309 | 'type' => 'string', |
| 310 | 310 | ); |
| 311 | 311 | return $new_params; |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
index ca0f53263a..f6f81b3e15 100644
|
|
|
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 92 | 92 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
| 93 | 93 | 'args' => array( |
| 94 | 94 | 'id' => array( |
| 95 | | 'description' => __( 'Unique identifier for the term.' ), |
| | 95 | 'description' => _l( 'Unique identifier for the term.' ), |
| 96 | 96 | 'type' => 'integer', |
| 97 | 97 | ), |
| 98 | 98 | ), |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 118 | 118 | 'force' => array( |
| 119 | 119 | 'type' => 'boolean', |
| 120 | 120 | 'default' => false, |
| 121 | | 'description' => __( 'Required to be true, as terms do not support trashing.' ), |
| | 121 | 'description' => _l( 'Required to be true, as terms do not support trashing.' ), |
| 122 | 122 | ), |
| 123 | 123 | ), |
| 124 | 124 | ), |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) { |
| 143 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 143 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 144 | 144 | } |
| 145 | 145 | return true; |
| 146 | 146 | } |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 294 | 294 | * @return WP_Term|WP_Error Term object if ID is valid, WP_Error otherwise. |
| 295 | 295 | */ |
| 296 | 296 | protected function get_term( $id ) { |
| 297 | | $error = new WP_Error( 'rest_term_invalid', __( 'Term does not exist.' ), array( 'status' => 404 ) ); |
| | 297 | $error = new WP_Error( 'rest_term_invalid', _l( 'Term does not exist.' ), array( 'status' => 404 ) ); |
| 298 | 298 | |
| 299 | 299 | if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) { |
| 300 | 300 | return $error; |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) { |
| 330 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 330 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 331 | 331 | } |
| 332 | 332 | return true; |
| 333 | 333 | } |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 367 | 367 | |
| 368 | 368 | $taxonomy_obj = get_taxonomy( $this->taxonomy ); |
| 369 | 369 | if ( ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) { |
| 370 | | return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 370 | return new WP_Error( 'rest_cannot_create', _l( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | return true; |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 384 | 384 | public function create_item( $request ) { |
| 385 | 385 | if ( isset( $request['parent'] ) ) { |
| 386 | 386 | if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { |
| 387 | | return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
| | 387 | return new WP_Error( 'rest_taxonomy_not_hierarchical', _l( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | $parent = get_term( (int) $request['parent'], $this->taxonomy ); |
| 391 | 391 | |
| 392 | 392 | if ( ! $parent ) { |
| 393 | | return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
| | 393 | return new WP_Error( 'rest_term_invalid', _l( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if ( ! current_user_can( 'edit_term', $term->term_id ) ) { |
| 469 | | return new WP_Error( 'rest_cannot_update', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 469 | return new WP_Error( 'rest_cannot_update', _l( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | return true; |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 488 | 488 | |
| 489 | 489 | if ( isset( $request['parent'] ) ) { |
| 490 | 490 | if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { |
| 491 | | return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
| | 491 | return new WP_Error( 'rest_taxonomy_not_hierarchical', _l( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | $parent = get_term( (int) $request['parent'], $this->taxonomy ); |
| 495 | 495 | |
| 496 | 496 | if ( ! $parent ) { |
| 497 | | return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
| | 497 | return new WP_Error( 'rest_term_invalid', _l( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | if ( ! current_user_can( 'delete_term', $term->term_id ) ) { |
| 554 | | return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 554 | return new WP_Error( 'rest_cannot_delete', _l( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | return true; |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 576 | 576 | // We don't support trashing for terms. |
| 577 | 577 | if ( ! $force ) { |
| 578 | 578 | /* translators: %s: force=true */ |
| 579 | | return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| | 579 | return new WP_Error( 'rest_trash_not_supported', sprintf( _l( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | $request->set_param( 'context', 'view' ); |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 586 | 586 | $retval = wp_delete_term( $term->term_id, $term->taxonomy ); |
| 587 | 587 | |
| 588 | 588 | if ( ! $retval ) { |
| 589 | | return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) ); |
| | 589 | return new WP_Error( 'rest_cannot_delete', _l( 'The term cannot be deleted.' ), array( 'status' => 500 ) ); |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | $response = new WP_REST_Response(); |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 809 | 809 | 'type' => 'object', |
| 810 | 810 | 'properties' => array( |
| 811 | 811 | 'id' => array( |
| 812 | | 'description' => __( 'Unique identifier for the term.' ), |
| | 812 | 'description' => _l( 'Unique identifier for the term.' ), |
| 813 | 813 | 'type' => 'integer', |
| 814 | 814 | 'context' => array( 'view', 'embed', 'edit' ), |
| 815 | 815 | 'readonly' => true, |
| 816 | 816 | ), |
| 817 | 817 | 'count' => array( |
| 818 | | 'description' => __( 'Number of published posts for the term.' ), |
| | 818 | 'description' => _l( 'Number of published posts for the term.' ), |
| 819 | 819 | 'type' => 'integer', |
| 820 | 820 | 'context' => array( 'view', 'edit' ), |
| 821 | 821 | 'readonly' => true, |
| 822 | 822 | ), |
| 823 | 823 | 'description' => array( |
| 824 | | 'description' => __( 'HTML description of the term.' ), |
| | 824 | 'description' => _l( 'HTML description of the term.' ), |
| 825 | 825 | 'type' => 'string', |
| 826 | 826 | 'context' => array( 'view', 'edit' ), |
| 827 | 827 | ), |
| 828 | 828 | 'link' => array( |
| 829 | | 'description' => __( 'URL of the term.' ), |
| | 829 | 'description' => _l( 'URL of the term.' ), |
| 830 | 830 | 'type' => 'string', |
| 831 | 831 | 'format' => 'uri', |
| 832 | 832 | 'context' => array( 'view', 'embed', 'edit' ), |
| 833 | 833 | 'readonly' => true, |
| 834 | 834 | ), |
| 835 | 835 | 'name' => array( |
| 836 | | 'description' => __( 'HTML title for the term.' ), |
| | 836 | 'description' => _l( 'HTML title for the term.' ), |
| 837 | 837 | 'type' => 'string', |
| 838 | 838 | 'context' => array( 'view', 'embed', 'edit' ), |
| 839 | 839 | 'arg_options' => array( |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 842 | 842 | 'required' => true, |
| 843 | 843 | ), |
| 844 | 844 | 'slug' => array( |
| 845 | | 'description' => __( 'An alphanumeric identifier for the term unique to its type.' ), |
| | 845 | 'description' => _l( 'An alphanumeric identifier for the term unique to its type.' ), |
| 846 | 846 | 'type' => 'string', |
| 847 | 847 | 'context' => array( 'view', 'embed', 'edit' ), |
| 848 | 848 | 'arg_options' => array( |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 850 | 850 | ), |
| 851 | 851 | ), |
| 852 | 852 | 'taxonomy' => array( |
| 853 | | 'description' => __( 'Type attribution for the term.' ), |
| | 853 | 'description' => _l( 'Type attribution for the term.' ), |
| 854 | 854 | 'type' => 'string', |
| 855 | 855 | 'enum' => array_keys( get_taxonomies() ), |
| 856 | 856 | 'context' => array( 'view', 'embed', 'edit' ), |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 863 | 863 | |
| 864 | 864 | if ( $taxonomy->hierarchical ) { |
| 865 | 865 | $schema['properties']['parent'] = array( |
| 866 | | 'description' => __( 'The parent term ID.' ), |
| | 866 | 'description' => _l( 'The parent term ID.' ), |
| 867 | 867 | 'type' => 'integer', |
| 868 | 868 | 'context' => array( 'view', 'edit' ), |
| 869 | 869 | ); |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 888 | 888 | $query_params['context']['default'] = 'view'; |
| 889 | 889 | |
| 890 | 890 | $query_params['exclude'] = array( |
| 891 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| | 891 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
| 892 | 892 | 'type' => 'array', |
| 893 | 893 | 'items' => array( |
| 894 | 894 | 'type' => 'integer', |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 897 | 897 | ); |
| 898 | 898 | |
| 899 | 899 | $query_params['include'] = array( |
| 900 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| | 900 | 'description' => _l( 'Limit result set to specific IDs.' ), |
| 901 | 901 | 'type' => 'array', |
| 902 | 902 | 'items' => array( |
| 903 | 903 | 'type' => 'integer', |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 907 | 907 | |
| 908 | 908 | if ( ! $taxonomy->hierarchical ) { |
| 909 | 909 | $query_params['offset'] = array( |
| 910 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| | 910 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
| 911 | 911 | 'type' => 'integer', |
| 912 | 912 | ); |
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | $query_params['order'] = array( |
| 916 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| | 916 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
| 917 | 917 | 'type' => 'string', |
| 918 | 918 | 'default' => 'asc', |
| 919 | 919 | 'enum' => array( |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 923 | 923 | ); |
| 924 | 924 | |
| 925 | 925 | $query_params['orderby'] = array( |
| 926 | | 'description' => __( 'Sort collection by term attribute.' ), |
| | 926 | 'description' => _l( 'Sort collection by term attribute.' ), |
| 927 | 927 | 'type' => 'string', |
| 928 | 928 | 'default' => 'name', |
| 929 | 929 | 'enum' => array( |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
| 938 | 938 | ); |
| 939 | 939 | |
| 940 | 940 | $query_params['hide_empty'] = array( |
| 941 | | 'description' => __( 'Whether to hide terms not assigned to any posts.' ), |
| | 941 | 'description' => _l( 'Whether to hide terms not assigned to any posts.' ), |
| 942 | 942 | 'type' => 'boolean', |
| 943 | 943 | 'default' => false, |
| 944 | 944 | ); |
| 945 | 945 | |
| 946 | 946 | if ( $taxonomy->hierarchical ) { |
| 947 | 947 | $query_params['parent'] = array( |
| 948 | | 'description' => __( 'Limit result set to terms assigned to a specific parent.' ), |
| | 948 | 'description' => _l( 'Limit result set to terms assigned to a specific parent.' ), |
| 949 | 949 | 'type' => 'integer', |
| 950 | 950 | ); |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | $query_params['post'] = array( |
| 954 | | 'description' => __( 'Limit result set to terms assigned to a specific post.' ), |
| | 954 | 'description' => _l( 'Limit result set to terms assigned to a specific post.' ), |
| 955 | 955 | 'type' => 'integer', |
| 956 | 956 | 'default' => null, |
| 957 | 957 | ); |
| 958 | 958 | |
| 959 | 959 | $query_params['slug'] = array( |
| 960 | | 'description' => __( 'Limit result set to terms with one or more specific slugs.' ), |
| | 960 | 'description' => _l( 'Limit result set to terms with one or more specific slugs.' ), |
| 961 | 961 | 'type' => 'array', |
| 962 | 962 | 'items' => array( |
| 963 | 963 | 'type' => 'string' |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
index 372c9654de..e2ade568df 100644
|
|
|
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 64 | 64 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
| 65 | 65 | 'args' => array( |
| 66 | 66 | 'id' => array( |
| 67 | | 'description' => __( 'Unique identifier for the user.' ), |
| | 67 | 'description' => _l( 'Unique identifier for the user.' ), |
| 68 | 68 | 'type' => 'integer', |
| 69 | 69 | ), |
| 70 | 70 | ), |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 90 | 90 | 'force' => array( |
| 91 | 91 | 'type' => 'boolean', |
| 92 | 92 | 'default' => false, |
| 93 | | 'description' => __( 'Required to be true, as users do not support trashing.' ), |
| | 93 | 'description' => _l( 'Required to be true, as users do not support trashing.' ), |
| 94 | 94 | ), |
| 95 | 95 | 'reassign' => array( |
| 96 | 96 | 'type' => 'integer', |
| 97 | | 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
| | 97 | 'description' => _l( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
| 98 | 98 | 'required' => true, |
| 99 | 99 | 'sanitize_callback' => array( $this, 'check_reassign' ), |
| 100 | 100 | ), |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 125 | 125 | 'force' => array( |
| 126 | 126 | 'type' => 'boolean', |
| 127 | 127 | 'default' => false, |
| 128 | | 'description' => __( 'Required to be true, as users do not support trashing.' ), |
| | 128 | 'description' => _l( 'Required to be true, as users do not support trashing.' ), |
| 129 | 129 | ), |
| 130 | 130 | 'reassign' => array( |
| 131 | 131 | 'type' => 'integer', |
| 132 | | 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
| | 132 | 'description' => _l( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
| 133 | 133 | 'required' => true, |
| 134 | 134 | 'sanitize_callback' => array( $this, 'check_reassign' ), |
| 135 | 135 | ), |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 161 | 161 | return false; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | | return new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
| | 164 | return new WP_Error( 'rest_invalid_param', _l( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 175 | 175 | public function get_items_permissions_check( $request ) { |
| 176 | 176 | // Check if roles is specified in GET request and if user can list users. |
| 177 | 177 | if ( ! empty( $request['roles'] ) && ! current_user_can( 'list_users' ) ) { |
| 178 | | return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to filter users by role.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 178 | return new WP_Error( 'rest_user_cannot_view', _l( 'Sorry, you are not allowed to filter users by role.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { |
| 182 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 182 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | if ( in_array( $request['orderby'], array( 'email', 'registered_date' ), true ) && ! current_user_can( 'list_users' ) ) { |
| 186 | | return new WP_Error( 'rest_forbidden_orderby', __( 'Sorry, you are not allowed to order users by this parameter.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 186 | return new WP_Error( 'rest_forbidden_orderby', _l( 'Sorry, you are not allowed to order users by this parameter.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | return true; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 330 | 330 | * @return WP_User|WP_Error True if ID is valid, WP_Error otherwise. |
| 331 | 331 | */ |
| 332 | 332 | protected function get_user( $id ) { |
| 333 | | $error = new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) ); |
| | 333 | $error = new WP_Error( 'rest_user_invalid_id', _l( 'Invalid user ID.' ), array( 'status' => 404 ) ); |
| 334 | 334 | if ( (int) $id <= 0 ) { |
| 335 | 335 | return $error; |
| 336 | 336 | } |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { |
| 371 | | return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 371 | return new WP_Error( 'rest_user_cannot_view', _l( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 372 | 372 | } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { |
| 373 | | return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 373 | return new WP_Error( 'rest_user_cannot_view', _l( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | return true; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 408 | 408 | $current_user_id = get_current_user_id(); |
| 409 | 409 | |
| 410 | 410 | if ( empty( $current_user_id ) ) { |
| 411 | | return new WP_Error( 'rest_not_logged_in', __( 'You are not currently logged in.' ), array( 'status' => 401 ) ); |
| | 411 | return new WP_Error( 'rest_not_logged_in', _l( 'You are not currently logged in.' ), array( 'status' => 401 ) ); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | $user = wp_get_current_user(); |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 430 | 430 | public function create_item_permissions_check( $request ) { |
| 431 | 431 | |
| 432 | 432 | if ( ! current_user_can( 'create_users' ) ) { |
| 433 | | return new WP_Error( 'rest_cannot_create_user', __( 'Sorry, you are not allowed to create new users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 433 | return new WP_Error( 'rest_cannot_create_user', _l( 'Sorry, you are not allowed to create new users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | return true; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 446 | 446 | */ |
| 447 | 447 | public function create_item( $request ) { |
| 448 | 448 | if ( ! empty( $request['id'] ) ) { |
| 449 | | return new WP_Error( 'rest_user_exists', __( 'Cannot create existing user.' ), array( 'status' => 400 ) ); |
| | 449 | return new WP_Error( 'rest_user_exists', _l( 'Cannot create existing user.' ), array( 'status' => 400 ) ); |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | $schema = $this->get_item_schema(); |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 465 | 465 | $ret = wpmu_validate_user_signup( $user->user_login, $user->user_email ); |
| 466 | 466 | |
| 467 | 467 | if ( is_wp_error( $ret['errors'] ) && ! empty( $ret['errors']->errors ) ) { |
| 468 | | $error = new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
| | 468 | $error = new WP_Error( 'rest_invalid_param', _l( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
| 469 | 469 | foreach ( $ret['errors']->errors as $code => $messages ) { |
| 470 | 470 | foreach ( $messages as $message ) { |
| 471 | 471 | $error->add( $code, $message ); |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 482 | 482 | $user_id = wpmu_create_user( $user->user_login, $user->user_pass, $user->user_email ); |
| 483 | 483 | |
| 484 | 484 | if ( ! $user_id ) { |
| 485 | | return new WP_Error( 'rest_user_create', __( 'Error creating new user.' ), array( 'status' => 500 ) ); |
| | 485 | return new WP_Error( 'rest_user_create', _l( 'Error creating new user.' ), array( 'status' => 500 ) ); |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | $user->ID = $user_id; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 563 | 563 | |
| 564 | 564 | if ( ! empty( $request['roles'] ) ) { |
| 565 | 565 | if ( ! current_user_can( 'promote_user', $user->ID ) ) { |
| 566 | | return new WP_Error( 'rest_cannot_edit_roles', __( 'Sorry, you are not allowed to edit roles of this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 566 | return new WP_Error( 'rest_cannot_edit_roles', _l( 'Sorry, you are not allowed to edit roles of this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | $request_params = array_keys( $request->get_params() ); |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
| 579 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 579 | return new WP_Error( 'rest_cannot_edit', _l( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | return true; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 599 | 599 | $id = $user->ID; |
| 600 | 600 | |
| 601 | 601 | if ( ! $user ) { |
| 602 | | return new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) ); |
| | 602 | return new WP_Error( 'rest_user_invalid_id', _l( 'Invalid user ID.' ), array( 'status' => 404 ) ); |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | if ( email_exists( $request['email'] ) && $request['email'] !== $user->user_email ) { |
| 606 | | return new WP_Error( 'rest_user_invalid_email', __( 'Invalid email address.' ), array( 'status' => 400 ) ); |
| | 606 | return new WP_Error( 'rest_user_invalid_email', _l( 'Invalid email address.' ), array( 'status' => 400 ) ); |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | if ( ! empty( $request['username'] ) && $request['username'] !== $user->user_login ) { |
| 610 | | return new WP_Error( 'rest_user_invalid_argument', __( "Username isn't editable." ), array( 'status' => 400 ) ); |
| | 610 | return new WP_Error( 'rest_user_invalid_argument', _l( "Username isn't editable." ), array( 'status' => 400 ) ); |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | if ( ! empty( $request['slug'] ) && $request['slug'] !== $user->user_nicename && get_user_by( 'slug', $request['slug'] ) ) { |
| 614 | | return new WP_Error( 'rest_user_invalid_slug', __( 'Invalid slug.' ), array( 'status' => 400 ) ); |
| | 614 | return new WP_Error( 'rest_user_invalid_slug', _l( 'Invalid slug.' ), array( 'status' => 400 ) ); |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | if ( ! empty( $request['roles'] ) ) { |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | if ( ! current_user_can( 'delete_user', $user->ID ) ) { |
| 713 | | return new WP_Error( 'rest_user_cannot_delete', __( 'Sorry, you are not allowed to delete this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 713 | return new WP_Error( 'rest_user_cannot_delete', _l( 'Sorry, you are not allowed to delete this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | return true; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 727 | 727 | public function delete_item( $request ) { |
| 728 | 728 | // We don't support delete requests in multisite. |
| 729 | 729 | if ( is_multisite() ) { |
| 730 | | return new WP_Error( 'rest_cannot_delete', __( 'The user cannot be deleted.' ), array( 'status' => 501 ) ); |
| | 730 | return new WP_Error( 'rest_cannot_delete', _l( 'The user cannot be deleted.' ), array( 'status' => 501 ) ); |
| 731 | 731 | } |
| 732 | 732 | $user = $this->get_user( $request['id'] ); |
| 733 | 733 | if ( is_wp_error( $user ) ) { |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 741 | 741 | // We don't support trashing for users. |
| 742 | 742 | if ( ! $force ) { |
| 743 | 743 | /* translators: %s: force=true */ |
| 744 | | return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Users do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| | 744 | return new WP_Error( 'rest_trash_not_supported', sprintf( _l( "Users do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | if ( ! empty( $reassign ) ) { |
| 748 | 748 | if ( $reassign === $id || ! get_userdata( $reassign ) ) { |
| 749 | | return new WP_Error( 'rest_user_invalid_reassign', __( 'Invalid user ID for reassignment.' ), array( 'status' => 400 ) ); |
| | 749 | return new WP_Error( 'rest_user_invalid_reassign', _l( 'Invalid user ID for reassignment.' ), array( 'status' => 400 ) ); |
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 760 | 760 | $result = wp_delete_user( $id, $reassign ); |
| 761 | 761 | |
| 762 | 762 | if ( ! $result ) { |
| 763 | | return new WP_Error( 'rest_cannot_delete', __( 'The user cannot be deleted.' ), array( 'status' => 500 ) ); |
| | 763 | return new WP_Error( 'rest_cannot_delete', _l( 'The user cannot be deleted.' ), array( 'status' => 500 ) ); |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | $response = new WP_REST_Response(); |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1034 | 1034 | |
| 1035 | 1035 | if ( ! isset( $wp_roles->role_objects[ $role ] ) ) { |
| 1036 | 1036 | /* translators: %s: role key */ |
| 1037 | | return new WP_Error( 'rest_user_invalid_role', sprintf( __( 'The role %s does not exist.' ), $role ), array( 'status' => 400 ) ); |
| | 1037 | return new WP_Error( 'rest_user_invalid_role', sprintf( _l( 'The role %s does not exist.' ), $role ), array( 'status' => 400 ) ); |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | $potential_role = $wp_roles->role_objects[ $role ]; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1048 | 1048 | && get_current_user_id() === $user_id |
| 1049 | 1049 | && ! $potential_role->has_cap( 'edit_users' ) |
| 1050 | 1050 | ) { |
| 1051 | | return new WP_Error( 'rest_user_invalid_role', __( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => rest_authorization_required_code() ) ); |
| | 1051 | return new WP_Error( 'rest_user_invalid_role', _l( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | /** Include admin functions to get access to get_editable_roles() */ |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1058 | 1058 | $editable_roles = get_editable_roles(); |
| 1059 | 1059 | |
| 1060 | 1060 | if ( empty( $editable_roles[ $role ] ) ) { |
| 1061 | | return new WP_Error( 'rest_user_invalid_role', __( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => 403 ) ); |
| | 1061 | return new WP_Error( 'rest_user_invalid_role', _l( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => 403 ) ); |
| 1062 | 1062 | } |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1081 | 1081 | $username = (string) $value; |
| 1082 | 1082 | |
| 1083 | 1083 | if ( ! validate_username( $username ) ) { |
| 1084 | | return new WP_Error( 'rest_user_invalid_username', __( 'Username contains invalid characters.' ), array( 'status' => 400 ) ); |
| | 1084 | return new WP_Error( 'rest_user_invalid_username', _l( 'Username contains invalid characters.' ), array( 'status' => 400 ) ); |
| 1085 | 1085 | } |
| 1086 | 1086 | |
| 1087 | 1087 | /** This filter is documented in wp-includes/user.php */ |
| 1088 | 1088 | $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
| 1089 | 1089 | |
| 1090 | 1090 | if ( in_array( strtolower( $username ), array_map( 'strtolower', $illegal_logins ) ) ) { |
| 1091 | | return new WP_Error( 'rest_user_invalid_username', __( 'Sorry, that username is not allowed.' ), array( 'status' => 400 ) ); |
| | 1091 | return new WP_Error( 'rest_user_invalid_username', _l( 'Sorry, that username is not allowed.' ), array( 'status' => 400 ) ); |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | return $username; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1110 | 1110 | $password = (string) $value; |
| 1111 | 1111 | |
| 1112 | 1112 | if ( empty( $password ) ) { |
| 1113 | | return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot be empty.' ), array( 'status' => 400 ) ); |
| | 1113 | return new WP_Error( 'rest_user_invalid_password', _l( 'Passwords cannot be empty.' ), array( 'status' => 400 ) ); |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | if ( false !== strpos( $password, "\\" ) ) { |
| 1117 | | return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) ); |
| | 1117 | return new WP_Error( 'rest_user_invalid_password', _l( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) ); |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | return $password; |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1134 | 1134 | 'type' => 'object', |
| 1135 | 1135 | 'properties' => array( |
| 1136 | 1136 | 'id' => array( |
| 1137 | | 'description' => __( 'Unique identifier for the user.' ), |
| | 1137 | 'description' => _l( 'Unique identifier for the user.' ), |
| 1138 | 1138 | 'type' => 'integer', |
| 1139 | 1139 | 'context' => array( 'embed', 'view', 'edit' ), |
| 1140 | 1140 | 'readonly' => true, |
| 1141 | 1141 | ), |
| 1142 | 1142 | 'username' => array( |
| 1143 | | 'description' => __( 'Login name for the user.' ), |
| | 1143 | 'description' => _l( 'Login name for the user.' ), |
| 1144 | 1144 | 'type' => 'string', |
| 1145 | 1145 | 'context' => array( 'edit' ), |
| 1146 | 1146 | 'required' => true, |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1149 | 1149 | ), |
| 1150 | 1150 | ), |
| 1151 | 1151 | 'name' => array( |
| 1152 | | 'description' => __( 'Display name for the user.' ), |
| | 1152 | 'description' => _l( 'Display name for the user.' ), |
| 1153 | 1153 | 'type' => 'string', |
| 1154 | 1154 | 'context' => array( 'embed', 'view', 'edit' ), |
| 1155 | 1155 | 'arg_options' => array( |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1157 | 1157 | ), |
| 1158 | 1158 | ), |
| 1159 | 1159 | 'first_name' => array( |
| 1160 | | 'description' => __( 'First name for the user.' ), |
| | 1160 | 'description' => _l( 'First name for the user.' ), |
| 1161 | 1161 | 'type' => 'string', |
| 1162 | 1162 | 'context' => array( 'edit' ), |
| 1163 | 1163 | 'arg_options' => array( |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1165 | 1165 | ), |
| 1166 | 1166 | ), |
| 1167 | 1167 | 'last_name' => array( |
| 1168 | | 'description' => __( 'Last name for the user.' ), |
| | 1168 | 'description' => _l( 'Last name for the user.' ), |
| 1169 | 1169 | 'type' => 'string', |
| 1170 | 1170 | 'context' => array( 'edit' ), |
| 1171 | 1171 | 'arg_options' => array( |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1173 | 1173 | ), |
| 1174 | 1174 | ), |
| 1175 | 1175 | 'email' => array( |
| 1176 | | 'description' => __( 'The email address for the user.' ), |
| | 1176 | 'description' => _l( 'The email address for the user.' ), |
| 1177 | 1177 | 'type' => 'string', |
| 1178 | 1178 | 'format' => 'email', |
| 1179 | 1179 | 'context' => array( 'edit' ), |
| 1180 | 1180 | 'required' => true, |
| 1181 | 1181 | ), |
| 1182 | 1182 | 'url' => array( |
| 1183 | | 'description' => __( 'URL of the user.' ), |
| | 1183 | 'description' => _l( 'URL of the user.' ), |
| 1184 | 1184 | 'type' => 'string', |
| 1185 | 1185 | 'format' => 'uri', |
| 1186 | 1186 | 'context' => array( 'embed', 'view', 'edit' ), |
| 1187 | 1187 | ), |
| 1188 | 1188 | 'description' => array( |
| 1189 | | 'description' => __( 'Description of the user.' ), |
| | 1189 | 'description' => _l( 'Description of the user.' ), |
| 1190 | 1190 | 'type' => 'string', |
| 1191 | 1191 | 'context' => array( 'embed', 'view', 'edit' ), |
| 1192 | 1192 | ), |
| 1193 | 1193 | 'link' => array( |
| 1194 | | 'description' => __( 'Author URL of the user.' ), |
| | 1194 | 'description' => _l( 'Author URL of the user.' ), |
| 1195 | 1195 | 'type' => 'string', |
| 1196 | 1196 | 'format' => 'uri', |
| 1197 | 1197 | 'context' => array( 'embed', 'view', 'edit' ), |
| 1198 | 1198 | 'readonly' => true, |
| 1199 | 1199 | ), |
| 1200 | 1200 | 'locale' => array( |
| 1201 | | 'description' => __( 'Locale for the user.' ), |
| | 1201 | 'description' => _l( 'Locale for the user.' ), |
| 1202 | 1202 | 'type' => 'string', |
| 1203 | 1203 | 'enum' => array_merge( array( '', 'en_US' ), get_available_languages() ), |
| 1204 | 1204 | 'context' => array( 'edit' ), |
| 1205 | 1205 | ), |
| 1206 | 1206 | 'nickname' => array( |
| 1207 | | 'description' => __( 'The nickname for the user.' ), |
| | 1207 | 'description' => _l( 'The nickname for the user.' ), |
| 1208 | 1208 | 'type' => 'string', |
| 1209 | 1209 | 'context' => array( 'edit' ), |
| 1210 | 1210 | 'arg_options' => array( |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1212 | 1212 | ), |
| 1213 | 1213 | ), |
| 1214 | 1214 | 'slug' => array( |
| 1215 | | 'description' => __( 'An alphanumeric identifier for the user.' ), |
| | 1215 | 'description' => _l( 'An alphanumeric identifier for the user.' ), |
| 1216 | 1216 | 'type' => 'string', |
| 1217 | 1217 | 'context' => array( 'embed', 'view', 'edit' ), |
| 1218 | 1218 | 'arg_options' => array( |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1220 | 1220 | ), |
| 1221 | 1221 | ), |
| 1222 | 1222 | 'registered_date' => array( |
| 1223 | | 'description' => __( 'Registration date for the user.' ), |
| | 1223 | 'description' => _l( 'Registration date for the user.' ), |
| 1224 | 1224 | 'type' => 'string', |
| 1225 | 1225 | 'format' => 'date-time', |
| 1226 | 1226 | 'context' => array( 'edit' ), |
| 1227 | 1227 | 'readonly' => true, |
| 1228 | 1228 | ), |
| 1229 | 1229 | 'roles' => array( |
| 1230 | | 'description' => __( 'Roles assigned to the user.' ), |
| | 1230 | 'description' => _l( 'Roles assigned to the user.' ), |
| 1231 | 1231 | 'type' => 'array', |
| 1232 | 1232 | 'items' => array( |
| 1233 | 1233 | 'type' => 'string', |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1235 | 1235 | 'context' => array( 'edit' ), |
| 1236 | 1236 | ), |
| 1237 | 1237 | 'password' => array( |
| 1238 | | 'description' => __( 'Password for the user (never included).' ), |
| | 1238 | 'description' => _l( 'Password for the user (never included).' ), |
| 1239 | 1239 | 'type' => 'string', |
| 1240 | 1240 | 'context' => array(), // Password is never displayed. |
| 1241 | 1241 | 'required' => true, |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1244 | 1244 | ), |
| 1245 | 1245 | ), |
| 1246 | 1246 | 'capabilities' => array( |
| 1247 | | 'description' => __( 'All capabilities assigned to the user.' ), |
| | 1247 | 'description' => _l( 'All capabilities assigned to the user.' ), |
| 1248 | 1248 | 'type' => 'object', |
| 1249 | 1249 | 'context' => array( 'edit' ), |
| 1250 | 1250 | 'readonly' => true, |
| 1251 | 1251 | ), |
| 1252 | 1252 | 'extra_capabilities' => array( |
| 1253 | | 'description' => __( 'Any extra capabilities assigned to the user.' ), |
| | 1253 | 'description' => _l( 'Any extra capabilities assigned to the user.' ), |
| 1254 | 1254 | 'type' => 'object', |
| 1255 | 1255 | 'context' => array( 'edit' ), |
| 1256 | 1256 | 'readonly' => true, |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1266 | 1266 | foreach ( $avatar_sizes as $size ) { |
| 1267 | 1267 | $avatar_properties[ $size ] = array( |
| 1268 | 1268 | /* translators: %d: avatar image size in pixels */ |
| 1269 | | 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ), |
| | 1269 | 'description' => sprintf( _l( 'Avatar URL with image size of %d pixels.' ), $size ), |
| 1270 | 1270 | 'type' => 'string', |
| 1271 | 1271 | 'format' => 'uri', |
| 1272 | 1272 | 'context' => array( 'embed', 'view', 'edit' ), |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | $schema['properties']['avatar_urls'] = array( |
| 1277 | | 'description' => __( 'Avatar URLs for the user.' ), |
| | 1277 | 'description' => _l( 'Avatar URLs for the user.' ), |
| 1278 | 1278 | 'type' => 'object', |
| 1279 | 1279 | 'context' => array( 'embed', 'view', 'edit' ), |
| 1280 | 1280 | 'readonly' => true, |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1300 | 1300 | $query_params['context']['default'] = 'view'; |
| 1301 | 1301 | |
| 1302 | 1302 | $query_params['exclude'] = array( |
| 1303 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| | 1303 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
| 1304 | 1304 | 'type' => 'array', |
| 1305 | 1305 | 'items' => array( |
| 1306 | 1306 | 'type' => 'integer', |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1309 | 1309 | ); |
| 1310 | 1310 | |
| 1311 | 1311 | $query_params['include'] = array( |
| 1312 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| | 1312 | 'description' => _l( 'Limit result set to specific IDs.' ), |
| 1313 | 1313 | 'type' => 'array', |
| 1314 | 1314 | 'items' => array( |
| 1315 | 1315 | 'type' => 'integer', |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1318 | 1318 | ); |
| 1319 | 1319 | |
| 1320 | 1320 | $query_params['offset'] = array( |
| 1321 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| | 1321 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
| 1322 | 1322 | 'type' => 'integer', |
| 1323 | 1323 | ); |
| 1324 | 1324 | |
| 1325 | 1325 | $query_params['order'] = array( |
| 1326 | 1326 | 'default' => 'asc', |
| 1327 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| | 1327 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
| 1328 | 1328 | 'enum' => array( 'asc', 'desc' ), |
| 1329 | 1329 | 'type' => 'string', |
| 1330 | 1330 | ); |
| 1331 | 1331 | |
| 1332 | 1332 | $query_params['orderby'] = array( |
| 1333 | 1333 | 'default' => 'name', |
| 1334 | | 'description' => __( 'Sort collection by object attribute.' ), |
| | 1334 | 'description' => _l( 'Sort collection by object attribute.' ), |
| 1335 | 1335 | 'enum' => array( |
| 1336 | 1336 | 'id', |
| 1337 | 1337 | 'include', |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1345 | 1345 | ); |
| 1346 | 1346 | |
| 1347 | 1347 | $query_params['slug'] = array( |
| 1348 | | 'description' => __( 'Limit result set to users with one or more specific slugs.' ), |
| | 1348 | 'description' => _l( 'Limit result set to users with one or more specific slugs.' ), |
| 1349 | 1349 | 'type' => 'array', |
| 1350 | 1350 | 'items' => array( |
| 1351 | 1351 | 'type' => 'string', |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
| 1353 | 1353 | ); |
| 1354 | 1354 | |
| 1355 | 1355 | $query_params['roles'] = array( |
| 1356 | | 'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ), |
| | 1356 | 'description' => _l( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ), |
| 1357 | 1357 | 'type' => 'array', |
| 1358 | 1358 | 'items' => array( |
| 1359 | 1359 | 'type' => 'string', |
-
diff --git src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
index 9288c0a284..519fcd4850 100644
|
|
|
abstract class WP_REST_Meta_Fields { |
| 173 | 173 | return new WP_Error( |
| 174 | 174 | 'rest_cannot_delete', |
| 175 | 175 | /* translators: %s: custom field key */ |
| 176 | | sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| | 176 | sprintf( _l( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| 177 | 177 | array( 'key' => $name, 'status' => rest_authorization_required_code() ) |
| 178 | 178 | ); |
| 179 | 179 | } |
| … |
… |
abstract class WP_REST_Meta_Fields { |
| 181 | 181 | if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ) ) ) { |
| 182 | 182 | return new WP_Error( |
| 183 | 183 | 'rest_meta_database_error', |
| 184 | | __( 'Could not delete meta value from database.' ), |
| | 184 | _l( 'Could not delete meta value from database.' ), |
| 185 | 185 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
| 186 | 186 | ); |
| 187 | 187 | } |
| … |
… |
abstract class WP_REST_Meta_Fields { |
| 208 | 208 | return new WP_Error( |
| 209 | 209 | 'rest_cannot_update', |
| 210 | 210 | /* translators: %s: custom field key */ |
| 211 | | sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| | 211 | sprintf( _l( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| 212 | 212 | array( 'key' => $name, 'status' => rest_authorization_required_code() ) |
| 213 | 213 | ); |
| 214 | 214 | } |
| … |
… |
abstract class WP_REST_Meta_Fields { |
| 243 | 243 | if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { |
| 244 | 244 | return new WP_Error( |
| 245 | 245 | 'rest_meta_database_error', |
| 246 | | __( 'Could not update meta value in database.' ), |
| | 246 | _l( 'Could not update meta value in database.' ), |
| 247 | 247 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
| 248 | 248 | ); |
| 249 | 249 | } |
| … |
… |
abstract class WP_REST_Meta_Fields { |
| 253 | 253 | if ( ! add_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { |
| 254 | 254 | return new WP_Error( |
| 255 | 255 | 'rest_meta_database_error', |
| 256 | | __( 'Could not update meta value in database.' ), |
| | 256 | _l( 'Could not update meta value in database.' ), |
| 257 | 257 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
| 258 | 258 | ); |
| 259 | 259 | } |
| … |
… |
abstract class WP_REST_Meta_Fields { |
| 279 | 279 | return new WP_Error( |
| 280 | 280 | 'rest_cannot_update', |
| 281 | 281 | /* translators: %s: custom field key */ |
| 282 | | sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| | 282 | sprintf( _l( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| 283 | 283 | array( 'key' => $name, 'status' => rest_authorization_required_code() ) |
| 284 | 284 | ); |
| 285 | 285 | } |
| … |
… |
abstract class WP_REST_Meta_Fields { |
| 299 | 299 | if ( ! update_metadata( $meta_type, $object_id, $meta_key, $meta_value ) ) { |
| 300 | 300 | return new WP_Error( |
| 301 | 301 | 'rest_meta_database_error', |
| 302 | | __( 'Could not update meta value in database.' ), |
| | 302 | _l( 'Could not update meta value in database.' ), |
| 303 | 303 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
| 304 | 304 | ); |
| 305 | 305 | } |
| … |
… |
abstract class WP_REST_Meta_Fields { |
| 376 | 376 | $fields = $this->get_registered_fields(); |
| 377 | 377 | |
| 378 | 378 | $schema = array( |
| 379 | | 'description' => __( 'Meta fields.' ), |
| | 379 | 'description' => _l( 'Meta fields.' ), |
| 380 | 380 | 'type' => 'object', |
| 381 | 381 | 'context' => array( 'view', 'edit' ), |
| 382 | 382 | 'properties' => array(), |
-
diff --git tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php
index d04cbcb7f7..e6476e14c2 100644
|
|
|
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { |
| 948 | 948 | } else { |
| 949 | 949 | $this->assertInternalType( 'array', $data['data']['params'] ); |
| 950 | 950 | $errors = $data['data']['params']; |
| 951 | | $this->assertInternalType( 'string', $errors['username'] ); |
| 952 | 951 | $this->assertEquals( 'Username contains invalid characters.', $errors['username'] ); |
| 953 | 952 | } |
| 954 | 953 | } |
| … |
… |
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { |
| 988 | 987 | $data = $response->get_data(); |
| 989 | 988 | $this->assertInternalType( 'array', $data['data']['params'] ); |
| 990 | 989 | $errors = $data['data']['params']; |
| 991 | | $this->assertInternalType( 'string', $errors['username'] ); |
| 992 | 990 | $this->assertEquals( 'Sorry, that username is not allowed.', $errors['username'] ); |
| 993 | 991 | } |
| 994 | 992 | |