wp/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
  1026 
  1026 
  1027 	/**
  1027 	/**
  1028 	 * Prepares a single comment output for response.
  1028 	 * Prepares a single comment output for response.
  1029 	 *
  1029 	 *
  1030 	 * @since 4.7.0
  1030 	 * @since 4.7.0
  1031 	 *
  1031 	 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support.
  1032 	 * @param WP_Comment      $comment Comment object.
  1032 	 *
       
  1033 	 * @param WP_Comment      $item    Comment object.
  1033 	 * @param WP_REST_Request $request Request object.
  1034 	 * @param WP_REST_Request $request Request object.
  1034 	 * @return WP_REST_Response Response object.
  1035 	 * @return WP_REST_Response Response object.
  1035 	 */
  1036 	 */
  1036 	public function prepare_item_for_response( $comment, $request ) {
  1037 	public function prepare_item_for_response( $item, $request ) {
  1037 
  1038 		// Restores the more descriptive, specific name for use within this method.
  1038 		$fields = $this->get_fields_for_response( $request );
  1039 		$comment = $item;
  1039 		$data   = array();
  1040 		$fields  = $this->get_fields_for_response( $request );
       
  1041 		$data    = array();
  1040 
  1042 
  1041 		if ( in_array( 'id', $fields, true ) ) {
  1043 		if ( in_array( 'id', $fields, true ) ) {
  1042 			$data['id'] = (int) $comment->comment_ID;
  1044 			$data['id'] = (int) $comment->comment_ID;
  1043 		}
  1045 		}
  1044 
  1046 
  1192 			);
  1194 			);
  1193 
  1195 
  1194 			$rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) );
  1196 			$rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) );
  1195 
  1197 
  1196 			$links['children'] = array(
  1198 			$links['children'] = array(
  1197 				'href' => $rest_url,
  1199 				'href'       => $rest_url,
       
  1200 				'embeddable' => true,
  1198 			);
  1201 			);
  1199 		}
  1202 		}
  1200 
  1203 
  1201 		return $links;
  1204 		return $links;
  1202 	}
  1205 	}