: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2013, MyThemesShop
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @param string $name Option name.
* @param mixed $default Default value.
function wp_review_option( $name, $default = null ) {
if ( ! is_array( $options ) ) {
$options = get_option( 'wp_review_options', array() );
$value = isset( $options[ $name ] ) ? $options[ $name ] : $default;
$value = apply_filters( 'wp_review_option_' . $name, $value );
$value = apply_filters( 'wp_review_option', $value, $name );
function wp_review_get_default_colors() {
'inactive_color' => '#95bae0',
'fontcolor' => '#555555',
'bordercolor' => '#e7e7e7',
$custom_default_colors = apply_filters( 'wp_review_default_colors', $default_colors );
return array_merge( $default_colors, $custom_default_colors );
* Gets global colors setting.
function wp_review_get_global_colors() {
$colors = wp_review_option( 'colors' );
$default_colors = wp_review_get_default_colors();
$fields = array( 'color', 'inactive_color', 'fontcolor', 'bgcolor1', 'bgcolor2', 'bordercolor' );
foreach ( $fields as $key ) {
if ( empty( $colors[ $key ] ) ) {
$colors[ $key ] = isset( $default_colors[ $key ] ) ? $default_colors[ $key ] : '';
function wp_review_get_default_location() {
return apply_filters( 'wp_review_default_location', 'bottom' );
function wp_review_get_default_criteria() {
$default_criteria = apply_filters( 'wp_review_default_criteria', array() );
if ( ! $default_criteria && wp_review_option( 'default_features', array() ) ) {
$default_criteria = wp_review_option( 'default_features', array() );
return $default_criteria;
* Gets post custom layout data.
* @param int $post_id Post ID.
function wp_review_get_custom_layout_data( $post_id ) {
'enable' => get_post_meta( $post_id, 'wp_review_custom_colors', true ),
'box_template' => get_post_meta( $post_id, 'wp_review_box_template', true ),
'color' => get_post_meta( $post_id, 'wp_review_color', true ),
'inactive_color' => get_post_meta( $post_id, 'wp_review_inactive_color', true ),
'fontcolor' => get_post_meta( $post_id, 'wp_review_fontcolor', true ),
'bgcolor1' => get_post_meta( $post_id, 'wp_review_bgcolor1', true ),
'bgcolor2' => get_post_meta( $post_id, 'wp_review_bgcolor2', true ),
'bordercolor' => get_post_meta( $post_id, 'wp_review_bordercolor', true ),
// Image sizes for the widgets.
add_image_size( 'wp_review_large', 320, 200, true );
add_image_size( 'wp_review_small', 65, 65, true );
// Filter to add custom images sizes in Thumbnail selection box.
'image_size_names_choose',
'wp_review_custom_image_sizes',
'wp_review_small' => __( 'WP Review Small', 'wp-review' ),
'wp_review_large' => __( 'WP Review Large', 'wp-review' ),
* Replaced by wp_review_get_review_box() in v2.0
* @param int $post_id Post ID.
function wp_review_get_data( $post_id = null ) {
return wp_review_get_review_box( $post_id );
* Injects reviews to content.
* @param string $content Post content.
function wp_review_inject_data( $content ) {
$options = get_option( 'wp_review_options' );
$custom_location = get_post_meta( $post_id, 'wp_review_custom_location', true );
$location = get_post_meta( $post_id, 'wp_review_location', true );
if ( ! $custom_location && ! empty( $options['review_location'] ) ) {
$location = $options['review_location'];
$location = apply_filters( 'wp_review_location', $location, $post_id );
if ( ! $location || 'custom' === $location ) {
if ( ! is_singular() || ! is_main_query() ) {
if ( ! wp_review_is_amp_page() && ! in_the_loop() ) {
$review = wp_review_get_review_box();
if ( 'bottom' == $location ) {
global $multipage, $numpages, $page;
if ( $page == $numpages ) {
return $content . $review;
return $content . $review;
} elseif ( 'top' == $location ) {
return $review . $content;
/* Display the meta box data below 'the_content' hook. */
add_filter( 'the_content', 'wp_review_inject_data' );
* Retrieve only total rating.
* To be used on archive pages, etc.
* @param bool $echo Echo or not.
* @param string $class CSS class.
* @param int $post_id Post ID. Use current post ID if empty.
* @param array $args Custom arguments. Use for filter.
function wp_review_show_total( $echo = true, $class = 'review-total-only', $post_id = null, $args = array() ) {
if ( empty( $post_id ) ) {
$rating_types = wp_review_get_rating_types();
$type = wp_review_get_post_review_type( $post_id );
$user_type = wp_review_get_post_user_review_type( $post_id );
if ( ! $type && ! $user_type ) {
wp_enqueue_style( 'wp_review-style' );
if ( false !== strpos( $class, 'latestPost-review-wrapper' ) ) {
$args['inactive_color'] = '#dedcdc';
if ( false !== strpos( $class, 'rank-math-snippet' ) ) {
$args['inactive_color'] = '#dedcdc';
$show_on_thumbnails_type = 'author';
$show_on_thumbnails_type = apply_filters( 'wp_review_thumbnails_total', $show_on_thumbnails_type, $post_id, $args ); // Will override option.
switch ( $show_on_thumbnails_type ) {
$total = get_post_meta( $post_id, 'wp_review_total', true );
if ( in_array( $type, array( 'point', 'percentage' ) ) ) {
$rating = sprintf( $rating_types[ $type ]['value_text'], $total );
$rating = wp_review_rating( $total, $post_id, $args );
$total = get_post_meta( $post_id, 'wp_review_user_reviews', true );
if ( 'point' == $user_type || 'percentage' == $user_type ) {
$rating = sprintf( $rating_types[ $user_type ]['value_text'], $total );
$rating = wp_review_rating( $total, $post_id, array( 'user_rating' => true ) ); // Return just output template.
if ( ! empty( $rating ) && ! empty( $total ) ) {
if ( ! empty( $args['context'] ) && 'product-rating' === $args['context'] ) {
$colors = wp_review_get_colors( $post_id );
$style .= sprintf( ' background-color: %s;', esc_attr( $colors['color'] ) );
$style = 'style="' . esc_attr( $style ) . '"';
$review .= '<div class="review-type-' . $type . ' ' . esc_attr( $class ) . ' wp-review-show-total wp-review-total-' . $post_id . ' wp-review-total-' . $type . '" ' . $style . '> ';
$review = apply_filters( 'wp_review_show_total', $review, $post_id, $type, $total );
$review = apply_filters( 'wp_review_total_output', $review, $post_id, $type, $total, $class, $args );
echo $review; // WPCS: xss ok.
* Gets post visitor reviews data.
* @param int $post_id Post ID.
* @param bool $force Force fetching from comments instead of post meta.
function mts_get_post_reviews( $post_id, $force = false ) {
$post_reviews = get_post_meta( $post_id, 'wp_review_user_reviews', true );
$review_count = (int) get_post_meta( $post_id, 'wp_review_review_count', true );
$positive_count = (int) get_post_meta( $post_id, 'wp_review_positive_count', true );
$negative_count = (int) get_post_meta( $post_id, 'wp_review_negative_count', true );
if ( ! $force && $post_reviews && $review_count ) {
'rating' => $post_reviews,
'count' => $review_count,
'positive_count' => $positive_count,
'negative_count' => $negative_count,
if ( is_numeric( $post_id ) && $post_id > 0 ) {
$comments = get_comments(
'type' => WP_REVIEW_COMMENT_TYPE_VISITOR,
$rating = array_reduce( $comments, 'wpreview_visitor_ratings_callback', 0 );
$count = count( $comments );
'rating' => $count > 0 ? round( $rating / $count, 2 ) : 0,
$positive_comments = get_comments(
'type' => WP_REVIEW_COMMENT_TYPE_VISITOR,
'meta_key' => WP_REVIEW_VISITOR_RATING_METAKEY,
$post_reviews['positive_count'] = count( $positive_comments );
$negative_comments = get_comments(
'type' => WP_REVIEW_COMMENT_TYPE_VISITOR,
'meta_key' => WP_REVIEW_VISITOR_RATING_METAKEY,
$post_reviews['negative_count'] = count( $negative_comments );
update_post_meta( $post_id, 'wp_review_user_reviews', $post_reviews['rating'] );
update_post_meta( $post_id, 'wp_review_review_count', $post_reviews['count'] );
update_post_meta( $post_id, 'wp_review_positive_count', $post_reviews['positive_count'] );
update_post_meta( $post_id, 'wp_review_negative_count', $post_reviews['negative_count'] );
* Gets post comment reviews data.
* @param int $post_id Post ID.
* @param bool $force Force fetching from comments instead of post meta.
function mts_get_post_comments_reviews( $post_id, $force = false ) {
$post_reviews = get_post_meta( $post_id, 'wp_review_comments_rating_value', true );
$review_count = (int) get_post_meta( $post_id, 'wp_review_comments_rating_count', true );
$positive_count = (int) get_post_meta( $post_id, 'wp_review_comments_positive_count', true );
$negative_count = (int) get_post_meta( $post_id, 'wp_review_comments_negative_count', true );
if ( ! $force && $post_reviews && $review_count ) {
'rating' => $post_reviews,
'count' => $review_count,
'positive_count' => $positive_count,
'negative_count' => $negative_count,
if ( is_numeric( $post_id ) && $post_id > 0 ) {
$comments = get_comments(
'type' => WP_REVIEW_COMMENT_TYPE_COMMENT,
$rating = array_reduce( $comments, 'wpreview_comment_ratings_callback', 0 );
$count = count( $comments );
'rating' => $count > 0 ? round( $rating / $count, 2 ) : 0,
$positive_comments = get_comments(
'type' => WP_REVIEW_COMMENT_TYPE_COMMENT,
'meta_key' => WP_REVIEW_COMMENT_RATING_METAKEY,
$post_reviews['positive_count'] = count( $positive_comments );
$negative_comments = get_comments(
'type' => WP_REVIEW_COMMENT_TYPE_COMMENT,
'meta_key' => WP_REVIEW_COMMENT_RATING_METAKEY,
$post_reviews['negative_count'] = count( $negative_comments );
update_post_meta( $post_id, 'wp_review_comments_rating_value', $post_reviews['rating'] );
update_post_meta( $post_id, 'wp_review_comments_rating_count', $post_reviews['count'] );
update_post_meta( $post_id, 'wp_review_comments_positive_count', $post_reviews['positive_count'] );
update_post_meta( $post_id, 'wp_review_comments_negative_count', $post_reviews['negative_count'] );
* Gets post visitor feature reviews data.
* @param int $post_id Post ID.
* @param bool $force Force fetching from comments instead of post meta.
* @param string $type Accepts `user` or `comment`.
function wp_review_get_post_feature_reviews( $post_id = null, $force = false, $type = 'user' ) {
$post_meta_key = "wp_review_{$type}_feature_reviews";
$reviews = get_post_meta( $post_id, $post_meta_key, true );
if ( ! $force && $reviews ) {
$features = wp_review_get_review_items( $post_id );
$comments = get_comments(
'type' => 'comment' === $type ? WP_REVIEW_COMMENT_TYPE_COMMENT : WP_REVIEW_COMMENT_TYPE_VISITOR,
foreach ( $features as $value ) {
$reviews[ $value['id'] ] = array(
foreach ( $comments as $comment ) {
$data = get_comment_meta( $comment->comment_ID, WP_REVIEW_COMMENT_FEATURES_RATING_METAKEY, true );
foreach ( $data as $key => $value ) {
if ( empty( $reviews[ $key ] ) ) {