@@ -123,21 +123,15 @@ public function register_routes() {
123123 * @return true|WP_Error True if the request has read access, error object otherwise.
124124 */
125125 public function get_items_permissions_check ( $ request ) {
126- $ is_note = 'note ' === $ request ['type ' ];
127- $ is_edit_context = 'edit ' === $ request ['context ' ];
126+ $ is_note = 'note ' === $ request ['type ' ];
127+ $ is_edit_context = 'edit ' === $ request ['context ' ];
128+ $ protected_params = array ( 'author ' , 'author_exclude ' , 'author_email ' , 'type ' , 'status ' );
129+ $ forbidden_params = array ();
128130
129131 if ( ! empty ( $ request ['post ' ] ) ) {
130132 foreach ( (array ) $ request ['post ' ] as $ post_id ) {
131133 $ post = get_post ( $ post_id );
132134
133- if ( $ post && $ is_note && ! $ this ->check_post_type_supports_notes ( $ post ->post_type ) ) {
134- return new WP_Error (
135- 'rest_comment_not_supported_post_type ' ,
136- __ ( 'Sorry, this post type does not support notes. ' ),
137- array ( 'status ' => 403 )
138- );
139- }
140-
141135 if ( ! empty ( $ post_id ) && $ post && ! $ this ->check_read_post_permission ( $ post , $ request ) ) {
142136 return new WP_Error (
143137 'rest_cannot_read_post ' ,
@@ -151,6 +145,36 @@ public function get_items_permissions_check( $request ) {
151145 array ( 'status ' => rest_authorization_required_code () )
152146 );
153147 }
148+
149+ if ( $ post && $ is_note && ! $ this ->check_post_type_supports_notes ( $ post ->post_type ) ) {
150+ if ( current_user_can ( get_post_type_object ( $ post ->post_type )->cap ->edit_posts ) ) {
151+ return new WP_Error (
152+ 'rest_comment_not_supported_post_type ' ,
153+ __ ( 'Sorry, this post type does not support notes. ' ),
154+ array ( 'status ' => 403 )
155+ );
156+ }
157+
158+ foreach ( $ protected_params as $ param ) {
159+ if ( 'status ' === $ param ) {
160+ if ( 'approve ' !== $ request [ $ param ] ) {
161+ $ forbidden_params [] = $ param ;
162+ }
163+ } elseif ( 'type ' === $ param ) {
164+ if ( 'comment ' !== $ request [ $ param ] ) {
165+ $ forbidden_params [] = $ param ;
166+ }
167+ } elseif ( ! empty ( $ request [ $ param ] ) ) {
168+ $ forbidden_params [] = $ param ;
169+ }
170+ }
171+ return new WP_Error (
172+ 'rest_forbidden_param ' ,
173+ /* translators: %s: List of forbidden parameters. */
174+ sprintf ( __ ( 'Query parameter not permitted: %s ' ), implode ( ', ' , $ forbidden_params ) ),
175+ array ( 'status ' => rest_authorization_required_code () )
176+ );
177+ }
154178 }
155179 }
156180
@@ -174,23 +198,6 @@ public function get_items_permissions_check( $request ) {
174198 }
175199
176200 if ( ! current_user_can ( 'edit_posts ' ) ) {
177- $ protected_params = array ( 'author ' , 'author_exclude ' , 'author_email ' , 'type ' , 'status ' );
178- $ forbidden_params = array ();
179-
180- foreach ( $ protected_params as $ param ) {
181- if ( 'status ' === $ param ) {
182- if ( 'approve ' !== $ request [ $ param ] ) {
183- $ forbidden_params [] = $ param ;
184- }
185- } elseif ( 'type ' === $ param ) {
186- if ( 'comment ' !== $ request [ $ param ] ) {
187- $ forbidden_params [] = $ param ;
188- }
189- } elseif ( ! empty ( $ request [ $ param ] ) ) {
190- $ forbidden_params [] = $ param ;
191- }
192- }
193-
194201 if ( ! empty ( $ forbidden_params ) ) {
195202 return new WP_Error (
196203 'rest_forbidden_param ' ,
0 commit comments