REST API: Treat any falsy value as `false` in 'rest_allow_anonymous_comments'.

Extend the check in 'rest_allow_anonymous_comments' to accept any falsy value (previously this was an explicit check for `false`).

One possible failure case is that a plugin developer forgets to include a return value for some code path in their callback for this filter, leading to a value of null which is currently treated like `true`.

Props joehoyle, jnylen0.
Merges [39487] to the 4.7 branch.
Fixes #39010.

Built from https://develop.svn.wordpress.org/branches/4.7@39566


git-svn-id: http://core.svn.wordpress.org/branches/4.7@39506 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2016-12-12 01:40:32 +00:00
parent 16cabf6b50
commit 6738759b0c
1 changed files with 1 additions and 1 deletions

View File

@ -392,7 +392,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
* response.
*/
$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request );
if ( false === $allow_anonymous ) {
if ( ! $allow_anonymous ) {
return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
}
}