- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r41735 r42343 44 44 public function register_routes() { 45 45 46 register_rest_route( $this->namespace, '/' . $this->rest_base, array( 47 array( 48 'methods' => WP_REST_Server::READABLE, 49 'callback' => array( $this, 'get_items' ), 50 'permission_callback' => array( $this, 'get_items_permissions_check' ), 51 'args' => $this->get_collection_params(), 52 ), 53 array( 54 'methods' => WP_REST_Server::CREATABLE, 55 'callback' => array( $this, 'create_item' ), 56 'permission_callback' => array( $this, 'create_item_permissions_check' ), 57 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), 58 ), 59 'schema' => array( $this, 'get_public_item_schema' ), 60 ) ); 61 62 register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( 63 'args' => array( 64 'id' => array( 65 'description' => __( 'Unique identifier for the object.' ), 66 'type' => 'integer', 67 ), 68 ), 69 array( 70 'methods' => WP_REST_Server::READABLE, 71 'callback' => array( $this, 'get_item' ), 72 'permission_callback' => array( $this, 'get_item_permissions_check' ), 73 'args' => array( 74 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 75 'password' => array( 76 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), 77 'type' => 'string', 46 register_rest_route( 47 $this->namespace, '/' . $this->rest_base, array( 48 array( 49 'methods' => WP_REST_Server::READABLE, 50 'callback' => array( $this, 'get_items' ), 51 'permission_callback' => array( $this, 'get_items_permissions_check' ), 52 'args' => $this->get_collection_params(), 53 ), 54 array( 55 'methods' => WP_REST_Server::CREATABLE, 56 'callback' => array( $this, 'create_item' ), 57 'permission_callback' => array( $this, 'create_item_permissions_check' ), 58 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), 59 ), 60 'schema' => array( $this, 'get_public_item_schema' ), 61 ) 62 ); 63 64 register_rest_route( 65 $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( 66 'args' => array( 67 'id' => array( 68 'description' => __( 'Unique identifier for the object.' ), 69 'type' => 'integer', 78 70 ), 79 71 ), 80 ), 81 array( 82 'methods' => WP_REST_Server::EDITABLE, 83 'callback' => array( $this, 'update_item' ), 84 'permission_callback' => array( $this, 'update_item_permissions_check' ), 85 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 86 ), 87 array( 88 'methods' => WP_REST_Server::DELETABLE, 89 'callback' => array( $this, 'delete_item' ), 90 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 91 'args' => array( 92 'force' => array( 93 'type' => 'boolean', 94 'default' => false, 95 'description' => __( 'Whether to bypass trash and force deletion.' ), 72 array( 73 'methods' => WP_REST_Server::READABLE, 74 'callback' => array( $this, 'get_item' ), 75 'permission_callback' => array( $this, 'get_item_permissions_check' ), 76 'args' => array( 77 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 78 'password' => array( 79 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), 80 'type' => 'string', 81 ), 96 82 ), 97 'password' => array( 98 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), 99 'type' => 'string', 83 ), 84 array( 85 'methods' => WP_REST_Server::EDITABLE, 86 'callback' => array( $this, 'update_item' ), 87 'permission_callback' => array( $this, 'update_item_permissions_check' ), 88 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 89 ), 90 array( 91 'methods' => WP_REST_Server::DELETABLE, 92 'callback' => array( $this, 'delete_item' ), 93 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 94 'args' => array( 95 'force' => array( 96 'type' => 'boolean', 97 'default' => false, 98 'description' => __( 'Whether to bypass trash and force deletion.' ), 99 ), 100 'password' => array( 101 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), 102 'type' => 'string', 103 ), 100 104 ), 101 105 ), 102 ),103 'schema' => array( $this, 'get_public_item_schema' ),104 ) );106 'schema' => array( $this, 'get_public_item_schema' ), 107 ) 108 ); 105 109 } 106 110 … … 246 250 $prepared_args = apply_filters( 'rest_comment_query', $prepared_args, $request ); 247 251 248 $query = new WP_Comment_Query;252 $query = new WP_Comment_Query; 249 253 $query_result = $query->query( $prepared_args ); 250 254 … … 256 260 } 257 261 258 $data = $this->prepare_item_for_response( $comment, $request );262 $data = $this->prepare_item_for_response( $comment, $request ); 259 263 $comments[] = $this->prepare_response_for_collection( $data ); 260 264 } … … 267 271 unset( $prepared_args['number'], $prepared_args['offset'] ); 268 272 269 $query = new WP_Comment_Query;273 $query = new WP_Comment_Query; 270 274 $prepared_args['count'] = true; 271 275 272 276 $total_comments = $query->query( $prepared_args ); 273 $max_pages = ceil( $total_comments / $request['per_page'] );277 $max_pages = ceil( $total_comments / $request['per_page'] ); 274 278 } 275 279 … … 315 319 } 316 320 317 $id = (int) $id;321 $id = (int) $id; 318 322 $comment = get_comment( $id ); 319 323 if ( empty( $comment ) ) { … … 376 380 } 377 381 378 $data = $this->prepare_item_for_response( $comment, $request );382 $data = $this->prepare_item_for_response( $comment, $request ); 379 383 $response = rest_ensure_response( $data ); 380 384 … … 416 420 // Limit who can set comment `author`, `author_ip` or `status` to anything other than the default. 417 421 if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { 418 return new WP_Error( 'rest_comment_invalid_author', 422 return new WP_Error( 423 'rest_comment_invalid_author', 419 424 /* translators: %s: request parameter */ 420 425 sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), … … 425 430 if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) { 426 431 if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) { 427 return new WP_Error( 'rest_comment_invalid_author_ip', 432 return new WP_Error( 433 'rest_comment_invalid_author_ip', 428 434 /* translators: %s: request parameter */ 429 435 sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ), … … 434 440 435 441 if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) { 436 return new WP_Error( 'rest_comment_invalid_status', 442 return new WP_Error( 443 'rest_comment_invalid_status', 437 444 /* translators: %s: request parameter */ 438 445 sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ), … … 516 523 $user = wp_get_current_user(); 517 524 518 $prepared_comment['user_id'] = $user->ID;519 $prepared_comment['comment_author'] = $user->display_name;525 $prepared_comment['user_id'] = $user->ID; 526 $prepared_comment['comment_author'] = $user->display_name; 520 527 $prepared_comment['comment_author_email'] = $user->user_email; 521 $prepared_comment['comment_author_url'] = $user->user_url;528 $prepared_comment['comment_author_url'] = $user->user_url; 522 529 } 523 530 … … 632 639 $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) ); 633 640 634 635 641 return $response; 636 642 } … … 805 811 if ( $force ) { 806 812 $previous = $this->prepare_item_for_response( $comment, $request ); 807 $result = wp_delete_comment( $comment->comment_ID, true );813 $result = wp_delete_comment( $comment->comment_ID, true ); 808 814 $response = new WP_REST_Response(); 809 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 815 $response->set_data( 816 array( 817 'deleted' => true, 818 'previous' => $previous->get_data(), 819 ) 820 ); 810 821 } else { 811 822 // If this type doesn't support trashing, error out. … … 819 830 } 820 831 821 $result = wp_trash_comment( $comment->comment_ID );822 $comment = get_comment( $comment->comment_ID );832 $result = wp_trash_comment( $comment->comment_ID ); 833 $comment = get_comment( $comment->comment_ID ); 823 834 $response = $this->prepare_item_for_response( $comment, $request ); 824 835 } … … 853 864 public function prepare_item_for_response( $comment, $request ) { 854 865 $data = array( 855 'id' => (int) $comment->comment_ID,856 'post' => (int) $comment->comment_post_ID,857 'parent' => (int) $comment->comment_parent,858 'author' => (int) $comment->user_id,859 'author_name' => $comment->comment_author,860 'author_email' => $comment->comment_author_email,861 'author_url' => $comment->comment_author_url,862 'author_ip' => $comment->comment_author_IP,863 'author_user_agent' => $comment->comment_agent,864 'date' => mysql_to_rfc3339( $comment->comment_date ),865 'date_gmt' => mysql_to_rfc3339( $comment->comment_date_gmt ),866 'content' => array(866 'id' => (int) $comment->comment_ID, 867 'post' => (int) $comment->comment_post_ID, 868 'parent' => (int) $comment->comment_parent, 869 'author' => (int) $comment->user_id, 870 'author_name' => $comment->comment_author, 871 'author_email' => $comment->comment_author_email, 872 'author_url' => $comment->comment_author_url, 873 'author_ip' => $comment->comment_author_IP, 874 'author_user_agent' => $comment->comment_agent, 875 'date' => mysql_to_rfc3339( $comment->comment_date ), 876 'date_gmt' => mysql_to_rfc3339( $comment->comment_date_gmt ), 877 'content' => array( 867 878 /** This filter is documented in wp-includes/comment-template.php */ 868 879 'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ), 869 880 'raw' => $comment->comment_content, 870 881 ), 871 'link' => get_comment_link( $comment ),872 'status' => $this->prepare_status_response( $comment->comment_approved ),873 'type' => get_comment_type( $comment->comment_ID ),882 'link' => get_comment_link( $comment ), 883 'status' => $this->prepare_status_response( $comment->comment_approved ), 884 'type' => get_comment_type( $comment->comment_ID ), 874 885 ); 875 886 … … 917 928 protected function prepare_links( $comment ) { 918 929 $links = array( 919 'self' => array(930 'self' => array( 920 931 'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ), 921 932 ), … … 936 947 937 948 if ( ! empty( $post->ID ) ) { 938 $obj = get_post_type_object( $post->post_type );949 $obj = get_post_type_object( $post->post_type ); 939 950 $base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name; 940 951 … … 955 966 956 967 // Only grab one comment to verify the comment has children. 957 $comment_children = $comment->get_children( array( 958 'number' => 1, 959 'count' => true 960 ) ); 968 $comment_children = $comment->get_children( 969 array( 970 'number' => 1, 971 'count' => true, 972 ) 973 ); 961 974 962 975 if ( ! empty( $comment_children ) ) { 963 976 $args = array( 964 'parent' => $comment->comment_ID 977 'parent' => $comment->comment_ID, 965 978 ); 966 979 … … 1071 1084 1072 1085 if ( $user->exists() ) { 1073 $prepared_comment['user_id'] = $user->ID;1074 $prepared_comment['comment_author'] = $user->display_name;1086 $prepared_comment['user_id'] = $user->ID; 1087 $prepared_comment['comment_author'] = $user->display_name; 1075 1088 $prepared_comment['comment_author_email'] = $user->user_email; 1076 $prepared_comment['comment_author_url'] = $user->user_url;1089 $prepared_comment['comment_author_url'] = $user->user_url; 1077 1090 } else { 1078 1091 return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); … … 1142 1155 public function get_item_schema() { 1143 1156 $schema = array( 1144 '$schema' => 'http://json-schema.org/draft-04/schema#',1145 'title' => 'comment',1146 'type' => 'object',1147 'properties' => array(1148 'id' => array(1149 'description' => __( 'Unique identifier for the object.' ),1150 'type' => 'integer',1151 'context' => array( 'view', 'edit', 'embed' ),1152 'readonly' => true,1153 ), 1154 'author' => array(1155 'description' => __( 'The ID of the user object, if author was a user.' ),1156 'type' => 'integer',1157 'context' => array( 'view', 'edit', 'embed' ),1158 ), 1159 'author_email' => array(1160 'description' => __( 'Email address for the object author.' ),1161 'type' => 'string',1162 'format' => 'email',1163 'context' => array( 'edit' ),1164 'arg_options' => array(1157 '$schema' => 'http://json-schema.org/draft-04/schema#', 1158 'title' => 'comment', 1159 'type' => 'object', 1160 'properties' => array( 1161 'id' => array( 1162 'description' => __( 'Unique identifier for the object.' ), 1163 'type' => 'integer', 1164 'context' => array( 'view', 'edit', 'embed' ), 1165 'readonly' => true, 1166 ), 1167 'author' => array( 1168 'description' => __( 'The ID of the user object, if author was a user.' ), 1169 'type' => 'integer', 1170 'context' => array( 'view', 'edit', 'embed' ), 1171 ), 1172 'author_email' => array( 1173 'description' => __( 'Email address for the object author.' ), 1174 'type' => 'string', 1175 'format' => 'email', 1176 'context' => array( 'edit' ), 1177 'arg_options' => array( 1165 1178 'sanitize_callback' => array( $this, 'check_comment_author_email' ), 1166 1179 'validate_callback' => null, // skip built-in validation of 'email'. 1167 1180 ), 1168 1181 ), 1169 'author_ip' => array(1170 'description' => __( 'IP address for the object author.' ),1171 'type' => 'string',1172 'format' => 'ip',1173 'context' => array( 'edit' ),1174 ), 1175 'author_name' => array(1176 'description' => __( 'Display name for the object author.' ),1177 'type' => 'string',1178 'context' => array( 'view', 'edit', 'embed' ),1179 'arg_options' => array(1182 'author_ip' => array( 1183 'description' => __( 'IP address for the object author.' ), 1184 'type' => 'string', 1185 'format' => 'ip', 1186 'context' => array( 'edit' ), 1187 ), 1188 'author_name' => array( 1189 'description' => __( 'Display name for the object author.' ), 1190 'type' => 'string', 1191 'context' => array( 'view', 'edit', 'embed' ), 1192 'arg_options' => array( 1180 1193 'sanitize_callback' => 'sanitize_text_field', 1181 1194 ), 1182 1195 ), 1183 'author_url' => array(1184 'description' => __( 'URL for the object author.' ),1185 'type' => 'string',1186 'format' => 'uri',1187 'context' => array( 'view', 'edit', 'embed' ),1188 ), 1189 'author_user_agent' => array(1190 'description' => __( 'User agent for the object author.' ),1191 'type' => 'string',1192 'context' => array( 'edit' ),1193 'arg_options' => array(1196 'author_url' => array( 1197 'description' => __( 'URL for the object author.' ), 1198 'type' => 'string', 1199 'format' => 'uri', 1200 'context' => array( 'view', 'edit', 'embed' ), 1201 ), 1202 'author_user_agent' => array( 1203 'description' => __( 'User agent for the object author.' ), 1204 'type' => 'string', 1205 'context' => array( 'edit' ), 1206 'arg_options' => array( 1194 1207 'sanitize_callback' => 'sanitize_text_field', 1195 1208 ), 1196 1209 ), 1197 'content' => array(1198 'description' => __( 'The content for the object.' ),1199 'type' => 'object',1200 'context' => array( 'view', 'edit', 'embed' ),1201 'arg_options' => array(1210 'content' => array( 1211 'description' => __( 'The content for the object.' ), 1212 'type' => 'object', 1213 'context' => array( 'view', 'edit', 'embed' ), 1214 'arg_options' => array( 1202 1215 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database() 1203 1216 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() 1204 1217 ), 1205 'properties' => array(1206 'raw' => array(1207 'description' => __( 'Content for the object, as it exists in the database.' ),1208 'type' => 'string',1209 'context' => array( 'edit' ),1218 'properties' => array( 1219 'raw' => array( 1220 'description' => __( 'Content for the object, as it exists in the database.' ), 1221 'type' => 'string', 1222 'context' => array( 'edit' ), 1210 1223 ), 1211 'rendered' => array(1212 'description' => __( 'HTML content for the object, transformed for display.' ),1213 'type' => 'string',1214 'context' => array( 'view', 'edit', 'embed' ),1215 'readonly' => true,1224 'rendered' => array( 1225 'description' => __( 'HTML content for the object, transformed for display.' ), 1226 'type' => 'string', 1227 'context' => array( 'view', 'edit', 'embed' ), 1228 'readonly' => true, 1216 1229 ), 1217 1230 ), 1218 1231 ), 1219 'date' => array(1220 'description' => __( "The date the object was published, in the site's timezone." ),1221 'type' => 'string',1222 'format' => 'date-time',1223 'context' => array( 'view', 'edit', 'embed' ),1224 ), 1225 'date_gmt' => array(1226 'description' => __( 'The date the object was published, as GMT.' ),1227 'type' => 'string',1228 'format' => 'date-time',1229 'context' => array( 'view', 'edit' ),1230 ), 1231 'link' => array(1232 'description' => __( 'URL to the object.' ),1233 'type' => 'string',1234 'format' => 'uri',1235 'context' => array( 'view', 'edit', 'embed' ),1236 'readonly' => true,1237 ), 1238 'parent' => array(1239 'description' => __( 'The ID for the parent of the object.' ),1240 'type' => 'integer',1241 'context' => array( 'view', 'edit', 'embed' ),1242 'default' => 0,1243 ), 1244 'post' => array(1245 'description' => __( 'The ID of the associated post object.' ),1246 'type' => 'integer',1247 'context' => array( 'view', 'edit' ),1248 'default' => 0,1249 ), 1250 'status' => array(1251 'description' => __( 'State of the object.' ),1252 'type' => 'string',1253 'context' => array( 'view', 'edit' ),1254 'arg_options' => array(1232 'date' => array( 1233 'description' => __( "The date the object was published, in the site's timezone." ), 1234 'type' => 'string', 1235 'format' => 'date-time', 1236 'context' => array( 'view', 'edit', 'embed' ), 1237 ), 1238 'date_gmt' => array( 1239 'description' => __( 'The date the object was published, as GMT.' ), 1240 'type' => 'string', 1241 'format' => 'date-time', 1242 'context' => array( 'view', 'edit' ), 1243 ), 1244 'link' => array( 1245 'description' => __( 'URL to the object.' ), 1246 'type' => 'string', 1247 'format' => 'uri', 1248 'context' => array( 'view', 'edit', 'embed' ), 1249 'readonly' => true, 1250 ), 1251 'parent' => array( 1252 'description' => __( 'The ID for the parent of the object.' ), 1253 'type' => 'integer', 1254 'context' => array( 'view', 'edit', 'embed' ), 1255 'default' => 0, 1256 ), 1257 'post' => array( 1258 'description' => __( 'The ID of the associated post object.' ), 1259 'type' => 'integer', 1260 'context' => array( 'view', 'edit' ), 1261 'default' => 0, 1262 ), 1263 'status' => array( 1264 'description' => __( 'State of the object.' ), 1265 'type' => 'string', 1266 'context' => array( 'view', 'edit' ), 1267 'arg_options' => array( 1255 1268 'sanitize_callback' => 'sanitize_key', 1256 1269 ), 1257 1270 ), 1258 'type' => array(1259 'description' => __( 'Type of Comment for the object.' ),1260 'type' => 'string',1261 'context' => array( 'view', 'edit', 'embed' ),1262 'readonly' => true,1271 'type' => array( 1272 'description' => __( 'Type of Comment for the object.' ), 1273 'type' => 'string', 1274 'context' => array( 'view', 'edit', 'embed' ), 1275 'readonly' => true, 1263 1276 ), 1264 1277 ), … … 1280 1293 1281 1294 $schema['properties']['author_avatar_urls'] = array( 1282 'description' => __( 'Avatar URLs for the object author.' ),1283 'type' => 'object',1284 'context' => array( 'view', 'edit', 'embed' ),1285 'readonly' => true,1286 'properties' => $avatar_properties,1295 'description' => __( 'Avatar URLs for the object author.' ), 1296 'type' => 'object', 1297 'context' => array( 'view', 'edit', 'embed' ), 1298 'readonly' => true, 1299 'properties' => $avatar_properties, 1287 1300 ); 1288 1301 } … … 1306 1319 1307 1320 $query_params['after'] = array( 1308 'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ),1309 'type' => 'string',1310 'format' => 'date-time',1321 'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ), 1322 'type' => 'string', 1323 'format' => 'date-time', 1311 1324 ); 1312 1325 1313 1326 $query_params['author'] = array( 1314 'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ),1315 'type' => 'array',1316 'items' => array(1317 'type' => 'integer',1327 'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), 1328 'type' => 'array', 1329 'items' => array( 1330 'type' => 'integer', 1318 1331 ), 1319 1332 ); 1320 1333 1321 1334 $query_params['author_exclude'] = array( 1322 'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ),1323 'type' => 'array',1324 'items' => array(1325 'type' => 'integer',1335 'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), 1336 'type' => 'array', 1337 'items' => array( 1338 'type' => 'integer', 1326 1339 ), 1327 1340 ); 1328 1341 1329 1342 $query_params['author_email'] = array( 1330 'default' => null,1331 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ),1332 'format' => 'email',1333 'type' => 'string',1343 'default' => null, 1344 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), 1345 'format' => 'email', 1346 'type' => 'string', 1334 1347 ); 1335 1348 1336 1349 $query_params['before'] = array( 1337 'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ),1338 'type' => 'string',1339 'format' => 'date-time',1350 'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ), 1351 'type' => 'string', 1352 'format' => 'date-time', 1340 1353 ); 1341 1354 1342 1355 $query_params['exclude'] = array( 1343 'description' => __( 'Ensure result set excludes specific IDs.' ),1344 'type' => 'array',1345 'items' => array(1346 'type' => 'integer',1356 'description' => __( 'Ensure result set excludes specific IDs.' ), 1357 'type' => 'array', 1358 'items' => array( 1359 'type' => 'integer', 1347 1360 ), 1348 'default' => array(),1361 'default' => array(), 1349 1362 ); 1350 1363 1351 1364 $query_params['include'] = array( 1352 'description' => __( 'Limit result set to specific IDs.' ),1353 'type' => 'array',1354 'items' => array(1355 'type' => 'integer',1365 'description' => __( 'Limit result set to specific IDs.' ), 1366 'type' => 'array', 1367 'items' => array( 1368 'type' => 'integer', 1356 1369 ), 1357 'default' => array(),1370 'default' => array(), 1358 1371 ); 1359 1372 1360 1373 $query_params['offset'] = array( 1361 'description' => __( 'Offset the result set by a specific number of items.' ),1362 'type' => 'integer',1363 ); 1364 1365 $query_params['order'] = array(1366 'description' => __( 'Order sort attribute ascending or descending.' ),1367 'type' => 'string',1368 'default' => 'desc',1369 'enum' => array(1374 'description' => __( 'Offset the result set by a specific number of items.' ), 1375 'type' => 'integer', 1376 ); 1377 1378 $query_params['order'] = array( 1379 'description' => __( 'Order sort attribute ascending or descending.' ), 1380 'type' => 'string', 1381 'default' => 'desc', 1382 'enum' => array( 1370 1383 'asc', 1371 1384 'desc', … … 1373 1386 ); 1374 1387 1375 $query_params['orderby'] = array(1376 'description' => __( 'Sort collection by object attribute.' ),1377 'type' => 'string',1378 'default' => 'date_gmt',1379 'enum' => array(1388 $query_params['orderby'] = array( 1389 'description' => __( 'Sort collection by object attribute.' ), 1390 'type' => 'string', 1391 'default' => 'date_gmt', 1392 'enum' => array( 1380 1393 'date', 1381 1394 'date_gmt', … … 1389 1402 1390 1403 $query_params['parent'] = array( 1391 'default' => array(),1392 'description' => __( 'Limit result set to comments of specific parent IDs.' ),1393 'type' => 'array',1394 'items' => array(1395 'type' => 'integer',1404 'default' => array(), 1405 'description' => __( 'Limit result set to comments of specific parent IDs.' ), 1406 'type' => 'array', 1407 'items' => array( 1408 'type' => 'integer', 1396 1409 ), 1397 1410 ); 1398 1411 1399 1412 $query_params['parent_exclude'] = array( 1400 'default' => array(),1401 'description' => __( 'Ensure result set excludes specific parent IDs.' ),1402 'type' => 'array',1403 'items' => array(1404 'type' => 'integer',1413 'default' => array(), 1414 'description' => __( 'Ensure result set excludes specific parent IDs.' ), 1415 'type' => 'array', 1416 'items' => array( 1417 'type' => 'integer', 1405 1418 ), 1406 1419 ); 1407 1420 1408 $query_params['post'] = array(1409 'default' => array(),1410 'description' => __( 'Limit result set to comments assigned to specific post IDs.' ),1411 'type' => 'array',1412 'items' => array(1413 'type' => 'integer',1421 $query_params['post'] = array( 1422 'default' => array(), 1423 'description' => __( 'Limit result set to comments assigned to specific post IDs.' ), 1424 'type' => 'array', 1425 'items' => array( 1426 'type' => 'integer', 1414 1427 ), 1415 1428 ); … … 1467 1480 1468 1481 switch ( $new_status ) { 1469 case 'approved' :1482 case 'approved': 1470 1483 case 'approve': 1471 1484 case '1': … … 1476 1489 $changed = wp_set_comment_status( $comment_id, 'hold' ); 1477 1490 break; 1478 case 'spam' :1491 case 'spam': 1479 1492 $changed = wp_spam_comment( $comment_id ); 1480 1493 break; 1481 case 'unspam' :1494 case 'unspam': 1482 1495 $changed = wp_unspam_comment( $comment_id ); 1483 1496 break; 1484 case 'trash' :1497 case 'trash': 1485 1498 $changed = wp_trash_comment( $comment_id ); 1486 1499 break; 1487 case 'untrash' :1500 case 'untrash': 1488 1501 $changed = wp_untrash_comment( $comment_id ); 1489 1502 break; 1490 default :1503 default: 1491 1504 $changed = false; 1492 1505 break; … … 1509 1522 protected function check_read_post_permission( $post, $request ) { 1510 1523 $posts_controller = new WP_REST_Posts_Controller( $post->post_type ); 1511 $post_type = get_post_type_object( $post->post_type );1524 $post_type = get_post_type_object( $post->post_type ); 1512 1525 1513 1526 $has_password_filter = false; 1514 1527 1515 1528 // Only check password if a specific post was queried for or a single comment 1516 $requested_post = ! empty( $request['post'] ) && ( !is_array( $request['post'] ) || 1 === count( $request['post'] ) );1529 $requested_post = ! empty( $request['post'] ) && ( ! is_array( $request['post'] ) || 1 === count( $request['post'] ) ); 1517 1530 $requested_comment = ! empty( $request['id'] ); 1518 1531 if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post, $request ) ) {
Note: See TracChangeset
for help on using the changeset viewer.