: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$reviews[ $key ]['total'] += $value;
$reviews[ $key ]['positive']++;
$reviews[ $key ]['negative']++;
$reviews[ $key ]['count']++;
update_post_meta( $post_id, $post_meta_key, $reviews );
* Clears cached when modify comment.
* @param WP_Comment $comment Comment object.
function wp_review_clear_cached_reviews( $comment ) {
delete_post_meta( $comment->comment_post_ID, 'wp_review_comment_feature_reviews' );
delete_post_meta( $comment->comment_post_ID, 'wp_review_comments_rating_value' );
delete_post_meta( $comment->comment_post_ID, 'wp_review_comments_rating_count' );
delete_post_meta( $comment->comment_post_ID, 'wp_review_user_feature_reviews' );
delete_post_meta( $comment->comment_post_ID, 'wp_review_user_reviews' );
delete_post_meta( $comment->comment_post_ID, 'wp_review_review_count' );
* Runs something when change comment status.
* @param string $new_status New status.
* @param string $old_status Old status.
* @param WP_Comment $comment Comment object.
function wp_review_on_change_comment_status( $new_status, $old_status, $comment ) {
wp_review_clear_cached_reviews( $comment );
add_action( 'transition_comment_status', 'wp_review_on_change_comment_status', 10, 3 );
* Comments rating callback for array_reduce().
* @param float $carry Rating.
* @param object $comment Comment object.
function wpreview_comment_ratings_callback( $carry, $comment ) {
$rating = get_comment_meta( $comment->comment_ID, WP_REVIEW_COMMENT_RATING_METAKEY, true );
$carry += floatval( $rating );
* Visitors rating callback for array_reduce().
* @param float $carry Rating.
* @param object $comment Comment object.
function wpreview_visitor_ratings_callback( $carry, $comment ) {
$rating = get_comment_meta( $comment->comment_ID, WP_REVIEW_VISITOR_RATING_METAKEY, true );
$carry += floatval( $rating );
* Check if user has reviewed this post previously.
* @param int $post_id Post ID.
* @param int $user_id User ID.
* @param string $ip User IP.
* @param string $type Rating type.
function hasPreviousReview( $post_id, $user_id, $ip, $type = 'any' ) { // phpcs:ignore
_deprecated_function( __FUNCTION__, '3.0.0', 'wp_review_has_reviewed' );
return wp_review_has_reviewed( $post_id, $user_id, $ip, $type );
* Check if user has reviewed this post previously.
* @param int $post_id Post ID.
* @param int $user_id User ID.
* @param string $ip User IP.
* @param string $type Rating type.
function wp_review_has_reviewed( $post_id, $user_id, $ip = null, $type = 'any' ) {
$ip = wp_review_get_user_ip();
if ( is_user_logged_in() && wp_review_option( 'multi_reviews_per_account' ) ) {
return false; // Allow multiple reviews per account.
if ( is_user_logged_in() ) {
return wp_review_has_reviewed_by_user_id( $post_id, $user_id, $ip, $type );
return wp_review_has_reviewed_by_ip( $post_id, $user_id, $ip, $type );
* Check if user has reviewed this post previously by user id.
* @param int $post_id Post ID.
* @param int $user_id User ID.
* @param string $ip User IP.
* @param string $type Rating type.
function wp_review_has_reviewed_by_user_id( $post_id, $user_id, $ip, $type = 'any' ) {
$args['type_in'] = array( WP_REVIEW_COMMENT_TYPE_COMMENT, WP_REVIEW_COMMENT_TYPE_VISITOR );
$count = intval( get_comments( $args ) );
* Check if user has reviewed this post previously by ip address.
* @param int $post_id Post ID.
* @param int $user_id User ID.
* @param string $ip User IP.
* @param string $type Rating type.
function wp_review_has_reviewed_by_ip( $post_id, $user_id, $ip, $type = 'any' ) {
$args['type_in'] = array( WP_REVIEW_COMMENT_TYPE_COMMENT, WP_REVIEW_COMMENT_TYPE_VISITOR );
set_query_var( 'wp_review_ip', $ip );
add_filter( 'comments_clauses', 'wp_review_filter_comment_by_ip' );
$count = intval( get_comments( $args ) );
remove_filter( 'comments_clauses', 'wp_review_filter_comment_by_ip' );
* Gets previous review comment.
* @param WP_Comment $comment Comment object.
* @return WP_Comment|false
function wp_review_get_previous_review_comment( $comment ) {
$post_id = $comment->comment_post_ID;
'type_in' => array( WP_REVIEW_COMMENT_TYPE_COMMENT ),
'meta_key' => WP_REVIEW_COMMENT_RATING_METAKEY,
if ( intval( $comment->user_id ) ) {
$query_args['user_id'] = $comment->user_id;
set_query_var( 'wp_review_ip', $comment->comment_author_IP );
add_filter( 'comments_clauses', 'wp_review_filter_comment_by_ip' );
$comments = get_comments( $query_args );
remove_filter( 'comments_clauses', 'wp_review_filter_comment_by_ip' );
* Add the comment type to comment query.
* @param WP_Comment_Query $query Comment query.
* @return WP_Comment_Query
function wp_review_add_comment_type_to_query( WP_Comment_Query $query ) {
$commenttype = get_query_var( 'wp_review_commenttype' );
if ( 'any' === $commenttype ) {
$query->query_vars['type__in'] = array( WP_REVIEW_COMMENT_TYPE_COMMENT, WP_REVIEW_COMMENT_TYPE_VISITOR );
$query->query_vars['type'] = $commenttype;
* Add a conditional to filter the comment query by IP.
* @param array $clauses Where clauses.
function wp_review_filter_comment_by_ip( array $clauses ) {
$clauses['where'] .= $wpdb->prepare( ' AND comment_author_IP = %s', get_query_var( 'wp_review_ip' ) );
* @param int $post_id Post ID.
* @param int $user_id User ID.
* @param string $ip IP Address.
* @param string $type Review type.
function getPreviousReview( $post_id, $user_id, $ip, $type = 'any' ) { // phpcs:ignore
if ( is_numeric( $post_id ) && $post_id > 0 ) {
set_query_var( 'wp_review_commenttype', $type );
add_filter( 'pre_get_comments', 'wp_review_add_comment_type_to_query' );
$args['user_id'] = array( $user_id );
set_query_var( 'wp_review_ip', $ip );
add_filter( 'comments_clauses', 'wp_review_filter_comment_by_ip' );
$comment = get_comments( $args );
remove_filter( 'pre_get_comments', 'wp_review_add_comment_type_to_query' );
remove_filter( 'comments_clauses', 'wp_review_filter_comment_by_ip' );
if ( ! empty( $comment ) ) {
return get_comment_meta( $comment[0]->comment_ID, WP_REVIEW_COMMENT_RATING_METAKEY, true );
* @param array $new_options New options.
* @param bool $force_change Force changes.
function wp_review_theme_defaults( $new_options, $force_change = false ) {
$opt_name = 'wp_review_options_' . wp_get_theme();
$options = get_option( 'wp_review_options' );
if ( empty( $options ) ) {
$options_updated = get_option( $opt_name );
// If the theme was just activated OR options weren't updated yet.
if ( empty( $options_updated ) || $options_updated != $new_options || $force_change || ( isset( $_GET['activated'] ) && 'themes.php' == $pagenow ) ) {
update_option( 'wp_review_options', array_merge( $options, $new_options ) );
update_option( $opt_name, $new_options );
function wp_review_get_all_image_sizes() {
global $_wp_additional_image_sizes;
$default_image_sizes = array( 'thumbnail', 'medium', 'large' );
foreach ( $default_image_sizes as $size ) {
$image_sizes[ $size ]['width'] = intval( get_option( "{$size}_size_w" ) );
$image_sizes[ $size ]['height'] = intval( get_option( "{$size}_size_h" ) );
$image_sizes[ $size ]['crop'] = get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false;
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) {
$image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes );
* Exclude review-type comments from being included in the comment query.
* @param WP_Comment_Query $query Comment query.
function wp_review_exclude_review_comments( WP_Comment_Query $query ) {
if ( ! is_admin() && ( WP_REVIEW_COMMENT_TYPE_VISITOR !== $query->query_vars['type'] && ! in_array( WP_REVIEW_COMMENT_TYPE_VISITOR, (array) $query->query_vars['type__in'] ) ) ) {
$query->query_vars['type__not_in'] = array_merge(
is_array( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array(),
array( WP_REVIEW_COMMENT_TYPE_VISITOR )
add_action( 'pre_get_comments', 'wp_review_exclude_review_comments', 15 );
* Add "Reviews" to comments table view.
* @param array $comment_types Comment types.
function wp_review_add_to_comment_table_dropdown( $comment_types ) {
$comment_types[ WP_REVIEW_COMMENT_TYPE_COMMENT ] = __( 'Comment Reviews', 'wp-review' );
$comment_types[ WP_REVIEW_COMMENT_TYPE_VISITOR ] = __( 'Visitor Reviews', 'wp-review' );
add_filter( 'admin_comment_types_dropdown', 'wp_review_add_to_comment_table_dropdown' );
* @since 3.0.0 Combine with global option.
* @param int $post_id Post ID.
* 1 - Visitor Rating Only
* 2 - Comment Rating Only
function wp_review_get_user_rating_setup( $post_id ) {
$default = wp_review_option( 'default_user_review_type', WP_REVIEW_REVIEW_DISABLED );
$user_reviews = get_post_meta( $post_id, 'wp_review_userReview', true );
$enabled = '' === $user_reviews ? $default : (int) $user_reviews;
if ( is_array( $user_reviews ) ) {
$enabled = (int) $user_reviews[0];
// Reviews through comments: enabled by default.
$review_through_comment = get_post_meta( $post_id, 'wp_review_through_comment', true );
$custom_fields = get_post_custom();
if ( ! isset( $custom_fields['wp_review_through_comment'] ) ) {
$review_through_comment = 0;
// Compatibility with the old option.
if ( $review_through_comment ) {
$enabled = WP_REVIEW_REVIEW_ALLOW_BOTH;
$enabled = WP_REVIEW_REVIEW_VISITOR_ONLY;
* Exclude visitor ratings when updating a post's comment count.
* @param int $post_id Post ID.
* @param object $new New comment.
* @param object $old Old comment.
* @internal param $comment_id
* @internal param $comment
function wp_review_exclude_visitor_review_count( $post_id, $new, $old ) {
'type__not_in' => array( WP_REVIEW_COMMENT_TYPE_VISITOR ),
$wpdb->update( $wpdb->posts, array( 'comment_count' => $count ), array( 'ID' => $post_id ) );
// Update user review count.
mts_get_post_reviews( $post_id, true );
clean_post_cache( $post_id );
add_action( 'wp_update_comment_count', 'wp_review_exclude_visitor_review_count', 10, 3 );
* Get the schema type of a review.
* @param int $post_id Post ID.
function wp_review_get_review_schema( $post_id ) {
$schema = get_post_meta( $post_id, 'wp_review_schema', true );
$schemas = wp_review_schema_types();
if ( empty( $schema ) || ! isset( $schemas[ $schema ] ) ) {
$schema = wp_review_option( 'default_schema_type', 'none' );
if ( in_array( $schema, array_keys( wp_review_get_deprecated_schema_types() ) ) ) {
* Get the IP of the current user.
function wp_review_get_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip = $_SERVER['REMOTE_ADDR'];
* Get the HTML for user reviews in review box.
* @param int $post_id Post ID.
* @param bool $votable Voteable or not.
* @param bool $force_display Force display or not.
function wp_review_user_review( $post_id, $votable = true, $force_display = false ) {
if ( ! $force_display && ! in_array( wp_review_get_user_rating_setup( $post_id ), array( WP_REVIEW_REVIEW_VISITOR_ONLY, WP_REVIEW_REVIEW_ALLOW_BOTH ) ) ) {
$allowed_class = 'allowed-to-rate';
$has_not_rated_class = ' has-not-rated-yet';
$post_reviews = mts_get_post_reviews( $post_id );
$user_total = $post_reviews['rating'];
$users_reviews_count = $post_reviews['count'];
$positive_rating = $post_reviews['positive_count'];
$negative_rating = $post_reviews['negative_count'];
$total = get_post_meta( $post_id, 'wp_review_total', true );
$type = get_post_meta( $post_id, 'wp_review_user_review_type', true );
$options = get_option( 'wp_review_options' );
$colors = wp_review_get_colors( $post_id );
$color = $colors['color'];
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
if ( '' == $user_total ) {
if ( ! $votable || wp_review_has_reviewed( $post_id, $user_id, wp_review_get_user_ip(), WP_REVIEW_COMMENT_TYPE_VISITOR ) || ( ! is_user_logged_in() && ! empty( $options['registered_only'] ) ) ) {
$has_not_rated_class = '';
$class = $allowed_class . $has_not_rated_class;
$template = mts_get_template_path( $type, 'star-output' );
set_query_var( 'rating', compact( 'value', 'users_reviews_count', 'user_id', 'class', 'post_id', 'color', 'colors', 'positive_rating', 'negative_rating' ) );