: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
load_template( $template, false );
$review = ob_get_contents();
if ( '0.0' !== $user_total && '' === $total ) { // Dont'show if no user ratings and there is review.
$review .= '<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
<meta itemprop="ratingValue" content="' . $user_total . '" />
<meta itemprop="reviewCount" content="' . $users_reviews_count . '" />
* Get the path to a rating template prioritizing theme directory first.
* @param string $type Rating type.
* @param string $default Default rating type.
function mts_get_template_path( $type, $default = 'star' ) {
$template = get_stylesheet_directory() . '/wp-review/' . $type . '.php';
// Template does not exist on theme dir, use plugin dir.
if ( ! file_exists( $template ) ) {
$template = WP_REVIEW_DIR . 'rating-types/' . $type . '.php';
// Template does not exist, fallback to star.
if ( ! file_exists( $template ) ) {
$template = WP_REVIEW_DIR . 'rating-types/' . $default . '.php';
$wp_review_rating_types = array();
* @param string $rating_type Rating type name.
* @param array $args Rating type args.
function wp_review_register_rating_type( $rating_type, $args ) {
global $wp_review_rating_types;
if ( empty( $args['output_template'] ) && empty( $args['template'] ) ) {
* If it has combined 'template'
* or 'input_template' (for user rating).
$args['user_rating'] = ! empty( $args['template'] ) || ! empty( $args['input_template'] );
$wp_review_rating_types[ $rating_type ] = $args;
* Registers default rating types.
function wp_review_register_default_rating_types() {
wp_review_register_rating_type(
'label' => __( 'Star', 'wp-review' ),
// translators: rating value text.
'value_text' => _x( '%s Stars', 'star rating value text', 'wp-review' ),
// translators: rating value singular text.
'value_text_singular' => _x( '%s Star', 'star rating value text singular', 'wp-review' ),
'input_template' => WP_REVIEW_DIR . 'rating-types/star-input.php',
'output_template' => WP_REVIEW_DIR . 'rating-types/star-output.php',
wp_review_register_rating_type(
'label' => __( 'Point', 'wp-review' ),
// translators: rating value text.
'value_text' => _x( '%s/10', 'point rating value text', 'wp-review' ),
// translators: rating value singular text.
'value_text_singular' => _x( '%s/10', 'point rating value text singular', 'wp-review' ),
'input_template' => WP_REVIEW_DIR . 'rating-types/point-input.php',
'output_template' => WP_REVIEW_DIR . 'rating-types/point-output.php',
wp_review_register_rating_type(
'label' => __( 'Percentage', 'wp-review' ),
// translators: rating value text.
'value_text' => _x( '%s%%', 'percentage rating value text', 'wp-review' ),
// translators: rating value singular text.
'value_text_singular' => _x( '%s%%', 'percentage rating value text singular', 'wp-review' ),
'input_template' => WP_REVIEW_DIR . 'rating-types/percentage-input.php',
'output_template' => WP_REVIEW_DIR . 'rating-types/percentage-output.php',
wp_review_register_rating_type(
'label' => __( 'Circle', 'wp-review' ),
// translators: rating value text.
'value_text' => _x( '%s', 'circle rating value text', 'wp-review' ), // phpcs:ignore
// translators: rating value singular text.
'value_text_singular' => _x( '%s', 'circle rating value text singular', 'wp-review' ), // phpcs:ignore
'input_template' => WP_REVIEW_DIR . 'rating-types/circle-input.php',
'output_template' => WP_REVIEW_DIR . 'rating-types/circle-output.php',
wp_review_register_rating_type(
'label' => __( 'Thumbs', 'wp-review' ),
// translators: rating value text.
'value_text' => _x( '%s/100', 'thumbs rating value text', 'wp-review' ),
// translators: rating value singular text.
'value_text_singular' => _x( '%s/100', 'thumbs rating value text singular', 'wp-review' ),
'input_template' => WP_REVIEW_DIR . 'rating-types/thumbs-input.php',
'output_template' => WP_REVIEW_DIR . 'rating-types/thumbs-output.php',
add_action( 'init', 'wp_review_register_default_rating_types' );
function wp_review_get_rating_types() {
global $wp_review_rating_types;
return apply_filters( 'wp_review_rating_types', $wp_review_rating_types );
* @param string $type Rating type name.
function wp_review_get_rating_type_data( $type ) {
$rating_types = wp_review_get_rating_types();
if ( ! isset( $rating_types[ $type ] ) ) {
'value_text_singular' => '',
* @param int $post_id Post ID.
* @return string Empty string if no review.
function wp_review_get_post_review_type( $post_id = null ) {
$type = get_post_meta( $post_id, 'wp_review_type', true );
$type = wp_review_option( 'review_type', 'none' );
$rating_types = wp_review_get_rating_types();
if ( 'none' === $type ) {
if ( $type && ! isset( $rating_types[ $type ] ) ) {
return apply_filters( 'wp_review_get_review_type', $type, $post_id );
* Gets user review type for post.
* @param int $post_id Post ID.
* @return string Empty string if no review.
function wp_review_get_post_user_review_type( $post_id = null ) {
$rating_types = wp_review_get_rating_types();
$type = wp_review_get_post_review_type( $post_id );
return ''; // Not a review.
$type = get_post_meta( $post_id, 'wp_review_user_review_type', true );
$user_rating_setup = wp_review_get_user_rating_setup( $post_id );
$user_reviews = in_array( $user_rating_setup, array( WP_REVIEW_REVIEW_VISITOR_ONLY, WP_REVIEW_REVIEW_COMMENT_ONLY, WP_REVIEW_REVIEW_ALLOW_BOTH ) );
return ''; // User ratings not enabled.
if ( empty( $rating_types[ $type ]['user_rating'] ) ) {
$type = 'star'; // Fallback if specific $type is not available.
return apply_filters( 'wp_review_get_user_review_type', $type, $post_id );
* @param int $post_id Post ID.
function wp_review_get_post_box_template( $post_id = null ) {
if ( empty( $post_id ) ) {
$template = wp_review_get_box_template( $post_id );
if ( empty( $template ) || ! wp_review_locate_box_template( $template ) ) {
$template = 'default.php'; // fallback to default.php.
return apply_filters( 'wp_review_get_box_template', $template, $post_id );
* Gets template file path.
* @param string $template_name Template file name.
* @param bool $return_full_path Return full path or not.
function wp_review_locate_box_template( $template_name, $return_full_path = true ) {
// We look for box templates in:
// 1. plugins_dir/box-templates
// 2. theme_dir/wp-review
// 3. childtheme_dir/wp-review
// 4... Use filter to add more.
WP_REVIEW_DIR . 'box-templates',
get_template_directory() . '/wp-review',
get_stylesheet_directory() . '/wp-review',
$template_paths = apply_filters( 'wp_review_box_template_paths', $default_paths );
$paths = array_reverse( $template_paths );
foreach ( $paths as $path ) {
$full_path = trailingslashit( $path ) . $template_name;
if ( file_exists( $full_path ) ) {
return $return_full_path ? $located : $path_partial;
* Is an alias of {@see wp_review_locate_box_template()}.
* @see wp_review_locate_box_template()
* @param string $template_name Template name with extension and folders.
* @param bool $return_full_path Return full path.
function wp_review_locate_template( $template_name, $return_full_path = true ) {
return wp_review_locate_box_template( $template_name, $return_full_path );
* @param string $template_name Template name with extension and folders.
* @param array $data Data passed to template file.
function wp_review_load_template( $template_name, $data = array() ) {
$path = wp_review_locate_template( $template_name, true );
extract( $data ); // phpcs:ignore
include $path; // phpcs:ignore
* Shows rating using output template
* @param float $value Rating value.
* @param int $post_id Optional post ID.
* @param array $args Custom args.
function wp_review_rating( $value, $post_id = null, $args = array() ) {
if ( ! empty( $args['user_rating'] ) ) {
$type = wp_review_get_post_user_review_type( $post_id );
$type = wp_review_get_post_review_type( $post_id );
if ( empty( $post_id ) ) {
$rating_type = wp_review_get_rating_type_data( $type );
$colors = wp_review_get_colors( $post_id );
$colors = array_merge( $colors, $args );
if ( ! empty( $args['bar_text_color_from'] ) && isset( $colors[ $args['bar_text_color_from'] ] ) ) {
$colors['bar_text_color'] = $colors[ $args['bar_text_color_from'] ];
$colors = apply_filters( 'wp_review_colors', $colors, $post_id );
$color = $colors['color'];
// Don't allow higher rating than max.
if ( $value > $rating_type['max'] ) {
$value = $rating_type['max'];
$template = $rating_type['output_template'];
set_query_var( 'rating', compact( 'value', 'post_id', 'type', 'args', 'comment_rating', 'color', 'colors' ) );
load_template( $template, false );
$review = ob_get_contents();
* @param int $post_id Post ID.
* @param array $args Custom args.
function wp_review_user_rating( $post_id = null, $args = array() ) {
$options = get_option( 'wp_review_options' );
$type = wp_review_get_post_user_review_type( $post_id );
$rating_type = wp_review_get_rating_type_data( $type );
$post_reviews = mts_get_post_reviews( $post_id );
$value = ! empty( $post_reviews['rating'] ) ? $post_reviews['rating'] : '0.0';
$args['positive_count'] = isset( $post_reviews['positive_count'] ) ? $post_reviews['positive_count'] : 0;
$args['negative_count'] = isset( $post_reviews['negative_count'] ) ? $post_reviews['negative_count'] : 0;
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$user_reviewed = wp_review_has_reviewed( $post_id, $user_id, wp_review_get_user_ip(), WP_REVIEW_COMMENT_TYPE_VISITOR );
$login_required = ! is_user_logged_in() && ! empty( $options['registered_only'] );
if ( $user_reviewed || $login_required ) {
$class_name .= ' wpr-user-reviewed';
$class_name .= ' wpr-login-required';
$output = wp_review_rating(
'positive_count' => $args['positive_count'],
'negative_count' => $args['negative_count'],
); // Return just output template.
$colors = wp_review_get_colors( $post_id );
$color = $colors['color'];
$rating_type_template = $rating_type['input_template'];
set_query_var( 'rating', compact( 'value', 'post_id', 'comment_rating', 'args', 'color', 'colors' ) );
load_template( $rating_type_template, false );
$review = '<div class="wp-review-user-rating wp-review-user-rating-' . $type . '">' . ob_get_contents() . '</div>';
* Shows visitor features rating.
* @param int $post_id Post ID.
* @param array $args Custom arguments.
function wp_review_visitor_feature_rating( $post_id = null, $args = array() ) {
$args = wp_parse_args( $args, array( 'type' => 'user' ) );
$type = wp_review_get_post_user_review_type( $post_id );
$rating_type = wp_review_get_rating_type_data( $type );
if ( empty( $rating_type ) ) {
$colors = wp_review_get_colors( $post_id );
$color = $colors['color'];
$user_has_reviewed = wp_review_has_reviewed( $post_id, get_current_user_id(), wp_review_get_user_ip(), 'comment' === $args['type'] ? WP_REVIEW_COMMENT_TYPE_COMMENT : WP_REVIEW_COMMENT_TYPE_VISITOR );
$is_output = $user_has_reviewed;
$rating_type_template = $is_output ? $rating_type['output_template'] : $rating_type['input_template'];
$args['hide_button'] = true;