WP_REST_Comments_Controller::handle_status_param() WordPress Method

The WP_REST_Comments_Controller::handle_status_param() is a Wordpress method used to set the status of a comment. The method takes a comment ID and a new status, and then updates the comment accordingly.

WP_REST_Comments_Controller::handle_status_param( string|int $new_status, int $comment_id ) #

Sets the comment_status of a given comment object when creating or updating a comment.


Parameters

$new_status

(string|int)(Required)New comment status.

$comment_id

(int)(Required)Comment ID.


Top ↑

Return

(bool) Whether the status was changed.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

	protected function handle_status_param( $new_status, $comment_id ) {
		$old_status = wp_get_comment_status( $comment_id );

		if ( $new_status === $old_status ) {
			return false;
		}

		switch ( $new_status ) {
			case 'approved':
			case 'approve':
			case '1':
				$changed = wp_set_comment_status( $comment_id, 'approve' );
				break;
			case 'hold':
			case '0':
				$changed = wp_set_comment_status( $comment_id, 'hold' );
				break;
			case 'spam':
				$changed = wp_spam_comment( $comment_id );
				break;
			case 'unspam':
				$changed = wp_unspam_comment( $comment_id );
				break;
			case 'trash':
				$changed = wp_trash_comment( $comment_id );
				break;
			case 'untrash':
				$changed = wp_untrash_comment( $comment_id );
				break;
			default:
				$changed = false;
				break;
		}

		return $changed;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.