: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( isset( $data['multiline'] ) && $data['multiline'] ) {
$value = preg_split( '/\r\n|[\r\n]/', $value );
if ( isset( $data['part_of'] ) ) {
$args[ $data['part_of'] ]['@type'] = $data['@type'];
if ( 'image' === $data['type'] ) {
$args[ $data['part_of'] ][ $name ] = $value['url'];
} elseif ( in_array( $name, apply_filters( 'wp_reviev_schema_ISO_8601_duration_items', array( 'prepTime', 'cookTime', 'totalTime', 'duration' ) ) ) ) { // phpcs:ignore
$args[ $data['part_of'] ][ $name ] = 'PT' . $value;
$args[ $data['part_of'] ][ $name ] = $value;
if ( 'image' === $data['type'] ) {
$args[ $name ] = $value['url'];
} elseif ( in_array( $name, apply_filters( 'wp_reviev_schema_ISO_8601_duration_items', array( 'prepTime', 'cookTime', 'totalTime', 'duration' ) ) ) ) { // phpcs:ignore
$args[ $name ] = 'PT' . $value;
// Add aggregateRating to Recipe.
if ( 'Recipe' === $review['schema'] ) {
$args['aggregateRating'] = wp_review_normalize_rating_value( $review['total'] );
if ( isset( $args['video'] ) && ( empty( $args['video']['name'] ) || empty( $args['video']['description'] ) || empty( $args['video']['thumbnailUrl'] ) || empty( $args['video']['uploadDate'] ) ) ) {
if ( 'Product' === $review['schema'] ) {
// Product type recommends both review and aggregateRating.
if ( empty( $args['review'] ) ) {
$review_rating = wp_review_get_schema_nested_review_args( $review );
if ( ! empty( $review_rating ) ) {
$args['review'] = $review_rating;
if ( empty( $args['aggregateRating'] ) ) {
$aggregate_rating = wp_review_get_schema_nested_user_rating_args( $review );
if ( ! empty( $aggregate_rating ) ) {
$args['aggregateRating'] = $aggregate_rating;
// Nested aggregateRating is recommended in some types ( SoftwareApplication, Recipe ).
if ( in_array( $review['schema'], apply_filters( 'wp_review_schema_force_nested_user_rating_types', array( 'SoftwareApplication', 'Recipe' ) ) ) && ( $review['user_review'] || $review['comments_review'] ) ) {
$aggregate_rating = wp_review_get_schema_nested_user_rating_args( $review );
if ( ! empty( $aggregate_rating ) ) {
$args['aggregateRating'] = $aggregate_rating;
return apply_filters( 'wp_review_get_schema_nested_item_args', $args, $review );
* Gets schema ld-json data.
* @param string $type Schema type.
* @param array $data Schema data.
* @param array $review Review data.
function wp_review_get_ldjson_data( $type, $data, $review ) {
$post_id = $review['post_id'];
$headline = ! empty( $data['headline'] ) ? $data['headline'] : '';
// Limit headline length to 110 characters.
if ( strlen( $headline ) > 110 ) {
$headline = substr( $headline, 0, 109 ) . '…';
'mainEntityOfPage' => array(
'@id' => get_permalink( $post_id ),
'@type' => 'ImageObject',
'url' => ! empty( $data['image']['url'] ) ? esc_url( $data['image']['url'] ) : '',
'datePublished' => get_the_time( 'Y-m-d H:i:s', $post_id ),
'dateModified' => get_the_modified_time( 'Y-m-d H:i:s', $post_id ),
'name' => ! empty( $data['author'] ) ? $data['author'] : '',
'@type' => 'Organization',
'name' => ! empty( $data['publisher'] ) ? $data['publisher'] : '',
'@type' => 'ImageObject',
'url' => ! empty( $data['publisher_logo']['url'] ) ? esc_url( $data['publisher_logo']['url'] ) : '',
'description' => ! empty( $data['description'] ) ? $data['description'] : '',
$ldjson_data['name'] = empty( $review['heading'] ) ? get_the_title( $review['post_id'] ) : esc_html( $review['heading'] );
function wp_review_get_rating_icon() {
function wp_review_get_rating_image() {
$rating_image = wp_review_option( 'rating_image', apply_filters( 'wp_review_default_rating_image', '' ) );
$rating_img_src = wp_get_attachment_image_src( $rating_image );
if ( ! empty( $rating_img_src ) ) {
$rating_image = $rating_img_src[0];
* Checks if review is enable.
* @param int $post_id Post ID.
function wp_review_is_enable( $post_id = null ) {
return ! ! wp_review_get_post_review_type( $post_id );
* Gets post rating schema.
* @param int $post_id Post ID.
function wp_review_get_rating_schema( $post_id ) {
$value = get_post_meta( $post_id, 'wp_review_rating_schema', true );
if ( wp_review_get_user_rating_setup( $post_id ) == WP_REVIEW_REVIEW_DISABLED ) {
* Checks if review description is hidden.
* @param int $post_id Post ID.
function wp_review_is_hidden_desc( $post_id ) {
$hide_desc = get_post_meta( $post_id, 'wp_review_hide_desc', true );
* @param int $post_id Post ID.
function wp_review_get_product_price( $post_id = null ) {
return get_post_meta( $post_id, 'wp_review_product_price', true );
* @param int $post_id Post ID.
function wp_review_product_price( $post_id = null ) {
echo esc_html( wp_review_get_product_price( $post_id ) );
* @param int $post_id Post ID.
function wp_review_get_review_total( $post_id = null ) {
return floatval( get_post_meta( $post_id, 'wp_review_total', true ) );
* @param int $post_id Post ID.
function wp_review_get_review_items( $post_id = null ) {
$items = get_post_meta( $post_id, 'wp_review_item', true );
if ( ! $items || ! is_array( $items ) ) {
$global_colors = wp_review_get_global_colors();
$custom_colors = get_post_meta( $post_id, 'wp_review_custom_colors', true );
$post_color = get_post_meta( $post_id, 'wp_review_color', true );
$post_inactive_color = get_post_meta( $post_id, 'wp_review_inactive_color', true );
$default_color = $custom_colors && $post_color ? $post_color : $global_colors['color'];
$default_inactive = $custom_colors && $post_inactive_color ? $post_inactive_color : $global_colors['inactive_color'];
foreach ( $items as $index => $item ) {
if ( empty( $item['id'] ) || is_numeric( $item['id'] ) ) {
$items[ $index ]['id'] = sanitize_title( $item['wp_review_item_title'] ) . '_' . wp_generate_password( 6 );
update_post_meta( $post_id, 'wp_review_item', $items );
foreach ( $items as $index => $item ) {
$items[ $item['id'] ] = $items[ $index ];
unset( $items[ $index ] );
if ( empty( $item['wp_review_item_color'] ) ) {
$items[ $item['id'] ]['wp_review_item_color'] = $default_color;
if ( empty( $item['wp_review_item_inactive_color'] ) ) {
$items[ $item['id'] ]['wp_review_item_inactive_color'] = $default_inactive;
* @param int $post_id Post ID.
function wp_review_get_review_links( $post_id = null ) {
$links = get_post_meta( $post_id, 'wp_review_links', true );
$links = $links ? (array) $links : array();
foreach ( $links as $review_link ) {
if ( ! empty( $review_link['text'] ) ) {
$return_links[] = $review_link;
* Gets review box template.
* @param int $post_id Post ID.
function wp_review_get_box_template( $post_id = null ) {
$template = get_post_meta( $post_id, 'wp_review_box_template', true );
$custom = get_post_meta( $post_id, 'wp_review_custom_colors', true );
if ( ! $custom || ! $template ) {
$template = wp_review_option( 'box_template', 'default' );
* Gets transient expired time.
function wp_review_transient_expired_time() {
return apply_filters( 'wp_review_transient_expired_time', WEEK_IN_SECONDS );
function wp_review_clear_cache() {
// delete_transient( 'wp_review_recent_reviews_query' );
// delete_transient( 'wp_review_toprated_reviews_query' );
// delete_transient( 'wp_review_mostvoted_reviews_query' );
// delete_transient( 'wp_review_custom_reviews_query' );
* Adds an option to clear cache via URL.
function wp_review_clear_cache_via_url() {
if ( ! isset( $_GET['clear'] ) ) {
add_action( 'template_redirect', 'wp_review_clear_cache_via_url' );
* @param string $type Type of the query.
* @param array $options Query options.
function wp_review_get_reviews_query( $type, $options ) {
$key = 'wp_review_' . md5(
'%1$s_%2$s_reviews_query',
if ( ! empty( $options['clear_cache'] ) ) {
delete_transient( $key );
$query = get_transient( $key );
if ( $query && empty( $options['no_cache'] ) ) {
$options['review_type'] = ! empty( $options['review_type'] ) ? (array) $options['review_type'] : array();
$options['cat'] = ! empty( $options['cat'] ) ? (array) $options['cat'] : array();
'orderby' => 'meta_value_num',
'meta_key' => 'wp_review_review_count',
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'meta_key' => ! empty( $options['toprated_key'] ) ? $options['toprated_key'] : 'wp_review_total',
'post_status' => 'publish',
'category__in' => $options['cat'],
'post_status' => 'publish',
'post__in' => $options['ids'],
'post_status' => 'publish',
'post_status' => 'publish',
$query_args['ignore_sticky_posts'] = true;
$query_args['post_type'] = isset( $options['post_type'] ) ? $options['post_type'] : 'post';
if ( ! empty( $options['post_num'] ) ) {
$query_args['posts_per_page'] = intval( $options['post_num'] );
if ( ! empty( $options['page'] ) ) {
$query_args['paged'] = intval( $options['page'] );
if ( ! empty( $options['number_of_days'] ) && intval( $options['number_of_days'] ) ) {
$date_str = $options['number_of_days'] > 1 ? '%s days ago' : '%s day ago';
$query_args['date_query'] = array(
'after' => sprintf( $date_str, intval( $options['number_of_days'] ) ),
// If specific review type.
if ( ! empty( $options['review_type'] ) ) {
'key' => 'wp_review_type',
'value' => $options['review_type'],
if ( wp_review_option( 'review_type' ) === $options['review_type'] ) {
// Is post setting is not set and default review type is not none.