WC_REST_Product_Reviews_Controller::prepare_item_for_database() protected WC 1.0
Prepare a single product review to be inserted into the database.
{} It's a method of the class: WC_REST_Product_Reviews_Controller{}
Hooks from the method
Return
Array|WP_Error. $prepared_review
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_item_for_database( $request );
- $request(WP_REST_Request) (required)
- Request object.
Code of WC_REST_Product_Reviews_Controller::prepare_item_for_database() WC REST Product Reviews Controller::prepare item for database WC 5.0.0
protected function prepare_item_for_database( $request ) {
if ( isset( $request['id'] ) ) {
$prepared_review['comment_ID'] = (int) $request['id'];
}
if ( isset( $request['review'] ) ) {
$prepared_review['comment_content'] = $request['review'];
}
if ( isset( $request['product_id'] ) ) {
$prepared_review['comment_post_ID'] = (int) $request['product_id'];
}
if ( isset( $request['reviewer'] ) ) {
$prepared_review['comment_author'] = $request['reviewer'];
}
if ( isset( $request['reviewer_email'] ) ) {
$prepared_review['comment_author_email'] = $request['reviewer_email'];
}
if ( ! empty( $request['date_created'] ) ) {
$date_data = rest_get_date_with_gmt( $request['date_created'] );
if ( ! empty( $date_data ) ) {
list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data;
}
} elseif ( ! empty( $request['date_created_gmt'] ) ) {
$date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true );
if ( ! empty( $date_data ) ) {
list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data;
}
}
/**
* Filters a review after it is prepared for the database.
*
* Allows modification of the review right after it is prepared for the database.
*
* @since 3.5.0
* @param array $prepared_review The prepared review data for `wp_insert_comment`.
* @param WP_REST_Request $request The current request.
*/
return apply_filters( 'woocommerce_rest_preprocess_product_review', $prepared_review, $request );
}