Filter hook 'comment_text'

in WP Core File wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php at line 1110

View Source

comment_text

Filter Hook
Description
Prepares a single comment output for response.

Hook Information

File Location wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php View on GitHub
Hook Type Filter
Line Number 1110

Hook Parameters

Type Name Description
WP_Comment $item Comment object.
WP_REST_Request $request Request object.

Usage Examples

Basic Usage
<?php
// Hook into comment_text
add_filter('comment_text', 'my_custom_filter', 10, 2);

function my_custom_filter($item, $request) {
    // Your custom filtering logic here
    return $item;
}

Source Code Context

wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:1110 - How this hook is used in WordPress core
<?php
1105  		}
1106  
1107  		if ( in_array( 'content', $fields, true ) ) {
1108  			$data['content'] = array(
1109  				/** This filter is documented in wp-includes/comment-template.php */
1110  				'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment, array() ),
1111  				'raw'      => $comment->comment_content,
1112  			);
1113  		}
1114  
1115  		if ( in_array( 'link', $fields, true ) ) {

PHP Documentation

<?php
/**
	 * Prepares a single comment output for response.
	 *
	 * @since 4.7.0
	 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support.
	 *
	 * @param WP_Comment      $item    Comment object.
	 * @param WP_REST_Request $request Request object.
	 * @return WP_REST_Response Response object.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
Related Hooks

Related hooks will be displayed here in future updates.