Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_allow_anonymous_comments

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

Line Code
385                 * Enables creating comments for anonymous users.
386                 *
387                 * @since 4.7.0
388                 *
389                 * @param bool $allow_anonymous Whether to allow anonymous comments to
390                 *                              be created. Default `false`.
391                 * @param WP_REST_Request $request Request used to generate the
392                 *                                 response.
393                 */
394                $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request );
395                if ( false === $allow_anonymous ) {
396                     return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
397                }
398           }
399
400           // Limit who can set comment `author`, `author_ip` or `status` to anything other than the default.
401           if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) {
402                return new WP_Error( 'rest_comment_invalid_author',
403                     /* translators: %s: request parameter */