XML-RPC: Improve error messages for unprivileged users.

Add specific permission checks to avoid ambiguous failure messages.

This brings the changes in [49380] to the 5.5 branch.

Props zieladam, peterwilsoncc, xknown, whyisjake.


git-svn-id: https://develop.svn.wordpress.org/branches/5.5@49389 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jake Spurlock 2020-10-29 18:26:20 +00:00
parent 7d5bf1c3f8
commit 0b0669ade2

View File

@ -3875,6 +3875,21 @@ class wp_xmlrpc_server extends IXR_Server {
return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) );
}
if (
'publish' === get_post_status( $post_id ) &&
! current_user_can( 'edit_post', $post_id ) &&
post_password_required( $post_id )
) {
return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
}
if (
'private' === get_post_status( $post_id ) &&
! current_user_can( 'read_post', $post_id )
) {
return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
}
if ( empty( $content_struct['content'] ) ) {
return new IXR_Error( 403, __( 'Comment is required.' ) );
}