rest_pre_insert_product_review

Filter a product review (comment) before it is inserted via the REST API.

Description

apply_filters( 'rest_pre_insert_product_review', (array) $prepared_review, (WP_REST_Request) $request ); 

Allows modification of the comment right before it is inserted via wp_insert_comment..

Parameters (2)

0. $prepared_review (array)
The prepared comment data for wp_insert_comment..
1. $request (WP_REST_Request)
Request used to insert the comment.

Usage

To run the hook, copy the example below.
  1. $prepared_review = apply_filters( 'rest_pre_insert_product_review', $prepared_review, $request ); 
  2.  
  3. if ( !empty( $prepared_review ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the rest_pre_insert_product_review callback 
  2. function filter_rest_pre_insert_product_review( $prepared_review, $request ) { 
  3. // make filter magic happen here... 
  4. return $prepared_review
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'rest_pre_insert_product_review', 'filter_rest_pre_insert_product_review', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'rest_pre_insert_product_review', 'filter_rest_pre_insert_product_review', 10, 2 ); 

Defined (1)

The filter is defined in the following location(s).

/includes/api/v1/class-wc-rest-product-reviews-controller.php  
  1. $prepared_review = apply_filters( 'rest_pre_insert_product_review', $prepared_review, $request );