Update saving of comment_type for product reviews to account for WP 5.5 default comment_type

This commit is contained in:
Jonathan Sadowski 2020-06-08 17:36:34 -05:00
parent 6564847802
commit f9731bb2ed
1 changed files with 16 additions and 2 deletions

View File

@ -146,7 +146,7 @@ class WC_Comments {
*/
public static function check_comment_rating( $comment_data ) {
// If posting a comment (not trackback etc) and not logged in.
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST['rating'], $comment_data['comment_type'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST['rating'] ) && '' === $comment_data['comment_type'] && wc_review_ratings_enabled() && wc_review_ratings_required() ) { // WPCS: input var ok, CSRF ok.
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST['rating'], $comment_data['comment_type'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST['rating'] ) && self::is_default_comment_type( $comment_data['comment_type'] ) && wc_review_ratings_enabled() && wc_review_ratings_required() ) { // WPCS: input var ok, CSRF ok.
wp_die( esc_html__( 'Please rate the product.', 'woocommerce' ) );
exit;
}
@ -406,12 +406,26 @@ class WC_Comments {
* @return array
*/
public static function update_comment_type( $comment_data ) {
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $comment_data['comment_type'] ) && '' === $comment_data['comment_type'] && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) ) { // WPCS: input var ok, CSRF ok.
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $comment_data['comment_type'] ) && self::is_default_comment_type( $comment_data['comment_type'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) ) { // WPCS: input var ok, CSRF ok.
$comment_data['comment_type'] = 'review';
}
return $comment_data;
}
/**
* Determines if a comment is of the default type.
*
* Prior to WordPress 5.5, '' was the default comment type.
* As of 5.5, the default type is 'comment'.
*
* @since 4.3.0
* @param string $comment_type Comment type.
* @return bool
*/
private static function is_default_comment_type( $comment_type ) {
return ( '' === $comment_type || 'comment' === $comment_type );
}
}
WC_Comments::init();