-
diff --git src/wp-includes/rest-api.php src/wp-includes/rest-api.php
index fd6dc3e5f9..a06d94f7bd 100644
|
|
function register_rest_route( $namespace, $route, $args = array(), $override = f |
39 | 39 | * and namespace indexes. If you really need to register a |
40 | 40 | * non-namespaced route, call `WP_REST_Server::register_route` directly. |
41 | 41 | */ |
42 | | _doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' ); |
| 42 | _doing_it_wrong( 'register_rest_route', _l( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' ); |
43 | 43 | return false; |
44 | 44 | } else if ( empty( $route ) ) { |
45 | | _doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' ); |
| 45 | _doing_it_wrong( 'register_rest_route', _l( 'Route must be specified.' ), '4.4.0' ); |
46 | 46 | return false; |
47 | 47 | } |
48 | 48 | |
… |
… |
function rest_handle_deprecated_function( $function, $replacement, $version ) { |
494 | 494 | } |
495 | 495 | if ( ! empty( $replacement ) ) { |
496 | 496 | /* translators: 1: function name, 2: WordPress version number, 3: new function name */ |
497 | | $string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement ); |
| 497 | $string = sprintf( _l( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement ); |
498 | 498 | } else { |
499 | 499 | /* translators: 1: function name, 2: WordPress version number */ |
500 | | $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
| 500 | $string = sprintf( _l( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
501 | 501 | } |
502 | 502 | |
503 | 503 | header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) ); |
… |
… |
function rest_handle_deprecated_argument( $function, $message, $version ) { |
518 | 518 | } |
519 | 519 | if ( ! empty( $message ) ) { |
520 | 520 | /* translators: 1: function name, 2: WordPress version number, 3: error message */ |
521 | | $string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function, $version, $message ); |
| 521 | $string = sprintf( _l( '%1$s (since %2$s; %3$s)' ), $function, $version, $message ); |
522 | 522 | } else { |
523 | 523 | /* translators: 1: function name, 2: WordPress version number */ |
524 | | $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
| 524 | $string = sprintf( _l( '%1$s (since %2$s; no alternative available)' ), $function, $version ); |
525 | 525 | } |
526 | 526 | |
527 | 527 | header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) ); |
… |
… |
function rest_cookie_check_errors( $result ) { |
741 | 741 | $result = wp_verify_nonce( $nonce, 'wp_rest' ); |
742 | 742 | |
743 | 743 | if ( ! $result ) { |
744 | | return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) ); |
| 744 | return new WP_Error( 'rest_cookie_invalid_nonce', _l( 'Cookie nonce is invalid' ), array( 'status' => 403 ) ); |
745 | 745 | } |
746 | 746 | |
747 | 747 | // Send a refreshed nonce in header. |
… |
… |
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
1046 | 1046 | } |
1047 | 1047 | if ( ! wp_is_numeric_array( $value ) ) { |
1048 | 1048 | /* translators: 1: parameter, 2: type name */ |
1049 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) ); |
| 1049 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, 'array' ) ); |
1050 | 1050 | } |
1051 | 1051 | foreach ( $value as $index => $v ) { |
1052 | 1052 | $is_valid = rest_validate_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' ); |
… |
… |
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
1058 | 1058 | if ( ! empty( $args['enum'] ) ) { |
1059 | 1059 | if ( ! in_array( $value, $args['enum'], true ) ) { |
1060 | 1060 | /* translators: 1: parameter, 2: list of valid values */ |
1061 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not one of %2$s.' ), $param, implode( ', ', $args['enum'] ) ) ); |
| 1061 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not one of %2$s.' ), $param, implode( ', ', $args['enum'] ) ) ); |
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | if ( in_array( $args['type'], array( 'integer', 'number' ) ) && ! is_numeric( $value ) ) { |
1066 | 1066 | /* translators: 1: parameter, 2: type name */ |
1067 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); |
| 1067 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); |
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | if ( 'integer' === $args['type'] && round( floatval( $value ) ) !== floatval( $value ) ) { |
1071 | 1071 | /* translators: 1: parameter, 2: type name */ |
1072 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'integer' ) ); |
| 1072 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, 'integer' ) ); |
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | if ( 'boolean' === $args['type'] && ! rest_is_boolean( $value ) ) { |
1076 | 1076 | /* translators: 1: parameter, 2: type name */ |
1077 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $value, 'boolean' ) ); |
| 1077 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $value, 'boolean' ) ); |
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | if ( 'string' === $args['type'] && ! is_string( $value ) ) { |
1081 | 1081 | /* translators: 1: parameter, 2: type name */ |
1082 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'string' ) ); |
| 1082 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s is not of type %2$s.' ), $param, 'string' ) ); |
1083 | 1083 | } |
1084 | 1084 | |
1085 | 1085 | if ( isset( $args['format'] ) ) { |
1086 | 1086 | switch ( $args['format'] ) { |
1087 | 1087 | case 'date-time' : |
1088 | 1088 | if ( ! rest_parse_date( $value ) ) { |
1089 | | return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) ); |
| 1089 | return new WP_Error( 'rest_invalid_date', _l( 'Invalid date.' ) ); |
1090 | 1090 | } |
1091 | 1091 | break; |
1092 | 1092 | |
1093 | 1093 | case 'email' : |
1094 | 1094 | if ( ! is_email( $value ) ) { |
1095 | | return new WP_Error( 'rest_invalid_email', __( 'Invalid email address.' ) ); |
| 1095 | return new WP_Error( 'rest_invalid_email', _l( 'Invalid email address.' ) ); |
1096 | 1096 | } |
1097 | 1097 | break; |
1098 | 1098 | case 'ip' : |
1099 | 1099 | if ( ! rest_is_ip_address( $value ) ) { |
1100 | 1100 | /* translators: %s: IP address */ |
1101 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) ); |
| 1101 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%s is not a valid IP address.' ), $value ) ); |
1102 | 1102 | } |
1103 | 1103 | break; |
1104 | 1104 | } |
… |
… |
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
1108 | 1108 | if ( isset( $args['minimum'] ) && ! isset( $args['maximum'] ) ) { |
1109 | 1109 | if ( ! empty( $args['exclusiveMinimum'] ) && $value <= $args['minimum'] ) { |
1110 | 1110 | /* translators: 1: parameter, 2: minimum number */ |
1111 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d' ), $param, $args['minimum'] ) ); |
| 1111 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be greater than %2$d' ), $param, $args['minimum'] ) ); |
1112 | 1112 | } elseif ( empty( $args['exclusiveMinimum'] ) && $value < $args['minimum'] ) { |
1113 | 1113 | /* translators: 1: parameter, 2: minimum number */ |
1114 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than or equal to %2$d' ), $param, $args['minimum'] ) ); |
| 1114 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be greater than or equal to %2$d' ), $param, $args['minimum'] ) ); |
1115 | 1115 | } |
1116 | 1116 | } elseif ( isset( $args['maximum'] ) && ! isset( $args['minimum'] ) ) { |
1117 | 1117 | if ( ! empty( $args['exclusiveMaximum'] ) && $value >= $args['maximum'] ) { |
1118 | 1118 | /* translators: 1: parameter, 2: maximum number */ |
1119 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d' ), $param, $args['maximum'] ) ); |
| 1119 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be less than %2$d' ), $param, $args['maximum'] ) ); |
1120 | 1120 | } elseif ( empty( $args['exclusiveMaximum'] ) && $value > $args['maximum'] ) { |
1121 | 1121 | /* translators: 1: parameter, 2: maximum number */ |
1122 | | return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than or equal to %2$d' ), $param, $args['maximum'] ) ); |
| 1122 | return new WP_Error( 'rest_invalid_param', sprintf( _l( '%1$s must be less than or equal to %2$d' ), $param, $args['maximum'] ) ); |
1123 | 1123 | } |
1124 | 1124 | } elseif ( isset( $args['maximum'] ) && isset( $args['minimum'] ) ) { |
1125 | 1125 | if ( ! empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) { |
1126 | 1126 | if ( $value >= $args['maximum'] || $value <= $args['minimum'] ) { |
1127 | 1127 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
1128 | | 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'] ) ); |
| 1128 | 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'] ) ); |
1129 | 1129 | } |
1130 | 1130 | } elseif ( empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) { |
1131 | 1131 | if ( $value >= $args['maximum'] || $value < $args['minimum'] ) { |
1132 | 1132 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
1133 | | 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'] ) ); |
| 1133 | 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'] ) ); |
1134 | 1134 | } |
1135 | 1135 | } elseif ( ! empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) { |
1136 | 1136 | if ( $value > $args['maximum'] || $value <= $args['minimum'] ) { |
1137 | 1137 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
1138 | | 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'] ) ); |
| 1138 | 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'] ) ); |
1139 | 1139 | } |
1140 | 1140 | } elseif ( empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) { |
1141 | 1141 | if ( $value > $args['maximum'] || $value < $args['minimum'] ) { |
1142 | 1142 | /* translators: 1: parameter, 2: minimum number, 3: maximum number */ |
1143 | | 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'] ) ); |
| 1143 | 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'] ) ); |
1144 | 1144 | } |
1145 | 1145 | } |
1146 | 1146 | } |
-
diff --git src/wp-includes/rest-api/class-wp-rest-request.php src/wp-includes/rest-api/class-wp-rest-request.php
index e41c014557..83a7c2458c 100644
|
|
class WP_REST_Request implements ArrayAccess { |
692 | 692 | $error_data['json_error_message'] = json_last_error_msg(); |
693 | 693 | } |
694 | 694 | |
695 | | return new WP_Error( 'rest_invalid_json', __( 'Invalid JSON body passed.' ), $error_data ); |
| 695 | return new WP_Error( 'rest_invalid_json', _l( 'Invalid JSON body passed.' ), $error_data ); |
696 | 696 | } |
697 | 697 | |
698 | 698 | $this->params['JSON'] = $params; |
… |
… |
class WP_REST_Request implements ArrayAccess { |
846 | 846 | } |
847 | 847 | |
848 | 848 | if ( $invalid_params ) { |
849 | | return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
| 849 | return new WP_Error( 'rest_invalid_param', sprintf( _l( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
850 | 850 | } |
851 | 851 | |
852 | 852 | return true; |
… |
… |
class WP_REST_Request implements ArrayAccess { |
885 | 885 | } |
886 | 886 | |
887 | 887 | if ( ! empty( $required ) ) { |
888 | | return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) ); |
| 888 | return new WP_Error( 'rest_missing_callback_param', sprintf( _l( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) ); |
889 | 889 | } |
890 | 890 | |
891 | 891 | /* |
… |
… |
class WP_REST_Request implements ArrayAccess { |
903 | 903 | $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key ); |
904 | 904 | |
905 | 905 | if ( false === $valid_check ) { |
906 | | $invalid_params[ $key ] = __( 'Invalid parameter.' ); |
| 906 | $invalid_params[ $key ] = _l( 'Invalid parameter.' ); |
907 | 907 | } |
908 | 908 | |
909 | 909 | if ( is_wp_error( $valid_check ) ) { |
… |
… |
class WP_REST_Request implements ArrayAccess { |
913 | 913 | } |
914 | 914 | |
915 | 915 | if ( $invalid_params ) { |
916 | | return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
| 916 | return new WP_Error( 'rest_invalid_param', sprintf( _l( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
917 | 917 | } |
918 | 918 | |
919 | 919 | 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 2ec8ccde23..2c1427d22b 100644
|
|
class WP_REST_Server { |
269 | 269 | * @param bool $rest_enabled Whether the REST API is enabled. Default true. |
270 | 270 | */ |
271 | 271 | apply_filters_deprecated( 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors', |
272 | | __( 'The REST API can no longer be completely disabled, the rest_authentication_errors filter can be used to restrict access to the API, instead.' ) |
| 272 | _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.' ) |
273 | 273 | ); |
274 | 274 | |
275 | 275 | /** |
… |
… |
class WP_REST_Server { |
285 | 285 | |
286 | 286 | if ( isset( $_GET['_jsonp'] ) ) { |
287 | 287 | if ( ! $jsonp_enabled ) { |
288 | | echo $this->json_error( 'rest_callback_disabled', __( 'JSONP support is disabled on this site.' ), 400 ); |
| 288 | echo $this->json_error( 'rest_callback_disabled', _l( 'JSONP support is disabled on this site.' ), 400 ); |
289 | 289 | return false; |
290 | 290 | } |
291 | 291 | |
292 | 292 | $jsonp_callback = $_GET['_jsonp']; |
293 | 293 | if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) { |
294 | | echo $this->json_error( 'rest_callback_invalid', __( 'Invalid JSONP callback function.' ), 400 ); |
| 294 | echo $this->json_error( 'rest_callback_invalid', _l( 'Invalid JSONP callback function.' ), 400 ); |
295 | 295 | return false; |
296 | 296 | } |
297 | 297 | } |
… |
… |
class WP_REST_Server { |
862 | 862 | } |
863 | 863 | |
864 | 864 | if ( ! is_callable( $callback ) ) { |
865 | | $response = new WP_Error( 'rest_invalid_handler', __( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); |
| 865 | $response = new WP_Error( 'rest_invalid_handler', _l( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); |
866 | 866 | } |
867 | 867 | |
868 | 868 | if ( ! is_wp_error( $response ) ) { |
… |
… |
class WP_REST_Server { |
919 | 919 | if ( is_wp_error( $permission ) ) { |
920 | 920 | $response = $permission; |
921 | 921 | } elseif ( false === $permission || null === $permission ) { |
922 | | $response = new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( 'status' => 403 ) ); |
| 922 | $response = new WP_Error( 'rest_forbidden', _l( 'Sorry, you are not allowed to do that.' ), array( 'status' => 403 ) ); |
923 | 923 | } |
924 | 924 | } |
925 | 925 | } |
… |
… |
class WP_REST_Server { |
983 | 983 | } |
984 | 984 | } |
985 | 985 | |
986 | | return $this->error_to_response( new WP_Error( 'rest_no_route', __( 'No route was found matching the URL and request method' ), array( 'status' => 404 ) ) ); |
| 986 | 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 ) ) ); |
987 | 987 | } |
988 | 988 | |
989 | 989 | /** |
… |
… |
class WP_REST_Server { |
1073 | 1073 | $namespace = $request['namespace']; |
1074 | 1074 | |
1075 | 1075 | if ( ! isset( $this->namespaces[ $namespace ] ) ) { |
1076 | | return new WP_Error( 'rest_invalid_namespace', __( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); |
| 1076 | return new WP_Error( 'rest_invalid_namespace', _l( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); |
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | $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 43d057e167..d00bff397b 100644
|
|
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
72 | 72 | } |
73 | 73 | |
74 | 74 | if ( ! current_user_can( 'upload_files' ) ) { |
75 | | return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to upload media on this site.' ), array( 'status' => 400 ) ); |
| 75 | return new WP_Error( 'rest_cannot_create', _l( 'Sorry, you are not allowed to upload media on this site.' ), array( 'status' => 400 ) ); |
76 | 76 | } |
77 | 77 | |
78 | 78 | // Attaching media to a post requires ability to edit said post. |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
81 | 81 | $post_parent_type = get_post_type_object( $parent->post_type ); |
82 | 82 | |
83 | 83 | if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) { |
84 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to upload media to this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 84 | 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() ) ); |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
100 | 100 | public function create_item( $request ) { |
101 | 101 | |
102 | 102 | if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { |
103 | | return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
| 103 | return new WP_Error( 'rest_invalid_param', _l( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Get the file via $_FILES or raw data. |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
207 | 207 | */ |
208 | 208 | public function update_item( $request ) { |
209 | 209 | if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { |
210 | | return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
| 210 | return new WP_Error( 'rest_invalid_param', _l( 'Invalid parent type.' ), array( 'status' => 400 ) ); |
211 | 211 | } |
212 | 212 | |
213 | 213 | $response = parent::update_item( $request ); |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
384 | 384 | $schema = parent::get_item_schema(); |
385 | 385 | |
386 | 386 | $schema['properties']['alt_text'] = array( |
387 | | 'description' => __( 'Alternative text to display when attachment is not displayed.' ), |
| 387 | 'description' => _l( 'Alternative text to display when attachment is not displayed.' ), |
388 | 388 | 'type' => 'string', |
389 | 389 | 'context' => array( 'view', 'edit', 'embed' ), |
390 | 390 | 'arg_options' => array( |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
393 | 393 | ); |
394 | 394 | |
395 | 395 | $schema['properties']['caption'] = array( |
396 | | 'description' => __( 'The attachment caption.' ), |
| 396 | 'description' => _l( 'The attachment caption.' ), |
397 | 397 | 'type' => 'object', |
398 | 398 | 'context' => array( 'view', 'edit', 'embed' ), |
399 | 399 | 'arg_options' => array( |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
401 | 401 | ), |
402 | 402 | 'properties' => array( |
403 | 403 | 'raw' => array( |
404 | | 'description' => __( 'Caption for the attachment, as it exists in the database.' ), |
| 404 | 'description' => _l( 'Caption for the attachment, as it exists in the database.' ), |
405 | 405 | 'type' => 'string', |
406 | 406 | 'context' => array( 'edit' ), |
407 | 407 | ), |
408 | 408 | 'rendered' => array( |
409 | | 'description' => __( 'HTML caption for the attachment, transformed for display.' ), |
| 409 | 'description' => _l( 'HTML caption for the attachment, transformed for display.' ), |
410 | 410 | 'type' => 'string', |
411 | 411 | 'context' => array( 'view', 'edit', 'embed' ), |
412 | 412 | 'readonly' => true, |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
415 | 415 | ); |
416 | 416 | |
417 | 417 | $schema['properties']['description'] = array( |
418 | | 'description' => __( 'The attachment description.' ), |
| 418 | 'description' => _l( 'The attachment description.' ), |
419 | 419 | 'type' => 'object', |
420 | 420 | 'context' => array( 'view', 'edit' ), |
421 | 421 | 'arg_options' => array( |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
423 | 423 | ), |
424 | 424 | 'properties' => array( |
425 | 425 | 'raw' => array( |
426 | | 'description' => __( 'Description for the object, as it exists in the database.' ), |
| 426 | 'description' => _l( 'Description for the object, as it exists in the database.' ), |
427 | 427 | 'type' => 'string', |
428 | 428 | 'context' => array( 'edit' ), |
429 | 429 | ), |
430 | 430 | 'rendered' => array( |
431 | | 'description' => __( 'HTML description for the object, transformed for display.' ), |
| 431 | 'description' => _l( 'HTML description for the object, transformed for display.' ), |
432 | 432 | 'type' => 'string', |
433 | 433 | 'context' => array( 'view', 'edit' ), |
434 | 434 | 'readonly' => true, |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
437 | 437 | ); |
438 | 438 | |
439 | 439 | $schema['properties']['media_type'] = array( |
440 | | 'description' => __( 'Attachment type.' ), |
| 440 | 'description' => _l( 'Attachment type.' ), |
441 | 441 | 'type' => 'string', |
442 | 442 | 'enum' => array( 'image', 'file' ), |
443 | 443 | 'context' => array( 'view', 'edit', 'embed' ), |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
445 | 445 | ); |
446 | 446 | |
447 | 447 | $schema['properties']['mime_type'] = array( |
448 | | 'description' => __( 'The attachment MIME type.' ), |
| 448 | 'description' => _l( 'The attachment MIME type.' ), |
449 | 449 | 'type' => 'string', |
450 | 450 | 'context' => array( 'view', 'edit', 'embed' ), |
451 | 451 | 'readonly' => true, |
452 | 452 | ); |
453 | 453 | |
454 | 454 | $schema['properties']['media_details'] = array( |
455 | | 'description' => __( 'Details about the media file, specific to its type.' ), |
| 455 | 'description' => _l( 'Details about the media file, specific to its type.' ), |
456 | 456 | 'type' => 'object', |
457 | 457 | 'context' => array( 'view', 'edit', 'embed' ), |
458 | 458 | 'readonly' => true, |
459 | 459 | ); |
460 | 460 | |
461 | 461 | $schema['properties']['post'] = array( |
462 | | 'description' => __( 'The ID for the associated post of the attachment.' ), |
| 462 | 'description' => _l( 'The ID for the associated post of the attachment.' ), |
463 | 463 | 'type' => 'integer', |
464 | 464 | 'context' => array( 'view', 'edit' ), |
465 | 465 | ); |
466 | 466 | |
467 | 467 | $schema['properties']['source_url'] = array( |
468 | | 'description' => __( 'URL to the original attachment file.' ), |
| 468 | 'description' => _l( 'URL to the original attachment file.' ), |
469 | 469 | 'type' => 'string', |
470 | 470 | 'format' => 'uri', |
471 | 471 | 'context' => array( 'view', 'edit', 'embed' ), |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
489 | 489 | */ |
490 | 490 | protected function upload_from_data( $data, $headers ) { |
491 | 491 | if ( empty( $data ) ) { |
492 | | return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); |
| 492 | return new WP_Error( 'rest_upload_no_data', _l( 'No data supplied.' ), array( 'status' => 400 ) ); |
493 | 493 | } |
494 | 494 | |
495 | 495 | if ( empty( $headers['content_type'] ) ) { |
496 | | return new WP_Error( 'rest_upload_no_content_type', __( 'No Content-Type supplied.' ), array( 'status' => 400 ) ); |
| 496 | return new WP_Error( 'rest_upload_no_content_type', _l( 'No Content-Type supplied.' ), array( 'status' => 400 ) ); |
497 | 497 | } |
498 | 498 | |
499 | 499 | if ( empty( $headers['content_disposition'] ) ) { |
500 | | return new WP_Error( 'rest_upload_no_content_disposition', __( 'No Content-Disposition supplied.' ), array( 'status' => 400 ) ); |
| 500 | return new WP_Error( 'rest_upload_no_content_disposition', _l( 'No Content-Disposition supplied.' ), array( 'status' => 400 ) ); |
501 | 501 | } |
502 | 502 | |
503 | 503 | $filename = self::get_filename_from_disposition( $headers['content_disposition'] ); |
504 | 504 | |
505 | 505 | if ( empty( $filename ) ) { |
506 | | 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 ) ); |
| 506 | 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 ) ); |
507 | 507 | } |
508 | 508 | |
509 | 509 | if ( ! empty( $headers['content_md5'] ) ) { |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
512 | 512 | $actual = md5( $data ); |
513 | 513 | |
514 | 514 | if ( $expected !== $actual ) { |
515 | | return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
| 515 | return new WP_Error( 'rest_upload_hash_mismatch', _l( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
528 | 528 | $fp = fopen( $tmpfname, 'w+' ); |
529 | 529 | |
530 | 530 | if ( ! $fp ) { |
531 | | return new WP_Error( 'rest_upload_file_error', __( 'Could not open file handle.' ), array( 'status' => 500 ) ); |
| 531 | return new WP_Error( 'rest_upload_file_error', _l( 'Could not open file handle.' ), array( 'status' => 500 ) ); |
532 | 532 | } |
533 | 533 | |
534 | 534 | fwrite( $fp, $data ); |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
644 | 644 | |
645 | 645 | $params['media_type'] = array( |
646 | 646 | 'default' => null, |
647 | | 'description' => __( 'Limit result set to attachments of a particular media type.' ), |
| 647 | 'description' => _l( 'Limit result set to attachments of a particular media type.' ), |
648 | 648 | 'type' => 'string', |
649 | 649 | 'enum' => array_keys( $media_types ), |
650 | 650 | ); |
651 | 651 | |
652 | 652 | $params['mime_type'] = array( |
653 | 653 | 'default' => null, |
654 | | 'description' => __( 'Limit result set to attachments of a particular MIME type.' ), |
| 654 | 'description' => _l( 'Limit result set to attachments of a particular MIME type.' ), |
655 | 655 | 'type' => 'string', |
656 | 656 | ); |
657 | 657 | |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
689 | 689 | */ |
690 | 690 | protected function upload_from_file( $files, $headers ) { |
691 | 691 | if ( empty( $files ) ) { |
692 | | return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); |
| 692 | return new WP_Error( 'rest_upload_no_data', _l( 'No data supplied.' ), array( 'status' => 400 ) ); |
693 | 693 | } |
694 | 694 | |
695 | 695 | // Verify hash, if given. |
… |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
699 | 699 | $actual = md5_file( $files['file']['tmp_name'] ); |
700 | 700 | |
701 | 701 | if ( $expected !== $actual ) { |
702 | | return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
| 702 | return new WP_Error( 'rest_upload_hash_mismatch', _l( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); |
703 | 703 | } |
704 | 704 | } |
705 | 705 | |
-
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 4ed2026dcb..2a2fe5515d 100644
|
|
class WP_REST_Comments_Controller extends WP_REST_Controller { |
65 | 65 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
66 | 66 | 'args' => array( |
67 | 67 | 'id' => array( |
68 | | 'description' => __( 'Unique identifier for the object.' ), |
| 68 | 'description' => _l( 'Unique identifier for the object.' ), |
69 | 69 | 'type' => 'integer', |
70 | 70 | ), |
71 | 71 | ), |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
76 | 76 | 'args' => array( |
77 | 77 | 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
78 | 78 | 'password' => array( |
79 | | 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), |
| 79 | 'description' => _l( 'The password for the parent post of the comment (if the post is password protected).' ), |
80 | 80 | 'type' => 'string', |
81 | 81 | ), |
82 | 82 | ), |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
95 | 95 | 'force' => array( |
96 | 96 | 'type' => 'boolean', |
97 | 97 | 'default' => false, |
98 | | 'description' => __( 'Whether to bypass trash and force deletion.' ), |
| 98 | 'description' => _l( 'Whether to bypass trash and force deletion.' ), |
99 | 99 | ), |
100 | 100 | 'password' => array( |
101 | | 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), |
| 101 | 'description' => _l( 'The password for the parent post of the comment (if the post is password protected).' ), |
102 | 102 | 'type' => 'string', |
103 | 103 | ), |
104 | 104 | ), |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
123 | 123 | $post = get_post( $post_id ); |
124 | 124 | |
125 | 125 | if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post, $request ) ) { |
126 | | 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() ) ); |
| 126 | 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() ) ); |
127 | 127 | } elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) { |
128 | | return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 128 | 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() ) ); |
129 | 129 | } |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { |
134 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 134 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
135 | 135 | } |
136 | 136 | |
137 | 137 | if ( ! current_user_can( 'edit_posts' ) ) { |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
153 | 153 | } |
154 | 154 | |
155 | 155 | if ( ! empty( $forbidden_params ) ) { |
156 | | return new WP_Error( 'rest_forbidden_param', sprintf( __( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) ); |
| 156 | return new WP_Error( 'rest_forbidden_param', sprintf( _l( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) ); |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
314 | 314 | * @return WP_Comment|WP_Error Comment object if ID is valid, WP_Error otherwise. |
315 | 315 | */ |
316 | 316 | protected function get_comment( $id ) { |
317 | | $error = new WP_Error( 'rest_comment_invalid_id', __( 'Invalid comment ID.' ), array( 'status' => 404 ) ); |
| 317 | $error = new WP_Error( 'rest_comment_invalid_id', _l( 'Invalid comment ID.' ), array( 'status' => 404 ) ); |
318 | 318 | if ( (int) $id <= 0 ) { |
319 | 319 | return $error; |
320 | 320 | } |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
328 | 328 | if ( ! empty( $comment->comment_post_ID ) ) { |
329 | 329 | $post = get_post( (int) $comment->comment_post_ID ); |
330 | 330 | if ( empty( $post ) ) { |
331 | | return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
| 331 | return new WP_Error( 'rest_post_invalid_id', _l( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
351 | 351 | } |
352 | 352 | |
353 | 353 | if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { |
354 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 354 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); |
355 | 355 | } |
356 | 356 | |
357 | 357 | $post = get_post( $comment->comment_post_ID ); |
358 | 358 | |
359 | 359 | if ( ! $this->check_read_permission( $comment, $request ) ) { |
360 | | return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 360 | return new WP_Error( 'rest_cannot_read', _l( 'Sorry, you are not allowed to read this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
361 | 361 | } |
362 | 362 | |
363 | 363 | if ( $post && ! $this->check_read_post_permission( $post, $request ) ) { |
364 | | 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() ) ); |
| 364 | 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() ) ); |
365 | 365 | } |
366 | 366 | |
367 | 367 | return true; |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
400 | 400 | public function create_item_permissions_check( $request ) { |
401 | 401 | if ( ! is_user_logged_in() ) { |
402 | 402 | if ( get_option( 'comment_registration' ) ) { |
403 | | return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
| 403 | return new WP_Error( 'rest_comment_login_required', _l( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
417 | 417 | */ |
418 | 418 | $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request ); |
419 | 419 | if ( ! $allow_anonymous ) { |
420 | | return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
| 420 | return new WP_Error( 'rest_comment_login_required', _l( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); |
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
425 | 425 | if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { |
426 | 426 | return new WP_Error( 'rest_comment_invalid_author', |
427 | 427 | /* translators: %s: request parameter */ |
428 | | sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), |
| 428 | sprintf( _l( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), |
429 | 429 | array( 'status' => rest_authorization_required_code() ) |
430 | 430 | ); |
431 | 431 | } |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
434 | 434 | if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) { |
435 | 435 | return new WP_Error( 'rest_comment_invalid_author_ip', |
436 | 436 | /* translators: %s: request parameter */ |
437 | | sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ), |
| 437 | sprintf( _l( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ), |
438 | 438 | array( 'status' => rest_authorization_required_code() ) |
439 | 439 | ); |
440 | 440 | } |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
443 | 443 | if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) { |
444 | 444 | return new WP_Error( 'rest_comment_invalid_status', |
445 | 445 | /* translators: %s: request parameter */ |
446 | | sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ), |
| 446 | sprintf( _l( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ), |
447 | 447 | array( 'status' => rest_authorization_required_code() ) |
448 | 448 | ); |
449 | 449 | } |
450 | 450 | |
451 | 451 | if ( empty( $request['post'] ) ) { |
452 | | return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); |
| 452 | 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 ) ); |
453 | 453 | } |
454 | 454 | |
455 | 455 | $post = get_post( (int) $request['post'] ); |
456 | 456 | if ( ! $post ) { |
457 | | return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); |
| 457 | 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 ) ); |
458 | 458 | } |
459 | 459 | |
460 | 460 | if ( 'draft' === $post->post_status ) { |
461 | | return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
| 461 | return new WP_Error( 'rest_comment_draft_post', _l( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
462 | 462 | } |
463 | 463 | |
464 | 464 | if ( 'trash' === $post->post_status ) { |
465 | | return new WP_Error( 'rest_comment_trash_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
| 465 | return new WP_Error( 'rest_comment_trash_post', _l( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); |
466 | 466 | } |
467 | 467 | |
468 | 468 | if ( ! $this->check_read_post_permission( $post, $request ) ) { |
469 | | 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() ) ); |
| 469 | 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() ) ); |
470 | 470 | } |
471 | 471 | |
472 | 472 | if ( ! comments_open( $post->ID ) ) { |
473 | | return new WP_Error( 'rest_comment_closed', __( 'Sorry, comments are closed for this item.' ), array( 'status' => 403 ) ); |
| 473 | return new WP_Error( 'rest_comment_closed', _l( 'Sorry, comments are closed for this item.' ), array( 'status' => 403 ) ); |
474 | 474 | } |
475 | 475 | |
476 | 476 | return true; |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
487 | 487 | */ |
488 | 488 | public function create_item( $request ) { |
489 | 489 | if ( ! empty( $request['id'] ) ) { |
490 | | return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) ); |
| 490 | return new WP_Error( 'rest_comment_exists', _l( 'Cannot create existing comment.' ), array( 'status' => 400 ) ); |
491 | 491 | } |
492 | 492 | |
493 | 493 | // Do not allow comments to be created with a non-default type. |
494 | 494 | if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) { |
495 | | return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); |
| 495 | return new WP_Error( 'rest_invalid_comment_type', _l( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); |
496 | 496 | } |
497 | 497 | |
498 | 498 | $prepared_comment = $this->prepare_item_for_database( $request ); |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
507 | 507 | * comment_content. See wp_handle_comment_submission(). |
508 | 508 | */ |
509 | 509 | if ( empty( $prepared_comment['comment_content'] ) ) { |
510 | | return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
| 510 | return new WP_Error( 'rest_comment_content_invalid', _l( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
511 | 511 | } |
512 | 512 | |
513 | 513 | // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
533 | 533 | // Honor the discussion setting that requires a name and email address of the comment author. |
534 | 534 | if ( get_option( 'require_name_email' ) ) { |
535 | 535 | if ( empty( $prepared_comment['comment_author'] ) || empty( $prepared_comment['comment_author_email'] ) ) { |
536 | | return new WP_Error( 'rest_comment_author_data_required', __( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) ); |
| 536 | return new WP_Error( 'rest_comment_author_data_required', _l( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) ); |
537 | 537 | } |
538 | 538 | } |
539 | 539 | |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
552 | 552 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_comment ); |
553 | 553 | if ( is_wp_error( $check_comment_lengths ) ) { |
554 | 554 | $error_code = $check_comment_lengths->get_error_code(); |
555 | | return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
| 555 | return new WP_Error( $error_code, _l( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
556 | 556 | } |
557 | 557 | |
558 | 558 | $prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true ); |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
593 | 593 | $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) ); |
594 | 594 | |
595 | 595 | if ( ! $comment_id ) { |
596 | | return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) ); |
| 596 | return new WP_Error( 'rest_comment_failed_create', _l( 'Creating comment failed.' ), array( 'status' => 500 ) ); |
597 | 597 | } |
598 | 598 | |
599 | 599 | if ( isset( $request['status'] ) ) { |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
660 | 660 | } |
661 | 661 | |
662 | 662 | if ( ! $this->check_edit_permission( $comment ) ) { |
663 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 663 | return new WP_Error( 'rest_cannot_edit', _l( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
664 | 664 | } |
665 | 665 | |
666 | 666 | return true; |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
684 | 684 | $id = $comment->comment_ID; |
685 | 685 | |
686 | 686 | if ( isset( $request['type'] ) && get_comment_type( $id ) !== $request['type'] ) { |
687 | | return new WP_Error( 'rest_comment_invalid_type', __( 'Sorry, you are not allowed to change the comment type.' ), array( 'status' => 404 ) ); |
| 687 | return new WP_Error( 'rest_comment_invalid_type', _l( 'Sorry, you are not allowed to change the comment type.' ), array( 'status' => 404 ) ); |
688 | 688 | } |
689 | 689 | |
690 | 690 | $prepared_args = $this->prepare_item_for_database( $request ); |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
696 | 696 | if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
697 | 697 | $post = get_post( $prepared_args['comment_post_ID'] ); |
698 | 698 | if ( empty( $post ) ) { |
699 | | return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) ); |
| 699 | return new WP_Error( 'rest_comment_invalid_post_id', _l( 'Invalid post ID.' ), array( 'status' => 403 ) ); |
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
705 | 705 | $change = $this->handle_status_param( $request['status'], $id ); |
706 | 706 | |
707 | 707 | if ( ! $change ) { |
708 | | return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment status failed.' ), array( 'status' => 500 ) ); |
| 708 | return new WP_Error( 'rest_comment_failed_edit', _l( 'Updating comment status failed.' ), array( 'status' => 500 ) ); |
709 | 709 | } |
710 | 710 | } elseif ( ! empty( $prepared_args ) ) { |
711 | 711 | if ( is_wp_error( $prepared_args ) ) { |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
713 | 713 | } |
714 | 714 | |
715 | 715 | if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
716 | | return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
| 716 | return new WP_Error( 'rest_comment_content_invalid', _l( 'Invalid comment content.' ), array( 'status' => 400 ) ); |
717 | 717 | } |
718 | 718 | |
719 | 719 | $prepared_args['comment_ID'] = $id; |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
721 | 721 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
722 | 722 | if ( is_wp_error( $check_comment_lengths ) ) { |
723 | 723 | $error_code = $check_comment_lengths->get_error_code(); |
724 | | return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
| 724 | return new WP_Error( $error_code, _l( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
725 | 725 | } |
726 | 726 | |
727 | 727 | $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); |
728 | 728 | |
729 | 729 | if ( false === $updated ) { |
730 | | return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); |
| 730 | return new WP_Error( 'rest_comment_failed_edit', _l( 'Updating comment failed.' ), array( 'status' => 500 ) ); |
731 | 731 | } |
732 | 732 | |
733 | 733 | if ( isset( $request['status'] ) ) { |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
779 | 779 | } |
780 | 780 | |
781 | 781 | if ( ! $this->check_edit_permission( $comment ) ) { |
782 | | return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 782 | return new WP_Error( 'rest_cannot_delete', _l( 'Sorry, you are not allowed to delete this comment.' ), array( 'status' => rest_authorization_required_code() ) ); |
783 | 783 | } |
784 | 784 | return true; |
785 | 785 | } |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
823 | 823 | } else { |
824 | 824 | // If this type doesn't support trashing, error out. |
825 | 825 | if ( ! $supports_trash ) { |
826 | | return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
| 826 | return new WP_Error( 'rest_trash_not_supported', _l( 'The comment does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
827 | 827 | } |
828 | 828 | |
829 | 829 | if ( 'trash' === $comment->comment_approved ) { |
830 | | return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) ); |
| 830 | return new WP_Error( 'rest_already_trashed', _l( 'The comment has already been trashed.' ), array( 'status' => 410 ) ); |
831 | 831 | } |
832 | 832 | |
833 | 833 | $result = wp_trash_comment( $comment->comment_ID ); |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
836 | 836 | } |
837 | 837 | |
838 | 838 | if ( ! $result ) { |
839 | | return new WP_Error( 'rest_cannot_delete', __( 'The comment cannot be deleted.' ), array( 'status' => 500 ) ); |
| 839 | return new WP_Error( 'rest_cannot_delete', _l( 'The comment cannot be deleted.' ), array( 'status' => 500 ) ); |
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1092 | 1092 | $prepared_comment['comment_author_email'] = $user->user_email; |
1093 | 1093 | $prepared_comment['comment_author_url'] = $user->user_url; |
1094 | 1094 | } else { |
1095 | | return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); |
| 1095 | return new WP_Error( 'rest_comment_author_invalid', _l( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); |
1096 | 1096 | } |
1097 | 1097 | } |
1098 | 1098 | |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1164 | 1164 | 'type' => 'object', |
1165 | 1165 | 'properties' => array( |
1166 | 1166 | 'id' => array( |
1167 | | 'description' => __( 'Unique identifier for the object.' ), |
| 1167 | 'description' => _l( 'Unique identifier for the object.' ), |
1168 | 1168 | 'type' => 'integer', |
1169 | 1169 | 'context' => array( 'view', 'edit', 'embed' ), |
1170 | 1170 | 'readonly' => true, |
1171 | 1171 | ), |
1172 | 1172 | 'author' => array( |
1173 | | 'description' => __( 'The ID of the user object, if author was a user.' ), |
| 1173 | 'description' => _l( 'The ID of the user object, if author was a user.' ), |
1174 | 1174 | 'type' => 'integer', |
1175 | 1175 | 'context' => array( 'view', 'edit', 'embed' ), |
1176 | 1176 | ), |
1177 | 1177 | 'author_email' => array( |
1178 | | 'description' => __( 'Email address for the object author.' ), |
| 1178 | 'description' => _l( 'Email address for the object author.' ), |
1179 | 1179 | 'type' => 'string', |
1180 | 1180 | 'format' => 'email', |
1181 | 1181 | 'context' => array( 'edit' ), |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1185 | 1185 | ), |
1186 | 1186 | ), |
1187 | 1187 | 'author_ip' => array( |
1188 | | 'description' => __( 'IP address for the object author.' ), |
| 1188 | 'description' => _l( 'IP address for the object author.' ), |
1189 | 1189 | 'type' => 'string', |
1190 | 1190 | 'format' => 'ip', |
1191 | 1191 | 'context' => array( 'edit' ), |
1192 | 1192 | ), |
1193 | 1193 | 'author_name' => array( |
1194 | | 'description' => __( 'Display name for the object author.' ), |
| 1194 | 'description' => _l( 'Display name for the object author.' ), |
1195 | 1195 | 'type' => 'string', |
1196 | 1196 | 'context' => array( 'view', 'edit', 'embed' ), |
1197 | 1197 | 'arg_options' => array( |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1199 | 1199 | ), |
1200 | 1200 | ), |
1201 | 1201 | 'author_url' => array( |
1202 | | 'description' => __( 'URL for the object author.' ), |
| 1202 | 'description' => _l( 'URL for the object author.' ), |
1203 | 1203 | 'type' => 'string', |
1204 | 1204 | 'format' => 'uri', |
1205 | 1205 | 'context' => array( 'view', 'edit', 'embed' ), |
1206 | 1206 | ), |
1207 | 1207 | 'author_user_agent' => array( |
1208 | | 'description' => __( 'User agent for the object author.' ), |
| 1208 | 'description' => _l( 'User agent for the object author.' ), |
1209 | 1209 | 'type' => 'string', |
1210 | 1210 | 'context' => array( 'edit' ), |
1211 | 1211 | 'arg_options' => array( |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1213 | 1213 | ), |
1214 | 1214 | ), |
1215 | 1215 | 'content' => array( |
1216 | | 'description' => __( 'The content for the object.' ), |
| 1216 | 'description' => _l( 'The content for the object.' ), |
1217 | 1217 | 'type' => 'object', |
1218 | 1218 | 'context' => array( 'view', 'edit', 'embed' ), |
1219 | 1219 | 'arg_options' => array( |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1221 | 1221 | ), |
1222 | 1222 | 'properties' => array( |
1223 | 1223 | 'raw' => array( |
1224 | | 'description' => __( 'Content for the object, as it exists in the database.' ), |
| 1224 | 'description' => _l( 'Content for the object, as it exists in the database.' ), |
1225 | 1225 | 'type' => 'string', |
1226 | 1226 | 'context' => array( 'edit' ), |
1227 | 1227 | ), |
1228 | 1228 | 'rendered' => array( |
1229 | | 'description' => __( 'HTML content for the object, transformed for display.' ), |
| 1229 | 'description' => _l( 'HTML content for the object, transformed for display.' ), |
1230 | 1230 | 'type' => 'string', |
1231 | 1231 | 'context' => array( 'view', 'edit', 'embed' ), |
1232 | 1232 | 'readonly' => true, |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1234 | 1234 | ), |
1235 | 1235 | ), |
1236 | 1236 | 'date' => array( |
1237 | | 'description' => __( "The date the object was published, in the site's timezone." ), |
| 1237 | 'description' => _l( "The date the object was published, in the site's timezone." ), |
1238 | 1238 | 'type' => 'string', |
1239 | 1239 | 'format' => 'date-time', |
1240 | 1240 | 'context' => array( 'view', 'edit', 'embed' ), |
1241 | 1241 | ), |
1242 | 1242 | 'date_gmt' => array( |
1243 | | 'description' => __( 'The date the object was published, as GMT.' ), |
| 1243 | 'description' => _l( 'The date the object was published, as GMT.' ), |
1244 | 1244 | 'type' => 'string', |
1245 | 1245 | 'format' => 'date-time', |
1246 | 1246 | 'context' => array( 'view', 'edit' ), |
1247 | 1247 | ), |
1248 | 1248 | 'link' => array( |
1249 | | 'description' => __( 'URL to the object.' ), |
| 1249 | 'description' => _l( 'URL to the object.' ), |
1250 | 1250 | 'type' => 'string', |
1251 | 1251 | 'format' => 'uri', |
1252 | 1252 | 'context' => array( 'view', 'edit', 'embed' ), |
1253 | 1253 | 'readonly' => true, |
1254 | 1254 | ), |
1255 | 1255 | 'parent' => array( |
1256 | | 'description' => __( 'The ID for the parent of the object.' ), |
| 1256 | 'description' => _l( 'The ID for the parent of the object.' ), |
1257 | 1257 | 'type' => 'integer', |
1258 | 1258 | 'context' => array( 'view', 'edit', 'embed' ), |
1259 | 1259 | 'default' => 0, |
1260 | 1260 | ), |
1261 | 1261 | 'post' => array( |
1262 | | 'description' => __( 'The ID of the associated post object.' ), |
| 1262 | 'description' => _l( 'The ID of the associated post object.' ), |
1263 | 1263 | 'type' => 'integer', |
1264 | 1264 | 'context' => array( 'view', 'edit' ), |
1265 | 1265 | 'default' => 0, |
1266 | 1266 | ), |
1267 | 1267 | 'status' => array( |
1268 | | 'description' => __( 'State of the object.' ), |
| 1268 | 'description' => _l( 'State of the object.' ), |
1269 | 1269 | 'type' => 'string', |
1270 | 1270 | 'context' => array( 'view', 'edit' ), |
1271 | 1271 | 'arg_options' => array( |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1273 | 1273 | ), |
1274 | 1274 | ), |
1275 | 1275 | 'type' => array( |
1276 | | 'description' => __( 'Type of Comment for the object.' ), |
| 1276 | 'description' => _l( 'Type of Comment for the object.' ), |
1277 | 1277 | 'type' => 'string', |
1278 | 1278 | 'context' => array( 'view', 'edit', 'embed' ), |
1279 | 1279 | 'readonly' => true, |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1288 | 1288 | foreach ( $avatar_sizes as $size ) { |
1289 | 1289 | $avatar_properties[ $size ] = array( |
1290 | 1290 | /* translators: %d: avatar image size in pixels */ |
1291 | | 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ), |
| 1291 | 'description' => sprintf( _l( 'Avatar URL with image size of %d pixels.' ), $size ), |
1292 | 1292 | 'type' => 'string', |
1293 | 1293 | 'format' => 'uri', |
1294 | 1294 | 'context' => array( 'embed', 'view', 'edit' ), |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1296 | 1296 | } |
1297 | 1297 | |
1298 | 1298 | $schema['properties']['author_avatar_urls'] = array( |
1299 | | 'description' => __( 'Avatar URLs for the object author.' ), |
| 1299 | 'description' => _l( 'Avatar URLs for the object author.' ), |
1300 | 1300 | 'type' => 'object', |
1301 | 1301 | 'context' => array( 'view', 'edit', 'embed' ), |
1302 | 1302 | 'readonly' => true, |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1323 | 1323 | $query_params['context']['default'] = 'view'; |
1324 | 1324 | |
1325 | 1325 | $query_params['after'] = array( |
1326 | | 'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ), |
| 1326 | 'description' => _l( 'Limit response to comments published after a given ISO8601 compliant date.' ), |
1327 | 1327 | 'type' => 'string', |
1328 | 1328 | 'format' => 'date-time', |
1329 | 1329 | ); |
1330 | 1330 | |
1331 | 1331 | $query_params['author'] = array( |
1332 | | 'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), |
| 1332 | 'description' => _l( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), |
1333 | 1333 | 'type' => 'array', |
1334 | 1334 | 'items' => array( |
1335 | 1335 | 'type' => 'integer', |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1337 | 1337 | ); |
1338 | 1338 | |
1339 | 1339 | $query_params['author_exclude'] = array( |
1340 | | 'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), |
| 1340 | 'description' => _l( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), |
1341 | 1341 | 'type' => 'array', |
1342 | 1342 | 'items' => array( |
1343 | 1343 | 'type' => 'integer', |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1346 | 1346 | |
1347 | 1347 | $query_params['author_email'] = array( |
1348 | 1348 | 'default' => null, |
1349 | | 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), |
| 1349 | 'description' => _l( 'Limit result set to that from a specific author email. Requires authorization.' ), |
1350 | 1350 | 'format' => 'email', |
1351 | 1351 | 'type' => 'string', |
1352 | 1352 | ); |
1353 | 1353 | |
1354 | 1354 | $query_params['before'] = array( |
1355 | | 'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ), |
| 1355 | 'description' => _l( 'Limit response to comments published before a given ISO8601 compliant date.' ), |
1356 | 1356 | 'type' => 'string', |
1357 | 1357 | 'format' => 'date-time', |
1358 | 1358 | ); |
1359 | 1359 | |
1360 | 1360 | $query_params['exclude'] = array( |
1361 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| 1361 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
1362 | 1362 | 'type' => 'array', |
1363 | 1363 | 'items' => array( |
1364 | 1364 | 'type' => 'integer', |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1367 | 1367 | ); |
1368 | 1368 | |
1369 | 1369 | $query_params['include'] = array( |
1370 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| 1370 | 'description' => _l( 'Limit result set to specific IDs.' ), |
1371 | 1371 | 'type' => 'array', |
1372 | 1372 | 'items' => array( |
1373 | 1373 | 'type' => 'integer', |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1376 | 1376 | ); |
1377 | 1377 | |
1378 | 1378 | $query_params['offset'] = array( |
1379 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| 1379 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
1380 | 1380 | 'type' => 'integer', |
1381 | 1381 | ); |
1382 | 1382 | |
1383 | 1383 | $query_params['order'] = array( |
1384 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| 1384 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
1385 | 1385 | 'type' => 'string', |
1386 | 1386 | 'default' => 'desc', |
1387 | 1387 | 'enum' => array( |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1391 | 1391 | ); |
1392 | 1392 | |
1393 | 1393 | $query_params['orderby'] = array( |
1394 | | 'description' => __( 'Sort collection by object attribute.' ), |
| 1394 | 'description' => _l( 'Sort collection by object attribute.' ), |
1395 | 1395 | 'type' => 'string', |
1396 | 1396 | 'default' => 'date_gmt', |
1397 | 1397 | 'enum' => array( |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1407 | 1407 | |
1408 | 1408 | $query_params['parent'] = array( |
1409 | 1409 | 'default' => array(), |
1410 | | 'description' => __( 'Limit result set to comments of specific parent IDs.' ), |
| 1410 | 'description' => _l( 'Limit result set to comments of specific parent 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['parent_exclude'] = array( |
1418 | 1418 | 'default' => array(), |
1419 | | 'description' => __( 'Ensure result set excludes specific parent IDs.' ), |
| 1419 | 'description' => _l( 'Ensure result set excludes specific parent IDs.' ), |
1420 | 1420 | 'type' => 'array', |
1421 | 1421 | 'items' => array( |
1422 | 1422 | 'type' => 'integer', |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1425 | 1425 | |
1426 | 1426 | $query_params['post'] = array( |
1427 | 1427 | 'default' => array(), |
1428 | | 'description' => __( 'Limit result set to comments assigned to specific post IDs.' ), |
| 1428 | 'description' => _l( 'Limit result set to comments assigned to specific post IDs.' ), |
1429 | 1429 | 'type' => 'array', |
1430 | 1430 | 'items' => array( |
1431 | 1431 | 'type' => 'integer', |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1434 | 1434 | |
1435 | 1435 | $query_params['status'] = array( |
1436 | 1436 | 'default' => 'approve', |
1437 | | 'description' => __( 'Limit result set to comments assigned a specific status. Requires authorization.' ), |
| 1437 | 'description' => _l( 'Limit result set to comments assigned a specific status. Requires authorization.' ), |
1438 | 1438 | 'sanitize_callback' => 'sanitize_key', |
1439 | 1439 | 'type' => 'string', |
1440 | 1440 | 'validate_callback' => 'rest_validate_request_arg', |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
1442 | 1442 | |
1443 | 1443 | $query_params['type'] = array( |
1444 | 1444 | 'default' => 'comment', |
1445 | | 'description' => __( 'Limit result set to comments assigned a specific type. Requires authorization.' ), |
| 1445 | 'description' => _l( 'Limit result set to comments assigned a specific type. Requires authorization.' ), |
1446 | 1446 | 'sanitize_callback' => 'sanitize_key', |
1447 | 1447 | 'type' => 'string', |
1448 | 1448 | 'validate_callback' => 'rest_validate_request_arg', |
1449 | 1449 | ); |
1450 | 1450 | |
1451 | 1451 | $query_params['password'] = array( |
1452 | | 'description' => __( 'The password for the post if it is password protected.' ), |
| 1452 | 'description' => _l( 'The password for the post if it is password protected.' ), |
1453 | 1453 | 'type' => 'string', |
1454 | 1454 | ); |
1455 | 1455 | |
-
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 b6c8ac42ac..8c2afbe1a4 100644
|
|
abstract class WP_REST_Controller { |
39 | 39 | * @access public |
40 | 40 | */ |
41 | 41 | public function register_routes() { |
42 | | _doing_it_wrong( 'WP_REST_Controller::register_routes', __( 'The register_routes() method must be overridden' ), '4.7' ); |
| 42 | _doing_it_wrong( 'WP_REST_Controller::register_routes', _l( 'The register_routes() method must be overridden' ), '4.7' ); |
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
… |
… |
abstract class WP_REST_Controller { |
52 | 52 | * @return WP_Error|bool True if the request has read access, WP_Error object otherwise. |
53 | 53 | */ |
54 | 54 | public function get_items_permissions_check( $request ) { |
55 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 55 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
… |
… |
abstract class WP_REST_Controller { |
65 | 65 | * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
66 | 66 | */ |
67 | 67 | public function get_items( $request ) { |
68 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 68 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
… |
… |
abstract class WP_REST_Controller { |
78 | 78 | * @return WP_Error|bool True if the request has read access for the item, WP_Error object otherwise. |
79 | 79 | */ |
80 | 80 | public function get_item_permissions_check( $request ) { |
81 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 81 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
… |
… |
abstract class WP_REST_Controller { |
91 | 91 | * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
92 | 92 | */ |
93 | 93 | public function get_item( $request ) { |
94 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 94 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
… |
… |
abstract class WP_REST_Controller { |
104 | 104 | * @return WP_Error|bool True if the request has access to create items, WP_Error object otherwise. |
105 | 105 | */ |
106 | 106 | public function create_item_permissions_check( $request ) { |
107 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 107 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
… |
… |
abstract class WP_REST_Controller { |
117 | 117 | * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
118 | 118 | */ |
119 | 119 | public function create_item( $request ) { |
120 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 120 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
… |
… |
abstract class WP_REST_Controller { |
130 | 130 | * @return WP_Error|bool True if the request has access to update the item, WP_Error object otherwise. |
131 | 131 | */ |
132 | 132 | public function update_item_permissions_check( $request ) { |
133 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 133 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
… |
… |
abstract class WP_REST_Controller { |
143 | 143 | * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
144 | 144 | */ |
145 | 145 | public function update_item( $request ) { |
146 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 146 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
… |
… |
abstract class WP_REST_Controller { |
156 | 156 | * @return WP_Error|bool True if the request has access to delete the item, WP_Error object otherwise. |
157 | 157 | */ |
158 | 158 | public function delete_item_permissions_check( $request ) { |
159 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 159 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
… |
… |
abstract class WP_REST_Controller { |
169 | 169 | * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
170 | 170 | */ |
171 | 171 | public function delete_item( $request ) { |
172 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 172 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
… |
… |
abstract class WP_REST_Controller { |
182 | 182 | * @return WP_Error|object The prepared item, or WP_Error object on failure. |
183 | 183 | */ |
184 | 184 | protected function prepare_item_for_database( $request ) { |
185 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 185 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
… |
… |
abstract class WP_REST_Controller { |
196 | 196 | * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
197 | 197 | */ |
198 | 198 | public function prepare_item_for_response( $item, $request ) { |
199 | | return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
| 199 | return new WP_Error( 'invalid-method', sprintf( _l( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
… |
… |
abstract class WP_REST_Controller { |
314 | 314 | return array( |
315 | 315 | 'context' => $this->get_context_param(), |
316 | 316 | 'page' => array( |
317 | | 'description' => __( 'Current page of the collection.' ), |
| 317 | 'description' => _l( 'Current page of the collection.' ), |
318 | 318 | 'type' => 'integer', |
319 | 319 | 'default' => 1, |
320 | 320 | 'sanitize_callback' => 'absint', |
… |
… |
abstract class WP_REST_Controller { |
322 | 322 | 'minimum' => 1, |
323 | 323 | ), |
324 | 324 | 'per_page' => array( |
325 | | 'description' => __( 'Maximum number of items to be returned in result set.' ), |
| 325 | 'description' => _l( 'Maximum number of items to be returned in result set.' ), |
326 | 326 | 'type' => 'integer', |
327 | 327 | 'default' => 10, |
328 | 328 | 'minimum' => 1, |
… |
… |
abstract class WP_REST_Controller { |
331 | 331 | 'validate_callback' => 'rest_validate_request_arg', |
332 | 332 | ), |
333 | 333 | 'search' => array( |
334 | | 'description' => __( 'Limit results to those matching a string.' ), |
| 334 | 'description' => _l( 'Limit results to those matching a string.' ), |
335 | 335 | 'type' => 'string', |
336 | 336 | 'sanitize_callback' => 'sanitize_text_field', |
337 | 337 | 'validate_callback' => 'rest_validate_request_arg', |
… |
… |
abstract class WP_REST_Controller { |
352 | 352 | */ |
353 | 353 | public function get_context_param( $args = array() ) { |
354 | 354 | $param_details = array( |
355 | | 'description' => __( 'Scope under which the request is made; determines fields present in response.' ), |
| 355 | 'description' => _l( 'Scope under which the request is made; determines fields present in response.' ), |
356 | 356 | 'type' => 'string', |
357 | 357 | 'sanitize_callback' => 'sanitize_key', |
358 | 358 | '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 59575d566c..89c5013bff 100644
|
|
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
50 | 50 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<status>[\w-]+)', array( |
51 | 51 | 'args' => array( |
52 | 52 | 'status' => array( |
53 | | 'description' => __( 'An alphanumeric identifier for the status.' ), |
| 53 | 'description' => _l( 'An alphanumeric identifier for the status.' ), |
54 | 54 | 'type' => 'string', |
55 | 55 | ), |
56 | 56 | ), |
… |
… |
class WP_REST_Post_Statuses_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 edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 87 | 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() ) ); |
88 | 88 | } |
89 | 89 | |
90 | 90 | return true; |
… |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
131 | 131 | $status = get_post_status_object( $request['status'] ); |
132 | 132 | |
133 | 133 | if ( empty( $status ) ) { |
134 | | return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); |
| 134 | return new WP_Error( 'rest_status_invalid', _l( 'Invalid status.' ), array( 'status' => 404 ) ); |
135 | 135 | } |
136 | 136 | |
137 | 137 | $check = $this->check_read_permission( $status ); |
138 | 138 | |
139 | 139 | if ( ! $check ) { |
140 | | return new WP_Error( 'rest_cannot_read_status', __( 'Cannot view status.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 140 | return new WP_Error( 'rest_cannot_read_status', _l( 'Cannot view status.' ), array( 'status' => rest_authorization_required_code() ) ); |
141 | 141 | } |
142 | 142 | |
143 | 143 | return true; |
… |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
183 | 183 | $obj = get_post_status_object( $request['status'] ); |
184 | 184 | |
185 | 185 | if ( empty( $obj ) ) { |
186 | | return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); |
| 186 | return new WP_Error( 'rest_status_invalid', _l( 'Invalid status.' ), array( 'status' => 404 ) ); |
187 | 187 | } |
188 | 188 | |
189 | 189 | $data = $this->prepare_item_for_response( $obj, $request ); |
… |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { |
254 | 254 | 'type' => 'object', |
255 | 255 | 'properties' => array( |
256 | 256 | 'name' => array( |
257 | | 'description' => __( 'The title for the status.' ), |
| 257 | 'description' => _l( 'The title for the status.' ), |
258 | 258 | 'type' => 'string', |
259 | 259 | 'context' => array( 'embed', 'view', 'edit' ), |
260 | 260 | 'readonly' => true, |
261 | 261 | ), |
262 | 262 | 'private' => array( |
263 | | 'description' => __( 'Whether posts with this status should be private.' ), |
| 263 | 'description' => _l( 'Whether posts with this status should be private.' ), |
264 | 264 | 'type' => 'boolean', |
265 | 265 | 'context' => array( 'edit' ), |
266 | 266 | 'readonly' => true, |
267 | 267 | ), |
268 | 268 | 'protected' => array( |
269 | | 'description' => __( 'Whether posts with this status should be protected.' ), |
| 269 | 'description' => _l( 'Whether posts with this status should be protected.' ), |
270 | 270 | 'type' => 'boolean', |
271 | 271 | 'context' => array( 'edit' ), |
272 | 272 | 'readonly' => true, |
273 | 273 | ), |
274 | 274 | 'public' => array( |
275 | | 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ), |
| 275 | 'description' => _l( 'Whether posts of this status should be shown in the front end of the site.' ), |
276 | 276 | 'type' => 'boolean', |
277 | 277 | 'context' => array( 'view', 'edit' ), |
278 | 278 | 'readonly' => true, |
279 | 279 | ), |
280 | 280 | 'queryable' => array( |
281 | | 'description' => __( 'Whether posts with this status should be publicly-queryable.' ), |
| 281 | 'description' => _l( 'Whether posts with this status should be publicly-queryable.' ), |
282 | 282 | 'type' => 'boolean', |
283 | 283 | 'context' => array( 'view', 'edit' ), |
284 | 284 | 'readonly' => true, |
285 | 285 | ), |
286 | 286 | 'show_in_list' => array( |
287 | | 'description' => __( 'Whether to include posts in the edit listing for their post type.' ), |
| 287 | 'description' => _l( 'Whether to include posts in the edit listing for their post type.' ), |
288 | 288 | 'type' => 'boolean', |
289 | 289 | 'context' => array( 'edit' ), |
290 | 290 | 'readonly' => true, |
291 | 291 | ), |
292 | 292 | 'slug' => array( |
293 | | 'description' => __( 'An alphanumeric identifier for the status.' ), |
| 293 | 'description' => _l( 'An alphanumeric identifier for the status.' ), |
294 | 294 | 'type' => 'string', |
295 | 295 | 'context' => array( 'embed', 'view', 'edit' ), |
296 | 296 | '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 69d221be75..181108221e 100644
|
|
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
50 | 50 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<type>[\w-]+)', array( |
51 | 51 | 'args' => array( |
52 | 52 | 'type' => array( |
53 | | 'description' => __( 'An alphanumeric identifier for the post type.' ), |
| 53 | 'description' => _l( 'An alphanumeric identifier for the post type.' ), |
54 | 54 | 'type' => 'string', |
55 | 55 | ), |
56 | 56 | ), |
… |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | | 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() ) ); |
| 85 | 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() ) ); |
86 | 86 | } |
87 | 87 | |
88 | 88 | return true; |
… |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
125 | 125 | $obj = get_post_type_object( $request['type'] ); |
126 | 126 | |
127 | 127 | if ( empty( $obj ) ) { |
128 | | return new WP_Error( 'rest_type_invalid', __( 'Invalid post type.' ), array( 'status' => 404 ) ); |
| 128 | return new WP_Error( 'rest_type_invalid', _l( 'Invalid post type.' ), array( 'status' => 404 ) ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | if ( empty( $obj->show_in_rest ) ) { |
132 | | return new WP_Error( 'rest_cannot_read_type', __( 'Cannot view post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 132 | return new WP_Error( 'rest_cannot_read_type', _l( 'Cannot view post type.' ), array( 'status' => rest_authorization_required_code() ) ); |
133 | 133 | } |
134 | 134 | |
135 | 135 | if ( 'edit' === $request['context'] && ! current_user_can( $obj->cap->edit_posts ) ) { |
136 | | 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() ) ); |
| 136 | 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() ) ); |
137 | 137 | } |
138 | 138 | |
139 | 139 | $data = $this->prepare_item_for_response( $obj, $request ); |
… |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
213 | 213 | 'type' => 'object', |
214 | 214 | 'properties' => array( |
215 | 215 | 'capabilities' => array( |
216 | | 'description' => __( 'All capabilities used by the post type.' ), |
| 216 | 'description' => _l( 'All capabilities used by the post type.' ), |
217 | 217 | 'type' => 'object', |
218 | 218 | 'context' => array( 'edit' ), |
219 | 219 | 'readonly' => true, |
220 | 220 | ), |
221 | 221 | 'description' => array( |
222 | | 'description' => __( 'A human-readable description of the post type.' ), |
| 222 | 'description' => _l( 'A human-readable description of the post type.' ), |
223 | 223 | 'type' => 'string', |
224 | 224 | 'context' => array( 'view', 'edit' ), |
225 | 225 | 'readonly' => true, |
226 | 226 | ), |
227 | 227 | 'hierarchical' => array( |
228 | | 'description' => __( 'Whether or not the post type should have children.' ), |
| 228 | 'description' => _l( 'Whether or not the post type should have children.' ), |
229 | 229 | 'type' => 'boolean', |
230 | 230 | 'context' => array( 'view', 'edit' ), |
231 | 231 | 'readonly' => true, |
232 | 232 | ), |
233 | 233 | 'labels' => array( |
234 | | 'description' => __( 'Human-readable labels for the post type for various contexts.' ), |
| 234 | 'description' => _l( 'Human-readable labels for the post type for various contexts.' ), |
235 | 235 | 'type' => 'object', |
236 | 236 | 'context' => array( 'edit' ), |
237 | 237 | 'readonly' => true, |
238 | 238 | ), |
239 | 239 | 'name' => array( |
240 | | 'description' => __( 'The title for the post type.' ), |
| 240 | 'description' => _l( 'The title for the post type.' ), |
241 | 241 | 'type' => 'string', |
242 | 242 | 'context' => array( 'view', 'edit', 'embed' ), |
243 | 243 | 'readonly' => true, |
244 | 244 | ), |
245 | 245 | 'slug' => array( |
246 | | 'description' => __( 'An alphanumeric identifier for the post type.' ), |
| 246 | 'description' => _l( 'An alphanumeric identifier for the post type.' ), |
247 | 247 | 'type' => 'string', |
248 | 248 | 'context' => array( 'view', 'edit', 'embed' ), |
249 | 249 | 'readonly' => true, |
250 | 250 | ), |
251 | 251 | 'supports' => array( |
252 | | 'description' => __( 'All features, supported by the post type.' ), |
| 252 | 'description' => _l( 'All features, supported by the post type.' ), |
253 | 253 | 'type' => 'object', |
254 | 254 | 'context' => array( 'edit' ), |
255 | 255 | 'readonly' => true, |
256 | 256 | ), |
257 | 257 | 'taxonomies' => array( |
258 | | 'description' => __( 'Taxonomies associated with post type.' ), |
| 258 | 'description' => _l( 'Taxonomies associated with post type.' ), |
259 | 259 | 'type' => 'array', |
260 | 260 | 'items' => array( |
261 | 261 | 'type' => 'string', |
… |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller { |
264 | 264 | 'readonly' => true, |
265 | 265 | ), |
266 | 266 | 'rest_base' => array( |
267 | | 'description' => __( 'REST base route for the post type.' ), |
| 267 | 'description' => _l( 'REST base route for the post type.' ), |
268 | 268 | 'type' => 'string', |
269 | 269 | 'context' => array( 'view', 'edit', 'embed' ), |
270 | 270 | '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 39593cbe3e..e1f722556c 100644
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
83 | 83 | ); |
84 | 84 | if ( isset( $schema['properties']['password'] ) ) { |
85 | 85 | $get_item_args['password'] = array( |
86 | | 'description' => __( 'The password for the post if it is password protected.' ), |
| 86 | 'description' => _l( 'The password for the post if it is password protected.' ), |
87 | 87 | 'type' => 'string', |
88 | 88 | ); |
89 | 89 | } |
90 | 90 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
91 | 91 | 'args' => array( |
92 | 92 | 'id' => array( |
93 | | 'description' => __( 'Unique identifier for the object.' ), |
| 93 | 'description' => _l( 'Unique identifier for the object.' ), |
94 | 94 | 'type' => 'integer', |
95 | 95 | ), |
96 | 96 | ), |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
114 | 114 | 'force' => array( |
115 | 115 | 'type' => 'boolean', |
116 | 116 | 'default' => false, |
117 | | 'description' => __( 'Whether to bypass trash and force deletion.' ), |
| 117 | 'description' => _l( 'Whether to bypass trash and force deletion.' ), |
118 | 118 | ), |
119 | 119 | ), |
120 | 120 | ), |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
136 | 136 | $post_type = get_post_type_object( $this->post_type ); |
137 | 137 | |
138 | 138 | if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) { |
139 | | 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() ) ); |
| 139 | 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() ) ); |
140 | 140 | } |
141 | 141 | |
142 | 142 | return true; |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
155 | 155 | |
156 | 156 | // Ensure a search string is set in case the orderby is set to 'relevance'. |
157 | 157 | if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) { |
158 | | return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); |
| 158 | return new WP_Error( 'rest_no_search_term_defined', _l( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); |
159 | 159 | } |
160 | 160 | |
161 | 161 | // Ensure an include parameter is set in case the orderby is set to 'include'. |
162 | 162 | if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) { |
163 | | return new WP_Error( 'rest_orderby_include_missing_include', __( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) ); |
| 163 | return new WP_Error( 'rest_orderby_include_missing_include', _l( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | // Retrieve the list of registered collection query parameters. |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
332 | 332 | $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] ); |
333 | 333 | |
334 | 334 | if ( $page > $max_pages && $total_posts > 0 ) { |
335 | | return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); |
| 335 | 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 ) ); |
336 | 336 | } |
337 | 337 | |
338 | 338 | $response = rest_ensure_response( $posts ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
372 | 372 | * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. |
373 | 373 | */ |
374 | 374 | protected function get_post( $id ) { |
375 | | $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
| 375 | $error = new WP_Error( 'rest_post_invalid_id', _l( 'Invalid post ID.' ), array( 'status' => 404 ) ); |
376 | 376 | if ( (int) $id <= 0 ) { |
377 | 377 | return $error; |
378 | 378 | } |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
401 | 401 | } |
402 | 402 | |
403 | 403 | if ( 'edit' === $request['context'] && $post && ! $this->check_update_permission( $post ) ) { |
404 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 404 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
405 | 405 | } |
406 | 406 | |
407 | 407 | if ( $post && ! empty( $request['password'] ) ) { |
408 | 408 | // Check post password, and return error if invalid. |
409 | 409 | if ( ! hash_equals( $post->post_password, $request['password'] ) ) { |
410 | | return new WP_Error( 'rest_post_incorrect_password', __( 'Incorrect post password.' ), array( 'status' => 403 ) ); |
| 410 | return new WP_Error( 'rest_post_incorrect_password', _l( 'Incorrect post password.' ), array( 'status' => 403 ) ); |
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
492 | 492 | */ |
493 | 493 | public function create_item_permissions_check( $request ) { |
494 | 494 | if ( ! empty( $request['id'] ) ) { |
495 | | return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
| 495 | return new WP_Error( 'rest_post_exists', _l( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
496 | 496 | } |
497 | 497 | |
498 | 498 | $post_type = get_post_type_object( $this->post_type ); |
499 | 499 | |
500 | 500 | if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
501 | | 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() ) ); |
| 501 | 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() ) ); |
502 | 502 | } |
503 | 503 | |
504 | 504 | if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
505 | | return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 505 | return new WP_Error( 'rest_cannot_assign_sticky', _l( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
506 | 506 | } |
507 | 507 | |
508 | 508 | if ( ! current_user_can( $post_type->cap->create_posts ) ) { |
509 | | return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 509 | 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() ) ); |
510 | 510 | } |
511 | 511 | |
512 | 512 | if ( ! $this->check_assign_terms_permission( $request ) ) { |
513 | | return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 513 | 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() ) ); |
514 | 514 | } |
515 | 515 | |
516 | 516 | return true; |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
527 | 527 | */ |
528 | 528 | public function create_item( $request ) { |
529 | 529 | if ( ! empty( $request['id'] ) ) { |
530 | | return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
| 530 | return new WP_Error( 'rest_post_exists', _l( 'Cannot create existing post.' ), array( 'status' => 400 ) ); |
531 | 531 | } |
532 | 532 | |
533 | 533 | $prepared_post = $this->prepare_item_for_database( $request ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
638 | 638 | $post_type = get_post_type_object( $this->post_type ); |
639 | 639 | |
640 | 640 | if ( $post && ! $this->check_update_permission( $post ) ) { |
641 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 641 | return new WP_Error( 'rest_cannot_edit', _l( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
642 | 642 | } |
643 | 643 | |
644 | 644 | if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
645 | | 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() ) ); |
| 645 | 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() ) ); |
646 | 646 | } |
647 | 647 | |
648 | 648 | if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
649 | | return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 649 | return new WP_Error( 'rest_cannot_assign_sticky', _l( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); |
650 | 650 | } |
651 | 651 | |
652 | 652 | if ( ! $this->check_assign_terms_permission( $request ) ) { |
653 | | return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 653 | 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() ) ); |
654 | 654 | } |
655 | 655 | |
656 | 656 | return true; |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
760 | 760 | } |
761 | 761 | |
762 | 762 | if ( $post && ! $this->check_delete_permission( $post ) ) { |
763 | | return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 763 | return new WP_Error( 'rest_cannot_delete', _l( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
764 | 764 | } |
765 | 765 | |
766 | 766 | return true; |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
805 | 805 | $supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post ); |
806 | 806 | |
807 | 807 | if ( ! $this->check_delete_permission( $post ) ) { |
808 | | return new WP_Error( 'rest_user_cannot_delete_post', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 808 | 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() ) ); |
809 | 809 | } |
810 | 810 | |
811 | 811 | $request->set_param( 'context', 'edit' ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
820 | 820 | } else { |
821 | 821 | // If we don't support trashing for this type, error out. |
822 | 822 | if ( ! $supports_trash ) { |
823 | | return new WP_Error( 'rest_trash_not_supported', __( 'The post does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
| 823 | return new WP_Error( 'rest_trash_not_supported', _l( 'The post does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
824 | 824 | } |
825 | 825 | |
826 | 826 | // Otherwise, only trash if we haven't already. |
827 | 827 | if ( 'trash' === $post->post_status ) { |
828 | | return new WP_Error( 'rest_already_trashed', __( 'The post has already been deleted.' ), array( 'status' => 410 ) ); |
| 828 | return new WP_Error( 'rest_already_trashed', _l( 'The post has already been deleted.' ), array( 'status' => 410 ) ); |
829 | 829 | } |
830 | 830 | |
831 | 831 | // (Note that internally this falls through to `wp_delete_post` if |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
836 | 836 | } |
837 | 837 | |
838 | 838 | if ( ! $result ) { |
839 | | return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
| 839 | return new WP_Error( 'rest_cannot_delete', _l( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1031 | 1031 | $user_obj = get_userdata( $post_author ); |
1032 | 1032 | |
1033 | 1033 | if ( ! $user_obj ) { |
1034 | | return new WP_Error( 'rest_invalid_author', __( 'Invalid author ID.' ), array( 'status' => 400 ) ); |
| 1034 | return new WP_Error( 'rest_invalid_author', _l( 'Invalid author ID.' ), array( 'status' => 400 ) ); |
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1044 | 1044 | |
1045 | 1045 | if ( '' !== $request['password'] ) { |
1046 | 1046 | if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { |
1047 | | return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) ); |
| 1047 | return new WP_Error( 'rest_invalid_field', _l( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) ); |
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) { |
1051 | | return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) ); |
| 1051 | return new WP_Error( 'rest_invalid_field', _l( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) ); |
1052 | 1052 | } |
1053 | 1053 | } |
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { |
1057 | 1057 | if ( ! empty( $prepared_post->ID ) && post_password_required( $prepared_post->ID ) ) { |
1058 | | return new WP_Error( 'rest_invalid_field', __( 'A password protected post can not be set to sticky.' ), array( 'status' => 400 ) ); |
| 1058 | return new WP_Error( 'rest_invalid_field', _l( 'A password protected post can not be set to sticky.' ), array( 'status' => 400 ) ); |
1059 | 1059 | } |
1060 | 1060 | } |
1061 | 1061 | |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1066 | 1066 | } else { |
1067 | 1067 | $parent = get_post( (int) $request['parent'] ); |
1068 | 1068 | if ( empty( $parent ) ) { |
1069 | | return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) ); |
| 1069 | return new WP_Error( 'rest_post_invalid_id', _l( 'Invalid post parent ID.' ), array( 'status' => 400 ) ); |
1070 | 1070 | } |
1071 | 1071 | $prepared_post->post_parent = (int) $parent->ID; |
1072 | 1072 | } |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1120 | 1120 | break; |
1121 | 1121 | case 'private': |
1122 | 1122 | if ( ! current_user_can( $post_type->cap->publish_posts ) ) { |
1123 | | 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() ) ); |
| 1123 | 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() ) ); |
1124 | 1124 | } |
1125 | 1125 | break; |
1126 | 1126 | case 'publish': |
1127 | 1127 | case 'future': |
1128 | 1128 | if ( ! current_user_can( $post_type->cap->publish_posts ) ) { |
1129 | | 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() ) ); |
| 1129 | 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() ) ); |
1130 | 1130 | } |
1131 | 1131 | break; |
1132 | 1132 | default: |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1157 | 1157 | if ( $result ) { |
1158 | 1158 | return true; |
1159 | 1159 | } else { |
1160 | | return new WP_Error( 'rest_invalid_featured_media', __( 'Invalid featured media ID.' ), array( 'status' => 400 ) ); |
| 1160 | return new WP_Error( 'rest_invalid_featured_media', _l( 'Invalid featured media ID.' ), array( 'status' => 400 ) ); |
1161 | 1161 | } |
1162 | 1162 | } else { |
1163 | 1163 | return delete_post_thumbnail( $post_id ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1722 | 1722 | // Base properties for every Post. |
1723 | 1723 | 'properties' => array( |
1724 | 1724 | 'date' => array( |
1725 | | 'description' => __( "The date the object was published, in the site's timezone." ), |
| 1725 | 'description' => _l( "The date the object was published, in the site's timezone." ), |
1726 | 1726 | 'type' => 'string', |
1727 | 1727 | 'format' => 'date-time', |
1728 | 1728 | 'context' => array( 'view', 'edit', 'embed' ), |
1729 | 1729 | ), |
1730 | 1730 | 'date_gmt' => array( |
1731 | | 'description' => __( 'The date the object was published, as GMT.' ), |
| 1731 | 'description' => _l( 'The date the object was published, as GMT.' ), |
1732 | 1732 | 'type' => 'string', |
1733 | 1733 | 'format' => 'date-time', |
1734 | 1734 | 'context' => array( 'view', 'edit' ), |
1735 | 1735 | ), |
1736 | 1736 | 'guid' => array( |
1737 | | 'description' => __( 'The globally unique identifier for the object.' ), |
| 1737 | 'description' => _l( 'The globally unique identifier for the object.' ), |
1738 | 1738 | 'type' => 'object', |
1739 | 1739 | 'context' => array( 'view', 'edit' ), |
1740 | 1740 | 'readonly' => true, |
1741 | 1741 | 'properties' => array( |
1742 | 1742 | 'raw' => array( |
1743 | | 'description' => __( 'GUID for the object, as it exists in the database.' ), |
| 1743 | 'description' => _l( 'GUID for the object, as it exists in the database.' ), |
1744 | 1744 | 'type' => 'string', |
1745 | 1745 | 'context' => array( 'edit' ), |
1746 | 1746 | 'readonly' => true, |
1747 | 1747 | ), |
1748 | 1748 | 'rendered' => array( |
1749 | | 'description' => __( 'GUID for the object, transformed for display.' ), |
| 1749 | 'description' => _l( 'GUID for the object, transformed for display.' ), |
1750 | 1750 | 'type' => 'string', |
1751 | 1751 | 'context' => array( 'view', 'edit' ), |
1752 | 1752 | 'readonly' => true, |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1754 | 1754 | ), |
1755 | 1755 | ), |
1756 | 1756 | 'id' => array( |
1757 | | 'description' => __( 'Unique identifier for the object.' ), |
| 1757 | 'description' => _l( 'Unique identifier for the object.' ), |
1758 | 1758 | 'type' => 'integer', |
1759 | 1759 | 'context' => array( 'view', 'edit', 'embed' ), |
1760 | 1760 | 'readonly' => true, |
1761 | 1761 | ), |
1762 | 1762 | 'link' => array( |
1763 | | 'description' => __( 'URL to the object.' ), |
| 1763 | 'description' => _l( 'URL to the object.' ), |
1764 | 1764 | 'type' => 'string', |
1765 | 1765 | 'format' => 'uri', |
1766 | 1766 | 'context' => array( 'view', 'edit', 'embed' ), |
1767 | 1767 | 'readonly' => true, |
1768 | 1768 | ), |
1769 | 1769 | 'modified' => array( |
1770 | | 'description' => __( "The date the object was last modified, in the site's timezone." ), |
| 1770 | 'description' => _l( "The date the object was last modified, in the site's timezone." ), |
1771 | 1771 | 'type' => 'string', |
1772 | 1772 | 'format' => 'date-time', |
1773 | 1773 | 'context' => array( 'view', 'edit' ), |
1774 | 1774 | 'readonly' => true, |
1775 | 1775 | ), |
1776 | 1776 | 'modified_gmt' => array( |
1777 | | 'description' => __( 'The date the object was last modified, as GMT.' ), |
| 1777 | 'description' => _l( 'The date the object was last modified, as GMT.' ), |
1778 | 1778 | 'type' => 'string', |
1779 | 1779 | 'format' => 'date-time', |
1780 | 1780 | 'context' => array( 'view', 'edit' ), |
1781 | 1781 | 'readonly' => true, |
1782 | 1782 | ), |
1783 | 1783 | 'slug' => array( |
1784 | | 'description' => __( 'An alphanumeric identifier for the object unique to its type.' ), |
| 1784 | 'description' => _l( 'An alphanumeric identifier for the object unique to its type.' ), |
1785 | 1785 | 'type' => 'string', |
1786 | 1786 | 'context' => array( 'view', 'edit', 'embed' ), |
1787 | 1787 | 'arg_options' => array( |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1789 | 1789 | ), |
1790 | 1790 | ), |
1791 | 1791 | 'status' => array( |
1792 | | 'description' => __( 'A named status for the object.' ), |
| 1792 | 'description' => _l( 'A named status for the object.' ), |
1793 | 1793 | 'type' => 'string', |
1794 | 1794 | 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), |
1795 | 1795 | 'context' => array( 'view', 'edit' ), |
1796 | 1796 | ), |
1797 | 1797 | 'type' => array( |
1798 | | 'description' => __( 'Type of Post for the object.' ), |
| 1798 | 'description' => _l( 'Type of Post for the object.' ), |
1799 | 1799 | 'type' => 'string', |
1800 | 1800 | 'context' => array( 'view', 'edit', 'embed' ), |
1801 | 1801 | 'readonly' => true, |
1802 | 1802 | ), |
1803 | 1803 | 'password' => array( |
1804 | | 'description' => __( 'A password to protect access to the content and excerpt.' ), |
| 1804 | 'description' => _l( 'A password to protect access to the content and excerpt.' ), |
1805 | 1805 | 'type' => 'string', |
1806 | 1806 | 'context' => array( 'edit' ), |
1807 | 1807 | ), |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1812 | 1812 | |
1813 | 1813 | if ( $post_type_obj->hierarchical ) { |
1814 | 1814 | $schema['properties']['parent'] = array( |
1815 | | 'description' => __( 'The ID for the parent of the object.' ), |
| 1815 | 'description' => _l( 'The ID for the parent of the object.' ), |
1816 | 1816 | 'type' => 'integer', |
1817 | 1817 | 'context' => array( 'view', 'edit' ), |
1818 | 1818 | ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1872 | 1872 | |
1873 | 1873 | case 'title': |
1874 | 1874 | $schema['properties']['title'] = array( |
1875 | | 'description' => __( 'The title for the object.' ), |
| 1875 | 'description' => _l( 'The title for the object.' ), |
1876 | 1876 | 'type' => 'object', |
1877 | 1877 | 'context' => array( 'view', 'edit', 'embed' ), |
1878 | 1878 | 'arg_options' => array( |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1880 | 1880 | ), |
1881 | 1881 | 'properties' => array( |
1882 | 1882 | 'raw' => array( |
1883 | | 'description' => __( 'Title for the object, as it exists in the database.' ), |
| 1883 | 'description' => _l( 'Title for the object, as it exists in the database.' ), |
1884 | 1884 | 'type' => 'string', |
1885 | 1885 | 'context' => array( 'edit' ), |
1886 | 1886 | ), |
1887 | 1887 | 'rendered' => array( |
1888 | | 'description' => __( 'HTML title for the object, transformed for display.' ), |
| 1888 | 'description' => _l( 'HTML title for the object, transformed for display.' ), |
1889 | 1889 | 'type' => 'string', |
1890 | 1890 | 'context' => array( 'view', 'edit', 'embed' ), |
1891 | 1891 | 'readonly' => true, |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1896 | 1896 | |
1897 | 1897 | case 'editor': |
1898 | 1898 | $schema['properties']['content'] = array( |
1899 | | 'description' => __( 'The content for the object.' ), |
| 1899 | 'description' => _l( 'The content for the object.' ), |
1900 | 1900 | 'type' => 'object', |
1901 | 1901 | 'context' => array( 'view', 'edit' ), |
1902 | 1902 | 'arg_options' => array( |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1904 | 1904 | ), |
1905 | 1905 | 'properties' => array( |
1906 | 1906 | 'raw' => array( |
1907 | | 'description' => __( 'Content for the object, as it exists in the database.' ), |
| 1907 | 'description' => _l( 'Content for the object, as it exists in the database.' ), |
1908 | 1908 | 'type' => 'string', |
1909 | 1909 | 'context' => array( 'edit' ), |
1910 | 1910 | ), |
1911 | 1911 | 'rendered' => array( |
1912 | | 'description' => __( 'HTML content for the object, transformed for display.' ), |
| 1912 | 'description' => _l( 'HTML content for the object, transformed for display.' ), |
1913 | 1913 | 'type' => 'string', |
1914 | 1914 | 'context' => array( 'view', 'edit' ), |
1915 | 1915 | 'readonly' => true, |
1916 | 1916 | ), |
1917 | 1917 | 'protected' => array( |
1918 | | 'description' => __( 'Whether the content is protected with a password.' ), |
| 1918 | 'description' => _l( 'Whether the content is protected with a password.' ), |
1919 | 1919 | 'type' => 'boolean', |
1920 | 1920 | 'context' => array( 'view', 'edit', 'embed' ), |
1921 | 1921 | 'readonly' => true, |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1926 | 1926 | |
1927 | 1927 | case 'author': |
1928 | 1928 | $schema['properties']['author'] = array( |
1929 | | 'description' => __( 'The ID for the author of the object.' ), |
| 1929 | 'description' => _l( 'The ID for the author of the object.' ), |
1930 | 1930 | 'type' => 'integer', |
1931 | 1931 | 'context' => array( 'view', 'edit', 'embed' ), |
1932 | 1932 | ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1934 | 1934 | |
1935 | 1935 | case 'excerpt': |
1936 | 1936 | $schema['properties']['excerpt'] = array( |
1937 | | 'description' => __( 'The excerpt for the object.' ), |
| 1937 | 'description' => _l( 'The excerpt for the object.' ), |
1938 | 1938 | 'type' => 'object', |
1939 | 1939 | 'context' => array( 'view', 'edit', 'embed' ), |
1940 | 1940 | 'arg_options' => array( |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1942 | 1942 | ), |
1943 | 1943 | 'properties' => array( |
1944 | 1944 | 'raw' => array( |
1945 | | 'description' => __( 'Excerpt for the object, as it exists in the database.' ), |
| 1945 | 'description' => _l( 'Excerpt for the object, as it exists in the database.' ), |
1946 | 1946 | 'type' => 'string', |
1947 | 1947 | 'context' => array( 'edit' ), |
1948 | 1948 | ), |
1949 | 1949 | 'rendered' => array( |
1950 | | 'description' => __( 'HTML excerpt for the object, transformed for display.' ), |
| 1950 | 'description' => _l( 'HTML excerpt for the object, transformed for display.' ), |
1951 | 1951 | 'type' => 'string', |
1952 | 1952 | 'context' => array( 'view', 'edit', 'embed' ), |
1953 | 1953 | 'readonly' => true, |
1954 | 1954 | ), |
1955 | 1955 | 'protected' => array( |
1956 | | 'description' => __( 'Whether the excerpt is protected with a password.' ), |
| 1956 | 'description' => _l( 'Whether the excerpt is protected with a password.' ), |
1957 | 1957 | 'type' => 'boolean', |
1958 | 1958 | 'context' => array( 'view', 'edit', 'embed' ), |
1959 | 1959 | 'readonly' => true, |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1964 | 1964 | |
1965 | 1965 | case 'thumbnail': |
1966 | 1966 | $schema['properties']['featured_media'] = array( |
1967 | | 'description' => __( 'The ID of the featured media for the object.' ), |
| 1967 | 'description' => _l( 'The ID of the featured media for the object.' ), |
1968 | 1968 | 'type' => 'integer', |
1969 | 1969 | 'context' => array( 'view', 'edit', 'embed' ), |
1970 | 1970 | ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1972 | 1972 | |
1973 | 1973 | case 'comments': |
1974 | 1974 | $schema['properties']['comment_status'] = array( |
1975 | | 'description' => __( 'Whether or not comments are open on the object.' ), |
| 1975 | 'description' => _l( 'Whether or not comments are open on the object.' ), |
1976 | 1976 | 'type' => 'string', |
1977 | 1977 | 'enum' => array( 'open', 'closed' ), |
1978 | 1978 | 'context' => array( 'view', 'edit' ), |
1979 | 1979 | ); |
1980 | 1980 | $schema['properties']['ping_status'] = array( |
1981 | | 'description' => __( 'Whether or not the object can be pinged.' ), |
| 1981 | 'description' => _l( 'Whether or not the object can be pinged.' ), |
1982 | 1982 | 'type' => 'string', |
1983 | 1983 | 'enum' => array( 'open', 'closed' ), |
1984 | 1984 | 'context' => array( 'view', 'edit' ), |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1987 | 1987 | |
1988 | 1988 | case 'page-attributes': |
1989 | 1989 | $schema['properties']['menu_order'] = array( |
1990 | | 'description' => __( 'The order of the object in relation to other object of its type.' ), |
| 1990 | 'description' => _l( 'The order of the object in relation to other object of its type.' ), |
1991 | 1991 | 'type' => 'integer', |
1992 | 1992 | 'context' => array( 'view', 'edit' ), |
1993 | 1993 | ); |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1998 | 1998 | $formats = array_values( get_post_format_slugs() ); |
1999 | 1999 | |
2000 | 2000 | $schema['properties']['format'] = array( |
2001 | | 'description' => __( 'The format for the object.' ), |
| 2001 | 'description' => _l( 'The format for the object.' ), |
2002 | 2002 | 'type' => 'string', |
2003 | 2003 | 'enum' => $formats, |
2004 | 2004 | 'context' => array( 'view', 'edit' ), |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2014 | 2014 | |
2015 | 2015 | if ( 'post' === $this->post_type ) { |
2016 | 2016 | $schema['properties']['sticky'] = array( |
2017 | | 'description' => __( 'Whether or not the object should be treated as sticky.' ), |
| 2017 | 'description' => _l( 'Whether or not the object should be treated as sticky.' ), |
2018 | 2018 | 'type' => 'boolean', |
2019 | 2019 | 'context' => array( 'view', 'edit' ), |
2020 | 2020 | ); |
2021 | 2021 | } |
2022 | 2022 | |
2023 | 2023 | $schema['properties']['template'] = array( |
2024 | | 'description' => __( 'The theme file to use to display the object.' ), |
| 2024 | 'description' => _l( 'The theme file to use to display the object.' ), |
2025 | 2025 | 'type' => 'string', |
2026 | 2026 | 'enum' => array_merge( array_keys( wp_get_theme()->get_page_templates( null, $this->post_type ) ), array( '' ) ), |
2027 | 2027 | 'context' => array( 'view', 'edit' ), |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2032 | 2032 | $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; |
2033 | 2033 | $schema['properties'][ $base ] = array( |
2034 | 2034 | /* translators: %s: taxonomy name */ |
2035 | | 'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ), |
| 2035 | 'description' => sprintf( _l( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ), |
2036 | 2036 | 'type' => 'array', |
2037 | 2037 | 'items' => array( |
2038 | 2038 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2058 | 2058 | $query_params['context']['default'] = 'view'; |
2059 | 2059 | |
2060 | 2060 | $query_params['after'] = array( |
2061 | | 'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ), |
| 2061 | 'description' => _l( 'Limit response to posts published after a given ISO8601 compliant date.' ), |
2062 | 2062 | 'type' => 'string', |
2063 | 2063 | 'format' => 'date-time', |
2064 | 2064 | ); |
2065 | 2065 | |
2066 | 2066 | if ( post_type_supports( $this->post_type, 'author' ) ) { |
2067 | 2067 | $query_params['author'] = array( |
2068 | | 'description' => __( 'Limit result set to posts assigned to specific authors.' ), |
| 2068 | 'description' => _l( 'Limit result set to posts assigned to specific authors.' ), |
2069 | 2069 | 'type' => 'array', |
2070 | 2070 | 'items' => array( |
2071 | 2071 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2073 | 2073 | 'default' => array(), |
2074 | 2074 | ); |
2075 | 2075 | $query_params['author_exclude'] = array( |
2076 | | 'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ), |
| 2076 | 'description' => _l( 'Ensure result set excludes posts assigned to specific authors.' ), |
2077 | 2077 | 'type' => 'array', |
2078 | 2078 | 'items' => array( |
2079 | 2079 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2083 | 2083 | } |
2084 | 2084 | |
2085 | 2085 | $query_params['before'] = array( |
2086 | | 'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ), |
| 2086 | 'description' => _l( 'Limit response to posts published before a given ISO8601 compliant date.' ), |
2087 | 2087 | 'type' => 'string', |
2088 | 2088 | 'format' => 'date-time', |
2089 | 2089 | ); |
2090 | 2090 | |
2091 | 2091 | $query_params['exclude'] = array( |
2092 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| 2092 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
2093 | 2093 | 'type' => 'array', |
2094 | 2094 | 'items' => array( |
2095 | 2095 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2098 | 2098 | ); |
2099 | 2099 | |
2100 | 2100 | $query_params['include'] = array( |
2101 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| 2101 | 'description' => _l( 'Limit result set to specific IDs.' ), |
2102 | 2102 | 'type' => 'array', |
2103 | 2103 | 'items' => array( |
2104 | 2104 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2108 | 2108 | |
2109 | 2109 | if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) { |
2110 | 2110 | $query_params['menu_order'] = array( |
2111 | | 'description' => __( 'Limit result set to posts with a specific menu_order value.' ), |
| 2111 | 'description' => _l( 'Limit result set to posts with a specific menu_order value.' ), |
2112 | 2112 | 'type' => 'integer', |
2113 | 2113 | ); |
2114 | 2114 | } |
2115 | 2115 | |
2116 | 2116 | $query_params['offset'] = array( |
2117 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| 2117 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
2118 | 2118 | 'type' => 'integer', |
2119 | 2119 | ); |
2120 | 2120 | |
2121 | 2121 | $query_params['order'] = array( |
2122 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| 2122 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
2123 | 2123 | 'type' => 'string', |
2124 | 2124 | 'default' => 'desc', |
2125 | 2125 | 'enum' => array( 'asc', 'desc' ), |
2126 | 2126 | ); |
2127 | 2127 | |
2128 | 2128 | $query_params['orderby'] = array( |
2129 | | 'description' => __( 'Sort collection by object attribute.' ), |
| 2129 | 'description' => _l( 'Sort collection by object attribute.' ), |
2130 | 2130 | 'type' => 'string', |
2131 | 2131 | 'default' => 'date', |
2132 | 2132 | 'enum' => array( |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2150 | 2150 | |
2151 | 2151 | if ( $post_type->hierarchical || 'attachment' === $this->post_type ) { |
2152 | 2152 | $query_params['parent'] = array( |
2153 | | 'description' => __( 'Limit result set to items with particular parent IDs.' ), |
| 2153 | 'description' => _l( 'Limit result set to items with particular parent IDs.' ), |
2154 | 2154 | 'type' => 'array', |
2155 | 2155 | 'items' => array( |
2156 | 2156 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2158 | 2158 | 'default' => array(), |
2159 | 2159 | ); |
2160 | 2160 | $query_params['parent_exclude'] = array( |
2161 | | 'description' => __( 'Limit result set to all items except those of a particular parent ID.' ), |
| 2161 | 'description' => _l( 'Limit result set to all items except those of a particular parent ID.' ), |
2162 | 2162 | 'type' => 'array', |
2163 | 2163 | 'items' => array( |
2164 | 2164 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2168 | 2168 | } |
2169 | 2169 | |
2170 | 2170 | $query_params['slug'] = array( |
2171 | | 'description' => __( 'Limit result set to posts with one or more specific slugs.' ), |
| 2171 | 'description' => _l( 'Limit result set to posts with one or more specific slugs.' ), |
2172 | 2172 | 'type' => 'array', |
2173 | 2173 | 'items' => array( |
2174 | 2174 | 'type' => 'string', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2178 | 2178 | |
2179 | 2179 | $query_params['status'] = array( |
2180 | 2180 | 'default' => 'publish', |
2181 | | 'description' => __( 'Limit result set to posts assigned one or more statuses.' ), |
| 2181 | 'description' => _l( 'Limit result set to posts assigned one or more statuses.' ), |
2182 | 2182 | 'type' => 'array', |
2183 | 2183 | 'items' => array( |
2184 | 2184 | 'enum' => array_merge( array_keys( get_post_stati() ), array( 'any' ) ), |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2194 | 2194 | |
2195 | 2195 | $query_params[ $base ] = array( |
2196 | 2196 | /* translators: %s: taxonomy name */ |
2197 | | 'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), |
| 2197 | 'description' => sprintf( _l( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), |
2198 | 2198 | 'type' => 'array', |
2199 | 2199 | 'items' => array( |
2200 | 2200 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2204 | 2204 | |
2205 | 2205 | $query_params[ $base . '_exclude' ] = array( |
2206 | 2206 | /* translators: %s: taxonomy name */ |
2207 | | 'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ), |
| 2207 | 'description' => sprintf( _l( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ), |
2208 | 2208 | 'type' => 'array', |
2209 | 2209 | 'items' => array( |
2210 | 2210 | 'type' => 'integer', |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2215 | 2215 | |
2216 | 2216 | if ( 'post' === $this->post_type ) { |
2217 | 2217 | $query_params['sticky'] = array( |
2218 | | 'description' => __( 'Limit result set to items that are sticky.' ), |
| 2218 | 'description' => _l( 'Limit result set to items that are sticky.' ), |
2219 | 2219 | 'type' => 'boolean', |
2220 | 2220 | ); |
2221 | 2221 | } |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2270 | 2270 | return $result; |
2271 | 2271 | } |
2272 | 2272 | } else { |
2273 | | return new WP_Error( 'rest_forbidden_status', __( 'Status is forbidden.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 2273 | return new WP_Error( 'rest_forbidden_status', _l( 'Status is forbidden.' ), array( 'status' => rest_authorization_required_code() ) ); |
2274 | 2274 | } |
2275 | 2275 | } |
2276 | 2276 | |
-
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 8b0efcdf3d..4b46d8296a 100644
|
|
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
73 | 73 | register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array( |
74 | 74 | 'args' => array( |
75 | 75 | 'parent' => array( |
76 | | 'description' => __( 'The ID for the parent of the object.' ), |
| 76 | 'description' => _l( 'The ID for the parent of the object.' ), |
77 | 77 | 'type' => 'integer', |
78 | 78 | ), |
79 | 79 | ), |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
89 | 89 | register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
90 | 90 | 'args' => array( |
91 | 91 | 'parent' => array( |
92 | | 'description' => __( 'The ID for the parent of the object.' ), |
| 92 | 'description' => _l( 'The ID for the parent of the object.' ), |
93 | 93 | 'type' => 'integer', |
94 | 94 | ), |
95 | 95 | 'id' => array( |
96 | | 'description' => __( 'Unique identifier for the object.' ), |
| 96 | 'description' => _l( 'Unique identifier for the object.' ), |
97 | 97 | 'type' => 'integer', |
98 | 98 | ), |
99 | 99 | ), |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
113 | 113 | 'force' => array( |
114 | 114 | 'type' => 'boolean', |
115 | 115 | 'default' => false, |
116 | | 'description' => __( 'Required to be true, as revisions do not support trashing.' ), |
| 116 | 'description' => _l( 'Required to be true, as revisions do not support trashing.' ), |
117 | 117 | ), |
118 | 118 | ), |
119 | 119 | ), |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
131 | 131 | * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. |
132 | 132 | */ |
133 | 133 | protected function get_parent( $parent ) { |
134 | | $error = new WP_Error( 'rest_post_invalid_parent', __( 'Invalid post parent ID.' ), array( 'status' => 404 ) ); |
| 134 | $error = new WP_Error( 'rest_post_invalid_parent', _l( 'Invalid post parent ID.' ), array( 'status' => 404 ) ); |
135 | 135 | if ( (int) $parent <= 0 ) { |
136 | 136 | return $error; |
137 | 137 | } |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
161 | 161 | |
162 | 162 | $parent_post_type_obj = get_post_type_object( $parent->post_type ); |
163 | 163 | if ( ! current_user_can( $parent_post_type_obj->cap->edit_post, $parent->ID ) ) { |
164 | | return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to view revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 164 | 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() ) ); |
165 | 165 | } |
166 | 166 | |
167 | 167 | return true; |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
176 | 176 | * @return WP_Post|WP_Error Revision post object if ID is valid, WP_Error otherwise. |
177 | 177 | */ |
178 | 178 | protected function get_revision( $id ) { |
179 | | $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid revision ID.' ), array( 'status' => 404 ) ); |
| 179 | $error = new WP_Error( 'rest_post_invalid_id', _l( 'Invalid revision ID.' ), array( 'status' => 404 ) ); |
180 | 180 | if ( (int) $id <= 0 ) { |
181 | 181 | return $error; |
182 | 182 | } |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
299 | 299 | |
300 | 300 | // We don't support trashing for revisions. |
301 | 301 | if ( ! $force ) { |
302 | | return new WP_Error( 'rest_trash_not_supported', __( 'Revisions do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
| 302 | return new WP_Error( 'rest_trash_not_supported', _l( 'Revisions do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
303 | 303 | } |
304 | 304 | |
305 | 305 | $previous = $this->prepare_item_for_response( $revision, $request ); |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
319 | 319 | do_action( 'rest_delete_revision', $result, $request ); |
320 | 320 | |
321 | 321 | if ( ! $result ) { |
322 | | return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
| 322 | return new WP_Error( 'rest_cannot_delete', _l( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); |
323 | 323 | } |
324 | 324 | |
325 | 325 | $response = new WP_REST_Response(); |
… |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller { |
471 | 471 | // Base properties for every Revision. |
472 | 472 | 'properties' => array( |
473 | 473 | 'author' => array( |
474 | | 'description' => __( 'The ID for the author of the object.' ), |
| 474 | 'description' => _l( 'The ID for the author of the object.' ), |
475 | 475 | 'type' => 'integer', |
476 | 476 | 'context' => array( 'view', 'edit', 'embed' ), |
477 | 477 | ), |
478 | 478 | 'date' => array( |
479 | | 'description' => __( "The date the object was published, in the site's timezone." ), |
| 479 | 'description' => _l( "The date the object was published, in the site's timezone." ), |
480 | 480 | 'type' => 'string', |
481 | 481 | 'format' => 'date-time', |
482 | 482 | 'context' => array( 'view', 'edit', 'embed' ), |
483 | 483 | ), |
484 | 484 | 'date_gmt' => array( |
485 | | 'description' => __( 'The date the object was published, as GMT.' ), |
| 485 | 'description' => _l( 'The date the object was published, as GMT.' ), |
486 | 486 | 'type' => 'string', |
487 | 487 | 'format' => 'date-time', |
488 | 488 | 'context' => array( 'view', 'edit' ), |
489 | 489 | ), |
490 | 490 | 'guid' => array( |
491 | | 'description' => __( 'GUID for the object, as it exists in the database.' ), |
| 491 | 'description' => _l( 'GUID for the object, as it exists in the database.' ), |
492 | 492 | 'type' => 'string', |
493 | 493 | 'context' => array( 'view', 'edit' ), |
494 | 494 | ), |
495 | 495 | 'id' => array( |
496 | | 'description' => __( 'Unique identifier for the object.' ), |
| 496 | 'description' => _l( 'Unique identifier for the object.' ), |
497 | 497 | 'type' => 'integer', |
498 | 498 | 'context' => array( 'view', 'edit', 'embed' ), |
499 | 499 | ), |
500 | 500 | 'modified' => array( |
501 | | 'description' => __( "The date the object was last modified, in the site's timezone." ), |
| 501 | 'description' => _l( "The date the object was last modified, in the site's timezone." ), |
502 | 502 | 'type' => 'string', |
503 | 503 | 'format' => 'date-time', |
504 | 504 | 'context' => array( 'view', 'edit' ), |
505 | 505 | ), |
506 | 506 | 'modified_gmt' => array( |
507 | | 'description' => __( 'The date the object was last modified, as GMT.' ), |
| 507 | 'description' => _l( 'The date the object was last modified, as GMT.' ), |
508 | 508 | 'type' => 'string', |
509 | 509 | 'format' => 'date-time', |
510 | 510 | 'context' => array( 'view', 'edit' ), |
511 | 511 | ), |
512 | 512 | 'parent' => array( |
513 | | 'description' => __( 'The ID for the parent of the object.' ), |
| 513 | 'description' => _l( 'The ID for the parent of the object.' ), |
514 | 514 | 'type' => 'integer', |
515 | 515 | 'context' => array( 'view', 'edit', 'embed' ), |
516 | 516 | ), |
517 | 517 | 'slug' => array( |
518 | | 'description' => __( 'An alphanumeric identifier for the object unique to its type.' ), |
| 518 | 'description' => _l( 'An alphanumeric identifier for the object unique to its type.' ), |
519 | 519 | 'type' => 'string', |
520 | 520 | 'context' => array( 'view', 'edit', 'embed' ), |
521 | 521 | ), |
-
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 57954f1b52..52e533a1a7 100644
|
|
class WP_REST_Settings_Controller extends WP_REST_Controller { |
200 | 200 | */ |
201 | 201 | if ( ! is_scalar( get_option( $args['option_name'], false ) ) ) { |
202 | 202 | return new WP_Error( |
203 | | 'rest_invalid_stored_value', sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) |
| 203 | 'rest_invalid_stored_value', sprintf( _l( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) |
204 | 204 | ); |
205 | 205 | } |
206 | 206 | |
-
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 b46562c9c4..b4c23d1d12 100644
|
|
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
50 | 50 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<taxonomy>[\w-]+)', array( |
51 | 51 | 'args' => array( |
52 | 52 | 'taxonomy' => array( |
53 | | 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), |
| 53 | 'description' => _l( 'An alphanumeric identifier for the taxonomy.' ), |
54 | 54 | 'type' => 'string', |
55 | 55 | ), |
56 | 56 | ), |
… |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
87 | 87 | return true; |
88 | 88 | } |
89 | 89 | } |
90 | | return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 90 | 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() ) ); |
91 | 91 | } |
92 | 92 | return true; |
93 | 93 | } |
… |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->manage_terms ) ) { |
150 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 150 | 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() ) ); |
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
… |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
166 | 166 | public function get_item( $request ) { |
167 | 167 | $tax_obj = get_taxonomy( $request['taxonomy'] ); |
168 | 168 | if ( empty( $tax_obj ) ) { |
169 | | return new WP_Error( 'rest_taxonomy_invalid', __( 'Invalid taxonomy.' ), array( 'status' => 404 ) ); |
| 169 | return new WP_Error( 'rest_taxonomy_invalid', _l( 'Invalid taxonomy.' ), array( 'status' => 404 ) ); |
170 | 170 | } |
171 | 171 | $data = $this->prepare_item_for_response( $tax_obj, $request ); |
172 | 172 | return rest_ensure_response( $data ); |
… |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
241 | 241 | 'type' => 'object', |
242 | 242 | 'properties' => array( |
243 | 243 | 'capabilities' => array( |
244 | | 'description' => __( 'All capabilities used by the taxonomy.' ), |
| 244 | 'description' => _l( 'All capabilities used by the taxonomy.' ), |
245 | 245 | 'type' => 'object', |
246 | 246 | 'context' => array( 'edit' ), |
247 | 247 | 'readonly' => true, |
248 | 248 | ), |
249 | 249 | 'description' => array( |
250 | | 'description' => __( 'A human-readable description of the taxonomy.' ), |
| 250 | 'description' => _l( 'A human-readable description of the taxonomy.' ), |
251 | 251 | 'type' => 'string', |
252 | 252 | 'context' => array( 'view', 'edit' ), |
253 | 253 | 'readonly' => true, |
254 | 254 | ), |
255 | 255 | 'hierarchical' => array( |
256 | | 'description' => __( 'Whether or not the taxonomy should have children.' ), |
| 256 | 'description' => _l( 'Whether or not the taxonomy should have children.' ), |
257 | 257 | 'type' => 'boolean', |
258 | 258 | 'context' => array( 'view', 'edit' ), |
259 | 259 | 'readonly' => true, |
260 | 260 | ), |
261 | 261 | 'labels' => array( |
262 | | 'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ), |
| 262 | 'description' => _l( 'Human-readable labels for the taxonomy for various contexts.' ), |
263 | 263 | 'type' => 'object', |
264 | 264 | 'context' => array( 'edit' ), |
265 | 265 | 'readonly' => true, |
266 | 266 | ), |
267 | 267 | 'name' => array( |
268 | | 'description' => __( 'The title for the taxonomy.' ), |
| 268 | 'description' => _l( 'The title for the taxonomy.' ), |
269 | 269 | 'type' => 'string', |
270 | 270 | 'context' => array( 'view', 'edit', 'embed' ), |
271 | 271 | 'readonly' => true, |
272 | 272 | ), |
273 | 273 | 'slug' => array( |
274 | | 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), |
| 274 | 'description' => _l( 'An alphanumeric identifier for the taxonomy.' ), |
275 | 275 | 'type' => 'string', |
276 | 276 | 'context' => array( 'view', 'edit', 'embed' ), |
277 | 277 | 'readonly' => true, |
278 | 278 | ), |
279 | 279 | 'show_cloud' => array( |
280 | | 'description' => __( 'Whether or not the term cloud should be displayed.' ), |
| 280 | 'description' => _l( 'Whether or not the term cloud should be displayed.' ), |
281 | 281 | 'type' => 'boolean', |
282 | 282 | 'context' => array( 'edit' ), |
283 | 283 | 'readonly' => true, |
284 | 284 | ), |
285 | 285 | 'types' => array( |
286 | | 'description' => __( 'Types associated with the taxonomy.' ), |
| 286 | 'description' => _l( 'Types associated with the taxonomy.' ), |
287 | 287 | 'type' => 'array', |
288 | 288 | 'items' => array( |
289 | 289 | 'type' => 'string', |
… |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
292 | 292 | 'readonly' => true, |
293 | 293 | ), |
294 | 294 | 'rest_base' => array( |
295 | | 'description' => __( 'REST base route for the taxonomy.' ), |
| 295 | 'description' => _l( 'REST base route for the taxonomy.' ), |
296 | 296 | 'type' => 'string', |
297 | 297 | 'context' => array( 'view', 'edit', 'embed' ), |
298 | 298 | 'readonly' => true, |
… |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller { |
314 | 314 | $new_params = array(); |
315 | 315 | $new_params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
316 | 316 | $new_params['type'] = array( |
317 | | 'description' => __( 'Limit results to taxonomies associated with a specific post type.' ), |
| 317 | 'description' => _l( 'Limit results to taxonomies associated with a specific post type.' ), |
318 | 318 | 'type' => 'string', |
319 | 319 | ); |
320 | 320 | 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 299b034329..f51b36c990 100644
|
|
class WP_REST_Terms_Controller extends WP_REST_Controller { |
98 | 98 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
99 | 99 | 'args' => array( |
100 | 100 | 'id' => array( |
101 | | 'description' => __( 'Unique identifier for the term.' ), |
| 101 | 'description' => _l( 'Unique identifier for the term.' ), |
102 | 102 | 'type' => 'integer', |
103 | 103 | ), |
104 | 104 | ), |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
124 | 124 | 'force' => array( |
125 | 125 | 'type' => 'boolean', |
126 | 126 | 'default' => false, |
127 | | 'description' => __( 'Required to be true, as terms do not support trashing.' ), |
| 127 | 'description' => _l( 'Required to be true, as terms do not support trashing.' ), |
128 | 128 | ), |
129 | 129 | ), |
130 | 130 | ), |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) { |
150 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 150 | 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() ) ); |
151 | 151 | } |
152 | 152 | return true; |
153 | 153 | } |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
302 | 302 | * @return WP_Term|WP_Error Term object if ID is valid, WP_Error otherwise. |
303 | 303 | */ |
304 | 304 | protected function get_term( $id ) { |
305 | | $error = new WP_Error( 'rest_term_invalid', __( 'Term does not exist.' ), array( 'status' => 404 ) ); |
| 305 | $error = new WP_Error( 'rest_term_invalid', _l( 'Term does not exist.' ), array( 'status' => 404 ) ); |
306 | 306 | |
307 | 307 | if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) { |
308 | 308 | return $error; |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
336 | 336 | } |
337 | 337 | |
338 | 338 | if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) { |
339 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 339 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
340 | 340 | } |
341 | 341 | return true; |
342 | 342 | } |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
378 | 378 | |
379 | 379 | $taxonomy_obj = get_taxonomy( $this->taxonomy ); |
380 | 380 | if ( ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) { |
381 | | return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 381 | return new WP_Error( 'rest_cannot_create', _l( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) ); |
382 | 382 | } |
383 | 383 | |
384 | 384 | return true; |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
396 | 396 | public function create_item( $request ) { |
397 | 397 | if ( isset( $request['parent'] ) ) { |
398 | 398 | if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { |
399 | | return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
| 399 | return new WP_Error( 'rest_taxonomy_not_hierarchical', _l( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
400 | 400 | } |
401 | 401 | |
402 | 402 | $parent = get_term( (int) $request['parent'], $this->taxonomy ); |
403 | 403 | |
404 | 404 | if ( ! $parent ) { |
405 | | return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
| 405 | return new WP_Error( 'rest_term_invalid', _l( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
479 | 479 | } |
480 | 480 | |
481 | 481 | if ( ! current_user_can( 'edit_term', $term->term_id ) ) { |
482 | | return new WP_Error( 'rest_cannot_update', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 482 | return new WP_Error( 'rest_cannot_update', _l( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
483 | 483 | } |
484 | 484 | |
485 | 485 | return true; |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
502 | 502 | |
503 | 503 | if ( isset( $request['parent'] ) ) { |
504 | 504 | if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { |
505 | | return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
| 505 | return new WP_Error( 'rest_taxonomy_not_hierarchical', _l( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
506 | 506 | } |
507 | 507 | |
508 | 508 | $parent = get_term( (int) $request['parent'], $this->taxonomy ); |
509 | 509 | |
510 | 510 | if ( ! $parent ) { |
511 | | return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
| 511 | return new WP_Error( 'rest_term_invalid', _l( 'Parent term does not exist.' ), array( 'status' => 400 ) ); |
512 | 512 | } |
513 | 513 | } |
514 | 514 | |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
566 | 566 | } |
567 | 567 | |
568 | 568 | if ( ! current_user_can( 'delete_term', $term->term_id ) ) { |
569 | | return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 569 | return new WP_Error( 'rest_cannot_delete', _l( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) ); |
570 | 570 | } |
571 | 571 | |
572 | 572 | return true; |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
591 | 591 | |
592 | 592 | // We don't support trashing for terms. |
593 | 593 | if ( ! $force ) { |
594 | | return new WP_Error( 'rest_trash_not_supported', __( 'Terms do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
| 594 | return new WP_Error( 'rest_trash_not_supported', _l( 'Terms do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
595 | 595 | } |
596 | 596 | |
597 | 597 | $request->set_param( 'context', 'view' ); |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
601 | 601 | $retval = wp_delete_term( $term->term_id, $term->taxonomy ); |
602 | 602 | |
603 | 603 | if ( ! $retval ) { |
604 | | return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) ); |
| 604 | return new WP_Error( 'rest_cannot_delete', _l( 'The term cannot be deleted.' ), array( 'status' => 500 ) ); |
605 | 605 | } |
606 | 606 | |
607 | 607 | $response = new WP_REST_Response(); |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
828 | 828 | 'type' => 'object', |
829 | 829 | 'properties' => array( |
830 | 830 | 'id' => array( |
831 | | 'description' => __( 'Unique identifier for the term.' ), |
| 831 | 'description' => _l( 'Unique identifier for the term.' ), |
832 | 832 | 'type' => 'integer', |
833 | 833 | 'context' => array( 'view', 'embed', 'edit' ), |
834 | 834 | 'readonly' => true, |
835 | 835 | ), |
836 | 836 | 'count' => array( |
837 | | 'description' => __( 'Number of published posts for the term.' ), |
| 837 | 'description' => _l( 'Number of published posts for the term.' ), |
838 | 838 | 'type' => 'integer', |
839 | 839 | 'context' => array( 'view', 'edit' ), |
840 | 840 | 'readonly' => true, |
841 | 841 | ), |
842 | 842 | 'description' => array( |
843 | | 'description' => __( 'HTML description of the term.' ), |
| 843 | 'description' => _l( 'HTML description of the term.' ), |
844 | 844 | 'type' => 'string', |
845 | 845 | 'context' => array( 'view', 'edit' ), |
846 | 846 | ), |
847 | 847 | 'link' => array( |
848 | | 'description' => __( 'URL of the term.' ), |
| 848 | 'description' => _l( 'URL of the term.' ), |
849 | 849 | 'type' => 'string', |
850 | 850 | 'format' => 'uri', |
851 | 851 | 'context' => array( 'view', 'embed', 'edit' ), |
852 | 852 | 'readonly' => true, |
853 | 853 | ), |
854 | 854 | 'name' => array( |
855 | | 'description' => __( 'HTML title for the term.' ), |
| 855 | 'description' => _l( 'HTML title for the term.' ), |
856 | 856 | 'type' => 'string', |
857 | 857 | 'context' => array( 'view', 'embed', 'edit' ), |
858 | 858 | 'arg_options' => array( |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
861 | 861 | 'required' => true, |
862 | 862 | ), |
863 | 863 | 'slug' => array( |
864 | | 'description' => __( 'An alphanumeric identifier for the term unique to its type.' ), |
| 864 | 'description' => _l( 'An alphanumeric identifier for the term unique to its type.' ), |
865 | 865 | 'type' => 'string', |
866 | 866 | 'context' => array( 'view', 'embed', 'edit' ), |
867 | 867 | 'arg_options' => array( |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
869 | 869 | ), |
870 | 870 | ), |
871 | 871 | 'taxonomy' => array( |
872 | | 'description' => __( 'Type attribution for the term.' ), |
| 872 | 'description' => _l( 'Type attribution for the term.' ), |
873 | 873 | 'type' => 'string', |
874 | 874 | 'enum' => array_keys( get_taxonomies() ), |
875 | 875 | 'context' => array( 'view', 'embed', 'edit' ), |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
882 | 882 | |
883 | 883 | if ( $taxonomy->hierarchical ) { |
884 | 884 | $schema['properties']['parent'] = array( |
885 | | 'description' => __( 'The parent term ID.' ), |
| 885 | 'description' => _l( 'The parent term ID.' ), |
886 | 886 | 'type' => 'integer', |
887 | 887 | 'context' => array( 'view', 'edit' ), |
888 | 888 | ); |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
908 | 908 | $query_params['context']['default'] = 'view'; |
909 | 909 | |
910 | 910 | $query_params['exclude'] = array( |
911 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| 911 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
912 | 912 | 'type' => 'array', |
913 | 913 | 'items' => array( |
914 | 914 | 'type' => 'integer', |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
917 | 917 | ); |
918 | 918 | |
919 | 919 | $query_params['include'] = array( |
920 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| 920 | 'description' => _l( 'Limit result set to specific IDs.' ), |
921 | 921 | 'type' => 'array', |
922 | 922 | 'items' => array( |
923 | 923 | 'type' => 'integer', |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
927 | 927 | |
928 | 928 | if ( ! $taxonomy->hierarchical ) { |
929 | 929 | $query_params['offset'] = array( |
930 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| 930 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
931 | 931 | 'type' => 'integer', |
932 | 932 | ); |
933 | 933 | } |
934 | 934 | |
935 | 935 | $query_params['order'] = array( |
936 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| 936 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
937 | 937 | 'type' => 'string', |
938 | 938 | 'default' => 'asc', |
939 | 939 | 'enum' => array( |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
943 | 943 | ); |
944 | 944 | |
945 | 945 | $query_params['orderby'] = array( |
946 | | 'description' => __( 'Sort collection by term attribute.' ), |
| 946 | 'description' => _l( 'Sort collection by term attribute.' ), |
947 | 947 | 'type' => 'string', |
948 | 948 | 'default' => 'name', |
949 | 949 | 'enum' => array( |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
958 | 958 | ); |
959 | 959 | |
960 | 960 | $query_params['hide_empty'] = array( |
961 | | 'description' => __( 'Whether to hide terms not assigned to any posts.' ), |
| 961 | 'description' => _l( 'Whether to hide terms not assigned to any posts.' ), |
962 | 962 | 'type' => 'boolean', |
963 | 963 | 'default' => false, |
964 | 964 | ); |
965 | 965 | |
966 | 966 | if ( $taxonomy->hierarchical ) { |
967 | 967 | $query_params['parent'] = array( |
968 | | 'description' => __( 'Limit result set to terms assigned to a specific parent.' ), |
| 968 | 'description' => _l( 'Limit result set to terms assigned to a specific parent.' ), |
969 | 969 | 'type' => 'integer', |
970 | 970 | ); |
971 | 971 | } |
972 | 972 | |
973 | 973 | $query_params['post'] = array( |
974 | | 'description' => __( 'Limit result set to terms assigned to a specific post.' ), |
| 974 | 'description' => _l( 'Limit result set to terms assigned to a specific post.' ), |
975 | 975 | 'type' => 'integer', |
976 | 976 | 'default' => null, |
977 | 977 | ); |
978 | 978 | |
979 | 979 | $query_params['slug'] = array( |
980 | | 'description' => __( 'Limit result set to terms with one or more specific slugs.' ), |
| 980 | 'description' => _l( 'Limit result set to terms with one or more specific slugs.' ), |
981 | 981 | 'type' => 'array', |
982 | 982 | 'items' => array( |
983 | 983 | '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 63fb4e9e99..3976effbbd 100644
|
|
class WP_REST_Users_Controller extends WP_REST_Controller { |
67 | 67 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
68 | 68 | 'args' => array( |
69 | 69 | 'id' => array( |
70 | | 'description' => __( 'Unique identifier for the user.' ), |
| 70 | 'description' => _l( 'Unique identifier for the user.' ), |
71 | 71 | 'type' => 'integer', |
72 | 72 | ), |
73 | 73 | ), |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
93 | 93 | 'force' => array( |
94 | 94 | 'type' => 'boolean', |
95 | 95 | 'default' => false, |
96 | | 'description' => __( 'Required to be true, as users do not support trashing.' ), |
| 96 | 'description' => _l( 'Required to be true, as users do not support trashing.' ), |
97 | 97 | ), |
98 | 98 | 'reassign' => array( |
99 | 99 | 'type' => 'integer', |
100 | | 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
| 100 | 'description' => _l( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
101 | 101 | 'required' => true, |
102 | 102 | 'sanitize_callback' => array( $this, 'check_reassign' ), |
103 | 103 | ), |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
128 | 128 | 'force' => array( |
129 | 129 | 'type' => 'boolean', |
130 | 130 | 'default' => false, |
131 | | 'description' => __( 'Required to be true, as users do not support trashing.' ), |
| 131 | 'description' => _l( 'Required to be true, as users do not support trashing.' ), |
132 | 132 | ), |
133 | 133 | 'reassign' => array( |
134 | 134 | 'type' => 'integer', |
135 | | 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
| 135 | 'description' => _l( 'Reassign the deleted user\'s posts and links to this user ID.' ), |
136 | 136 | 'required' => true, |
137 | 137 | 'sanitize_callback' => array( $this, 'check_reassign' ), |
138 | 138 | ), |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | | return new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
| 168 | return new WP_Error( 'rest_invalid_param', _l( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
180 | 180 | public function get_items_permissions_check( $request ) { |
181 | 181 | // Check if roles is specified in GET request and if user can list users. |
182 | 182 | if ( ! empty( $request['roles'] ) && ! current_user_can( 'list_users' ) ) { |
183 | | return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to filter users by role.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 183 | 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() ) ); |
184 | 184 | } |
185 | 185 | |
186 | 186 | if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { |
187 | | return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 187 | return new WP_Error( 'rest_forbidden_context', _l( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
188 | 188 | } |
189 | 189 | |
190 | 190 | if ( in_array( $request['orderby'], array( 'email', 'registered_date' ), true ) && ! current_user_can( 'list_users' ) ) { |
191 | | return new WP_Error( 'rest_forbidden_orderby', __( 'Sorry, you are not allowed to order users by this parameter.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 191 | 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() ) ); |
192 | 192 | } |
193 | 193 | |
194 | 194 | return true; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
336 | 336 | * @return WP_User|WP_Error True if ID is valid, WP_Error otherwise. |
337 | 337 | */ |
338 | 338 | protected function get_user( $id ) { |
339 | | $error = new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) ); |
| 339 | $error = new WP_Error( 'rest_user_invalid_id', _l( 'Invalid user ID.' ), array( 'status' => 404 ) ); |
340 | 340 | if ( (int) $id <= 0 ) { |
341 | 341 | return $error; |
342 | 342 | } |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
375 | 375 | } |
376 | 376 | |
377 | 377 | if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { |
378 | | return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 378 | return new WP_Error( 'rest_user_cannot_view', _l( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
379 | 379 | } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { |
380 | | return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 380 | return new WP_Error( 'rest_user_cannot_view', _l( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); |
381 | 381 | } |
382 | 382 | |
383 | 383 | return true; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
417 | 417 | $current_user_id = get_current_user_id(); |
418 | 418 | |
419 | 419 | if ( empty( $current_user_id ) ) { |
420 | | return new WP_Error( 'rest_not_logged_in', __( 'You are not currently logged in.' ), array( 'status' => 401 ) ); |
| 420 | return new WP_Error( 'rest_not_logged_in', _l( 'You are not currently logged in.' ), array( 'status' => 401 ) ); |
421 | 421 | } |
422 | 422 | |
423 | 423 | $user = wp_get_current_user(); |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
440 | 440 | public function create_item_permissions_check( $request ) { |
441 | 441 | |
442 | 442 | if ( ! current_user_can( 'create_users' ) ) { |
443 | | return new WP_Error( 'rest_cannot_create_user', __( 'Sorry, you are not allowed to create new users.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 443 | return new WP_Error( 'rest_cannot_create_user', _l( 'Sorry, you are not allowed to create new users.' ), array( 'status' => rest_authorization_required_code() ) ); |
444 | 444 | } |
445 | 445 | |
446 | 446 | return true; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
457 | 457 | */ |
458 | 458 | public function create_item( $request ) { |
459 | 459 | if ( ! empty( $request['id'] ) ) { |
460 | | return new WP_Error( 'rest_user_exists', __( 'Cannot create existing user.' ), array( 'status' => 400 ) ); |
| 460 | return new WP_Error( 'rest_user_exists', _l( 'Cannot create existing user.' ), array( 'status' => 400 ) ); |
461 | 461 | } |
462 | 462 | |
463 | 463 | $schema = $this->get_item_schema(); |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
476 | 476 | $ret = wpmu_validate_user_signup( $user->user_login, $user->user_email ); |
477 | 477 | |
478 | 478 | if ( is_wp_error( $ret['errors'] ) && ! empty( $ret['errors']->errors ) ) { |
479 | | $error = new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
| 479 | $error = new WP_Error( 'rest_invalid_param', _l( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); |
480 | 480 | foreach ( $ret['errors']->errors as $code => $messages ) { |
481 | 481 | foreach ( $messages as $message ) { |
482 | 482 | $error->add( $code, $message ); |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
493 | 493 | $user_id = wpmu_create_user( $user->user_login, $user->user_pass, $user->user_email ); |
494 | 494 | |
495 | 495 | if ( ! $user_id ) { |
496 | | return new WP_Error( 'rest_user_create', __( 'Error creating new user.' ), array( 'status' => 500 ) ); |
| 496 | return new WP_Error( 'rest_user_create', _l( 'Error creating new user.' ), array( 'status' => 500 ) ); |
497 | 497 | } |
498 | 498 | |
499 | 499 | $user->ID = $user_id; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
571 | 571 | } |
572 | 572 | |
573 | 573 | if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
574 | | return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 574 | return new WP_Error( 'rest_cannot_edit', _l( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
575 | 575 | } |
576 | 576 | |
577 | 577 | if ( ! empty( $request['roles'] ) && ! current_user_can( 'edit_users' ) ) { |
578 | | 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() ) ); |
| 578 | 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() ) ); |
579 | 579 | } |
580 | 580 | |
581 | 581 | 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 { |
713 | 713 | } |
714 | 714 | |
715 | 715 | if ( ! current_user_can( 'delete_user', $user->ID ) ) { |
716 | | return new WP_Error( 'rest_user_cannot_delete', __( 'Sorry, you are not allowed to delete this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 716 | return new WP_Error( 'rest_user_cannot_delete', _l( 'Sorry, you are not allowed to delete this user.' ), array( 'status' => rest_authorization_required_code() ) ); |
717 | 717 | } |
718 | 718 | |
719 | 719 | return true; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
731 | 731 | public function delete_item( $request ) { |
732 | 732 | // We don't support delete requests in multisite. |
733 | 733 | if ( is_multisite() ) { |
734 | | return new WP_Error( 'rest_cannot_delete', __( 'The user cannot be deleted.' ), array( 'status' => 501 ) ); |
| 734 | return new WP_Error( 'rest_cannot_delete', _l( 'The user cannot be deleted.' ), array( 'status' => 501 ) ); |
735 | 735 | } |
736 | 736 | $user = $this->get_user( $request['id'] ); |
737 | 737 | if ( is_wp_error( $user ) ) { |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
744 | 744 | |
745 | 745 | // We don't support trashing for users. |
746 | 746 | if ( ! $force ) { |
747 | | return new WP_Error( 'rest_trash_not_supported', __( 'Users do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
| 747 | return new WP_Error( 'rest_trash_not_supported', _l( 'Users do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) ); |
748 | 748 | } |
749 | 749 | |
750 | 750 | if ( ! empty( $reassign ) ) { |
751 | 751 | if ( $reassign === $id || ! get_userdata( $reassign ) ) { |
752 | | return new WP_Error( 'rest_user_invalid_reassign', __( 'Invalid user ID for reassignment.' ), array( 'status' => 400 ) ); |
| 752 | return new WP_Error( 'rest_user_invalid_reassign', _l( 'Invalid user ID for reassignment.' ), array( 'status' => 400 ) ); |
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
763 | 763 | $result = wp_delete_user( $id, $reassign ); |
764 | 764 | |
765 | 765 | if ( ! $result ) { |
766 | | return new WP_Error( 'rest_cannot_delete', __( 'The user cannot be deleted.' ), array( 'status' => 500 ) ); |
| 766 | return new WP_Error( 'rest_cannot_delete', _l( 'The user cannot be deleted.' ), array( 'status' => 500 ) ); |
767 | 767 | } |
768 | 768 | |
769 | 769 | $response = new WP_REST_Response(); |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1043 | 1043 | |
1044 | 1044 | if ( ! isset( $wp_roles->role_objects[ $role ] ) ) { |
1045 | 1045 | /* translators: %s: role key */ |
1046 | | return new WP_Error( 'rest_user_invalid_role', sprintf( __( 'The role %s does not exist.' ), $role ), array( 'status' => 400 ) ); |
| 1046 | return new WP_Error( 'rest_user_invalid_role', sprintf( _l( 'The role %s does not exist.' ), $role ), array( 'status' => 400 ) ); |
1047 | 1047 | } |
1048 | 1048 | |
1049 | 1049 | $potential_role = $wp_roles->role_objects[ $role ]; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1057 | 1057 | && get_current_user_id() === $user_id |
1058 | 1058 | && ! $potential_role->has_cap( 'edit_users' ) |
1059 | 1059 | ) { |
1060 | | return new WP_Error( 'rest_user_invalid_role', __( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => rest_authorization_required_code() ) ); |
| 1060 | 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() ) ); |
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | /** Include admin functions to get access to get_editable_roles() */ |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1067 | 1067 | $editable_roles = get_editable_roles(); |
1068 | 1068 | |
1069 | 1069 | if ( empty( $editable_roles[ $role ] ) ) { |
1070 | | return new WP_Error( 'rest_user_invalid_role', __( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => 403 ) ); |
| 1070 | return new WP_Error( 'rest_user_invalid_role', _l( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => 403 ) ); |
1071 | 1071 | } |
1072 | 1072 | } |
1073 | 1073 | |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1091 | 1091 | $username = (string) $value; |
1092 | 1092 | |
1093 | 1093 | if ( ! validate_username( $username ) ) { |
1094 | | return new WP_Error( 'rest_user_invalid_username', __( 'Username contains invalid characters.' ), array( 'status' => 400 ) ); |
| 1094 | return new WP_Error( 'rest_user_invalid_username', _l( 'Username contains invalid characters.' ), array( 'status' => 400 ) ); |
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | /** This filter is documented in wp-includes/user.php */ |
1098 | 1098 | $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
1099 | 1099 | |
1100 | 1100 | if ( in_array( strtolower( $username ), array_map( 'strtolower', $illegal_logins ) ) ) { |
1101 | | return new WP_Error( 'rest_user_invalid_username', __( 'Sorry, that username is not allowed.' ), array( 'status' => 400 ) ); |
| 1101 | return new WP_Error( 'rest_user_invalid_username', _l( 'Sorry, that username is not allowed.' ), array( 'status' => 400 ) ); |
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | return $username; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1121 | 1121 | $password = (string) $value; |
1122 | 1122 | |
1123 | 1123 | if ( empty( $password ) ) { |
1124 | | return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot be empty.' ), array( 'status' => 400 ) ); |
| 1124 | return new WP_Error( 'rest_user_invalid_password', _l( 'Passwords cannot be empty.' ), array( 'status' => 400 ) ); |
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | if ( false !== strpos( $password, "\\" ) ) { |
1128 | | return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) ); |
| 1128 | return new WP_Error( 'rest_user_invalid_password', _l( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) ); |
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | return $password; |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1146 | 1146 | 'type' => 'object', |
1147 | 1147 | 'properties' => array( |
1148 | 1148 | 'id' => array( |
1149 | | 'description' => __( 'Unique identifier for the user.' ), |
| 1149 | 'description' => _l( 'Unique identifier for the user.' ), |
1150 | 1150 | 'type' => 'integer', |
1151 | 1151 | 'context' => array( 'embed', 'view', 'edit' ), |
1152 | 1152 | 'readonly' => true, |
1153 | 1153 | ), |
1154 | 1154 | 'username' => array( |
1155 | | 'description' => __( 'Login name for the user.' ), |
| 1155 | 'description' => _l( 'Login name for the user.' ), |
1156 | 1156 | 'type' => 'string', |
1157 | 1157 | 'context' => array( 'edit' ), |
1158 | 1158 | 'required' => true, |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1161 | 1161 | ), |
1162 | 1162 | ), |
1163 | 1163 | 'name' => array( |
1164 | | 'description' => __( 'Display name for the user.' ), |
| 1164 | 'description' => _l( 'Display name for the user.' ), |
1165 | 1165 | 'type' => 'string', |
1166 | 1166 | 'context' => array( 'embed', 'view', 'edit' ), |
1167 | 1167 | 'arg_options' => array( |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1169 | 1169 | ), |
1170 | 1170 | ), |
1171 | 1171 | 'first_name' => array( |
1172 | | 'description' => __( 'First name for the user.' ), |
| 1172 | 'description' => _l( 'First name for the user.' ), |
1173 | 1173 | 'type' => 'string', |
1174 | 1174 | 'context' => array( 'edit' ), |
1175 | 1175 | 'arg_options' => array( |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1177 | 1177 | ), |
1178 | 1178 | ), |
1179 | 1179 | 'last_name' => array( |
1180 | | 'description' => __( 'Last name for the user.' ), |
| 1180 | 'description' => _l( 'Last name for the user.' ), |
1181 | 1181 | 'type' => 'string', |
1182 | 1182 | 'context' => array( 'edit' ), |
1183 | 1183 | 'arg_options' => array( |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1185 | 1185 | ), |
1186 | 1186 | ), |
1187 | 1187 | 'email' => array( |
1188 | | 'description' => __( 'The email address for the user.' ), |
| 1188 | 'description' => _l( 'The email address for the user.' ), |
1189 | 1189 | 'type' => 'string', |
1190 | 1190 | 'format' => 'email', |
1191 | 1191 | 'context' => array( 'edit' ), |
1192 | 1192 | 'required' => true, |
1193 | 1193 | ), |
1194 | 1194 | 'url' => array( |
1195 | | 'description' => __( 'URL of the user.' ), |
| 1195 | 'description' => _l( 'URL of the user.' ), |
1196 | 1196 | 'type' => 'string', |
1197 | 1197 | 'format' => 'uri', |
1198 | 1198 | 'context' => array( 'embed', 'view', 'edit' ), |
1199 | 1199 | ), |
1200 | 1200 | 'description' => array( |
1201 | | 'description' => __( 'Description of the user.' ), |
| 1201 | 'description' => _l( 'Description of the user.' ), |
1202 | 1202 | 'type' => 'string', |
1203 | 1203 | 'context' => array( 'embed', 'view', 'edit' ), |
1204 | 1204 | ), |
1205 | 1205 | 'link' => array( |
1206 | | 'description' => __( 'Author URL of the user.' ), |
| 1206 | 'description' => _l( 'Author URL of the user.' ), |
1207 | 1207 | 'type' => 'string', |
1208 | 1208 | 'format' => 'uri', |
1209 | 1209 | 'context' => array( 'embed', 'view', 'edit' ), |
1210 | 1210 | 'readonly' => true, |
1211 | 1211 | ), |
1212 | 1212 | 'locale' => array( |
1213 | | 'description' => __( 'Locale for the user.' ), |
| 1213 | 'description' => _l( 'Locale for the user.' ), |
1214 | 1214 | 'type' => 'string', |
1215 | 1215 | 'enum' => array_merge( array( '', 'en_US' ), get_available_languages() ), |
1216 | 1216 | 'context' => array( 'edit' ), |
1217 | 1217 | ), |
1218 | 1218 | 'nickname' => array( |
1219 | | 'description' => __( 'The nickname for the user.' ), |
| 1219 | 'description' => _l( 'The nickname for the user.' ), |
1220 | 1220 | 'type' => 'string', |
1221 | 1221 | 'context' => array( 'edit' ), |
1222 | 1222 | 'arg_options' => array( |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1224 | 1224 | ), |
1225 | 1225 | ), |
1226 | 1226 | 'slug' => array( |
1227 | | 'description' => __( 'An alphanumeric identifier for the user.' ), |
| 1227 | 'description' => _l( 'An alphanumeric identifier for the user.' ), |
1228 | 1228 | 'type' => 'string', |
1229 | 1229 | 'context' => array( 'embed', 'view', 'edit' ), |
1230 | 1230 | 'arg_options' => array( |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1232 | 1232 | ), |
1233 | 1233 | ), |
1234 | 1234 | 'registered_date' => array( |
1235 | | 'description' => __( 'Registration date for the user.' ), |
| 1235 | 'description' => _l( 'Registration date for the user.' ), |
1236 | 1236 | 'type' => 'string', |
1237 | 1237 | 'format' => 'date-time', |
1238 | 1238 | 'context' => array( 'edit' ), |
1239 | 1239 | 'readonly' => true, |
1240 | 1240 | ), |
1241 | 1241 | 'roles' => array( |
1242 | | 'description' => __( 'Roles assigned to the user.' ), |
| 1242 | 'description' => _l( 'Roles assigned to the user.' ), |
1243 | 1243 | 'type' => 'array', |
1244 | 1244 | 'items' => array( |
1245 | 1245 | 'type' => 'string', |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1247 | 1247 | 'context' => array( 'edit' ), |
1248 | 1248 | ), |
1249 | 1249 | 'password' => array( |
1250 | | 'description' => __( 'Password for the user (never included).' ), |
| 1250 | 'description' => _l( 'Password for the user (never included).' ), |
1251 | 1251 | 'type' => 'string', |
1252 | 1252 | 'context' => array(), // Password is never displayed. |
1253 | 1253 | 'required' => true, |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1256 | 1256 | ), |
1257 | 1257 | ), |
1258 | 1258 | 'capabilities' => array( |
1259 | | 'description' => __( 'All capabilities assigned to the user.' ), |
| 1259 | 'description' => _l( 'All capabilities assigned to the user.' ), |
1260 | 1260 | 'type' => 'object', |
1261 | 1261 | 'context' => array( 'edit' ), |
1262 | 1262 | 'readonly' => true, |
1263 | 1263 | ), |
1264 | 1264 | 'extra_capabilities' => array( |
1265 | | 'description' => __( 'Any extra capabilities assigned to the user.' ), |
| 1265 | 'description' => _l( 'Any extra capabilities assigned to the user.' ), |
1266 | 1266 | 'type' => 'object', |
1267 | 1267 | 'context' => array( 'edit' ), |
1268 | 1268 | 'readonly' => true, |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1278 | 1278 | foreach ( $avatar_sizes as $size ) { |
1279 | 1279 | $avatar_properties[ $size ] = array( |
1280 | 1280 | /* translators: %d: avatar image size in pixels */ |
1281 | | 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ), |
| 1281 | 'description' => sprintf( _l( 'Avatar URL with image size of %d pixels.' ), $size ), |
1282 | 1282 | 'type' => 'string', |
1283 | 1283 | 'format' => 'uri', |
1284 | 1284 | 'context' => array( 'embed', 'view', 'edit' ), |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | $schema['properties']['avatar_urls'] = array( |
1289 | | 'description' => __( 'Avatar URLs for the user.' ), |
| 1289 | 'description' => _l( 'Avatar URLs for the user.' ), |
1290 | 1290 | 'type' => 'object', |
1291 | 1291 | 'context' => array( 'embed', 'view', 'edit' ), |
1292 | 1292 | 'readonly' => true, |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1313 | 1313 | $query_params['context']['default'] = 'view'; |
1314 | 1314 | |
1315 | 1315 | $query_params['exclude'] = array( |
1316 | | 'description' => __( 'Ensure result set excludes specific IDs.' ), |
| 1316 | 'description' => _l( 'Ensure result set excludes specific IDs.' ), |
1317 | 1317 | 'type' => 'array', |
1318 | 1318 | 'items' => array( |
1319 | 1319 | 'type' => 'integer', |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1322 | 1322 | ); |
1323 | 1323 | |
1324 | 1324 | $query_params['include'] = array( |
1325 | | 'description' => __( 'Limit result set to specific IDs.' ), |
| 1325 | 'description' => _l( 'Limit result set to specific IDs.' ), |
1326 | 1326 | 'type' => 'array', |
1327 | 1327 | 'items' => array( |
1328 | 1328 | 'type' => 'integer', |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1331 | 1331 | ); |
1332 | 1332 | |
1333 | 1333 | $query_params['offset'] = array( |
1334 | | 'description' => __( 'Offset the result set by a specific number of items.' ), |
| 1334 | 'description' => _l( 'Offset the result set by a specific number of items.' ), |
1335 | 1335 | 'type' => 'integer', |
1336 | 1336 | ); |
1337 | 1337 | |
1338 | 1338 | $query_params['order'] = array( |
1339 | 1339 | 'default' => 'asc', |
1340 | | 'description' => __( 'Order sort attribute ascending or descending.' ), |
| 1340 | 'description' => _l( 'Order sort attribute ascending or descending.' ), |
1341 | 1341 | 'enum' => array( 'asc', 'desc' ), |
1342 | 1342 | 'type' => 'string', |
1343 | 1343 | ); |
1344 | 1344 | |
1345 | 1345 | $query_params['orderby'] = array( |
1346 | 1346 | 'default' => 'name', |
1347 | | 'description' => __( 'Sort collection by object attribute.' ), |
| 1347 | 'description' => _l( 'Sort collection by object attribute.' ), |
1348 | 1348 | 'enum' => array( |
1349 | 1349 | 'id', |
1350 | 1350 | 'include', |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1358 | 1358 | ); |
1359 | 1359 | |
1360 | 1360 | $query_params['slug'] = array( |
1361 | | 'description' => __( 'Limit result set to users with one or more specific slugs.' ), |
| 1361 | 'description' => _l( 'Limit result set to users with one or more specific slugs.' ), |
1362 | 1362 | 'type' => 'array', |
1363 | 1363 | 'items' => array( |
1364 | 1364 | 'type' => 'string', |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1366 | 1366 | ); |
1367 | 1367 | |
1368 | 1368 | $query_params['roles'] = array( |
1369 | | 'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ), |
| 1369 | 'description' => _l( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ), |
1370 | 1370 | 'type' => 'array', |
1371 | 1371 | 'items' => array( |
1372 | 1372 | '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 eaf70a5781..2b44d89f71 100644
|
|
abstract class WP_REST_Meta_Fields { |
180 | 180 | return new WP_Error( |
181 | 181 | 'rest_cannot_delete', |
182 | 182 | /* translators: %s: custom field key */ |
183 | | sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| 183 | sprintf( _l( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
184 | 184 | array( 'key' => $name, 'status' => rest_authorization_required_code() ) |
185 | 185 | ); |
186 | 186 | } |
… |
… |
abstract class WP_REST_Meta_Fields { |
188 | 188 | if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ) ) ) { |
189 | 189 | return new WP_Error( |
190 | 190 | 'rest_meta_database_error', |
191 | | __( 'Could not delete meta value from database.' ), |
| 191 | _l( 'Could not delete meta value from database.' ), |
192 | 192 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
193 | 193 | ); |
194 | 194 | } |
… |
… |
abstract class WP_REST_Meta_Fields { |
216 | 216 | return new WP_Error( |
217 | 217 | 'rest_cannot_update', |
218 | 218 | /* translators: %s: custom field key */ |
219 | | sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| 219 | sprintf( _l( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
220 | 220 | array( 'key' => $name, 'status' => rest_authorization_required_code() ) |
221 | 221 | ); |
222 | 222 | } |
… |
… |
abstract class WP_REST_Meta_Fields { |
251 | 251 | if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { |
252 | 252 | return new WP_Error( |
253 | 253 | 'rest_meta_database_error', |
254 | | __( 'Could not update meta value in database.' ), |
| 254 | _l( 'Could not update meta value in database.' ), |
255 | 255 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
256 | 256 | ); |
257 | 257 | } |
… |
… |
abstract class WP_REST_Meta_Fields { |
261 | 261 | if ( ! add_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { |
262 | 262 | return new WP_Error( |
263 | 263 | 'rest_meta_database_error', |
264 | | __( 'Could not update meta value in database.' ), |
| 264 | _l( 'Could not update meta value in database.' ), |
265 | 265 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
266 | 266 | ); |
267 | 267 | } |
… |
… |
abstract class WP_REST_Meta_Fields { |
288 | 288 | return new WP_Error( |
289 | 289 | 'rest_cannot_update', |
290 | 290 | /* translators: %s: custom field key */ |
291 | | sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
| 291 | sprintf( _l( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), |
292 | 292 | array( 'key' => $name, 'status' => rest_authorization_required_code() ) |
293 | 293 | ); |
294 | 294 | } |
… |
… |
abstract class WP_REST_Meta_Fields { |
308 | 308 | if ( ! update_metadata( $meta_type, $object_id, $meta_key, $meta_value ) ) { |
309 | 309 | return new WP_Error( |
310 | 310 | 'rest_meta_database_error', |
311 | | __( 'Could not update meta value in database.' ), |
| 311 | _l( 'Could not update meta value in database.' ), |
312 | 312 | array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) |
313 | 313 | ); |
314 | 314 | } |
… |
… |
abstract class WP_REST_Meta_Fields { |
387 | 387 | $fields = $this->get_registered_fields(); |
388 | 388 | |
389 | 389 | $schema = array( |
390 | | 'description' => __( 'Meta fields.' ), |
| 390 | 'description' => _l( 'Meta fields.' ), |
391 | 391 | 'type' => 'object', |
392 | 392 | 'context' => array( 'view', 'edit' ), |
393 | 393 | 'properties' => array(), |
-
diff --git tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php
index 30246932bf..68bca079f6 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 | |