rest_allow_anonymous_comments filter-hookWP 4.7.0

Filters whether comments can be created via the REST API without authentication.

Enables creating comments for anonymous users.

Usage

add_filter( 'rest_allow_anonymous_comments', 'wp_kama_rest_allow_anonymous_comments_filter', 10, 2 );

/**
 * Function for `rest_allow_anonymous_comments` filter-hook.
 * 
 * @param bool            $allow_anonymous Whether to allow anonymous comments to be created.
 * @param WP_REST_Request $request         Request used to generate the response.
 *
 * @return bool
 */
function wp_kama_rest_allow_anonymous_comments_filter( $allow_anonymous, $request ){

	// filter...
	return $allow_anonymous;
}
$allow_anonymous(true|false)
Whether to allow anonymous comments to be created.
Default: false
$request(WP_REST_Request)
Request used to generate the response.

Changelog

Since 4.7.0 Introduced.

Where the hook is called

WP_REST_Comments_Controller::create_item_permissions_check()
rest_allow_anonymous_comments
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php 466
$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request );

Where the hook is used in WordPress

Usage not found.