Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-revie.../includes
File: functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WP Review
[2] Fix | Delete
*
[3] Fix | Delete
* @package WP_Review
[4] Fix | Delete
* @since 2.0
[5] Fix | Delete
* @copyright Copyright (c) 2013, MyThemesShop
[6] Fix | Delete
* @author MyThemesShop
[7] Fix | Delete
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Gets plugin option.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 3.0.0
[14] Fix | Delete
*
[15] Fix | Delete
* @param string $name Option name.
[16] Fix | Delete
* @param mixed $default Default value.
[17] Fix | Delete
* @return mixed
[18] Fix | Delete
*/
[19] Fix | Delete
function wp_review_option( $name, $default = null ) {
[20] Fix | Delete
static $options = null;
[21] Fix | Delete
if ( ! is_array( $options ) ) {
[22] Fix | Delete
$options = get_option( 'wp_review_options', array() );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
$value = isset( $options[ $name ] ) ? $options[ $name ] : $default;
[26] Fix | Delete
$value = apply_filters( 'wp_review_option_' . $name, $value );
[27] Fix | Delete
$value = apply_filters( 'wp_review_option', $value, $name );
[28] Fix | Delete
return $value;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Gets default colors.
[34] Fix | Delete
*
[35] Fix | Delete
* @since 3.0.0
[36] Fix | Delete
*
[37] Fix | Delete
* @return array
[38] Fix | Delete
*/
[39] Fix | Delete
function wp_review_get_default_colors() {
[40] Fix | Delete
$default_colors = array(
[41] Fix | Delete
'color' => '#1e73be',
[42] Fix | Delete
'inactive_color' => '#95bae0',
[43] Fix | Delete
'fontcolor' => '#555555',
[44] Fix | Delete
'bgcolor1' => '#e7e7e7',
[45] Fix | Delete
'bgcolor2' => '#ffffff',
[46] Fix | Delete
'bordercolor' => '#e7e7e7',
[47] Fix | Delete
);
[48] Fix | Delete
[49] Fix | Delete
$custom_default_colors = apply_filters( 'wp_review_default_colors', $default_colors );
[50] Fix | Delete
[51] Fix | Delete
return array_merge( $default_colors, $custom_default_colors );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Gets global colors setting.
[57] Fix | Delete
*
[58] Fix | Delete
* @since 3.0.0
[59] Fix | Delete
*
[60] Fix | Delete
* @return array
[61] Fix | Delete
*/
[62] Fix | Delete
function wp_review_get_global_colors() {
[63] Fix | Delete
$colors = wp_review_option( 'colors' );
[64] Fix | Delete
$default_colors = wp_review_get_default_colors();
[65] Fix | Delete
$fields = array( 'color', 'inactive_color', 'fontcolor', 'bgcolor1', 'bgcolor2', 'bordercolor' );
[66] Fix | Delete
foreach ( $fields as $key ) {
[67] Fix | Delete
if ( empty( $colors[ $key ] ) ) {
[68] Fix | Delete
$colors[ $key ] = isset( $default_colors[ $key ] ) ? $default_colors[ $key ] : '';
[69] Fix | Delete
}
[70] Fix | Delete
}
[71] Fix | Delete
return $colors;
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Gets default location.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 3.0.0
[79] Fix | Delete
*
[80] Fix | Delete
* @return string
[81] Fix | Delete
*/
[82] Fix | Delete
function wp_review_get_default_location() {
[83] Fix | Delete
return apply_filters( 'wp_review_default_location', 'bottom' );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Gets default criteria.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 3.0.0
[91] Fix | Delete
*
[92] Fix | Delete
* @return array
[93] Fix | Delete
*/
[94] Fix | Delete
function wp_review_get_default_criteria() {
[95] Fix | Delete
$default_criteria = apply_filters( 'wp_review_default_criteria', array() );
[96] Fix | Delete
if ( ! $default_criteria && wp_review_option( 'default_features', array() ) ) {
[97] Fix | Delete
$default_criteria = wp_review_option( 'default_features', array() );
[98] Fix | Delete
}
[99] Fix | Delete
return $default_criteria;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Gets post custom layout data.
[105] Fix | Delete
*
[106] Fix | Delete
* @since 3.0.0
[107] Fix | Delete
*
[108] Fix | Delete
* @param int $post_id Post ID.
[109] Fix | Delete
* @return array
[110] Fix | Delete
*/
[111] Fix | Delete
function wp_review_get_custom_layout_data( $post_id ) {
[112] Fix | Delete
$data = array(
[113] Fix | Delete
'enable' => get_post_meta( $post_id, 'wp_review_custom_colors', true ),
[114] Fix | Delete
'box_template' => get_post_meta( $post_id, 'wp_review_box_template', true ),
[115] Fix | Delete
'color' => get_post_meta( $post_id, 'wp_review_color', true ),
[116] Fix | Delete
'inactive_color' => get_post_meta( $post_id, 'wp_review_inactive_color', true ),
[117] Fix | Delete
'fontcolor' => get_post_meta( $post_id, 'wp_review_fontcolor', true ),
[118] Fix | Delete
'bgcolor1' => get_post_meta( $post_id, 'wp_review_bgcolor1', true ),
[119] Fix | Delete
'bgcolor2' => get_post_meta( $post_id, 'wp_review_bgcolor2', true ),
[120] Fix | Delete
'bordercolor' => get_post_meta( $post_id, 'wp_review_bordercolor', true ),
[121] Fix | Delete
);
[122] Fix | Delete
return $data;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
[126] Fix | Delete
// Image sizes for the widgets.
[127] Fix | Delete
add_image_size( 'wp_review_large', 320, 200, true );
[128] Fix | Delete
add_image_size( 'wp_review_small', 65, 65, true );
[129] Fix | Delete
[130] Fix | Delete
// Filter to add custom images sizes in Thumbnail selection box.
[131] Fix | Delete
add_filter(
[132] Fix | Delete
'image_size_names_choose',
[133] Fix | Delete
function( $sizes ) {
[134] Fix | Delete
return array_merge(
[135] Fix | Delete
$sizes,
[136] Fix | Delete
apply_filters(
[137] Fix | Delete
'wp_review_custom_image_sizes',
[138] Fix | Delete
array(
[139] Fix | Delete
'wp_review_small' => __( 'WP Review Small', 'wp-review' ),
[140] Fix | Delete
'wp_review_large' => __( 'WP Review Large', 'wp-review' ),
[141] Fix | Delete
)
[142] Fix | Delete
)
[143] Fix | Delete
);
[144] Fix | Delete
}
[145] Fix | Delete
);
[146] Fix | Delete
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Get the meta box data.
[150] Fix | Delete
* Replaced by wp_review_get_review_box() in v2.0
[151] Fix | Delete
*
[152] Fix | Delete
* @since 1.0
[153] Fix | Delete
*
[154] Fix | Delete
* @param int $post_id Post ID.
[155] Fix | Delete
* @return string
[156] Fix | Delete
*/
[157] Fix | Delete
function wp_review_get_data( $post_id = null ) {
[158] Fix | Delete
return wp_review_get_review_box( $post_id );
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Injects reviews to content.
[164] Fix | Delete
*
[165] Fix | Delete
* @param string $content Post content.
[166] Fix | Delete
* @return string
[167] Fix | Delete
*/
[168] Fix | Delete
function wp_review_inject_data( $content ) {
[169] Fix | Delete
$post_id = get_the_ID();
[170] Fix | Delete
$options = get_option( 'wp_review_options' );
[171] Fix | Delete
$custom_location = get_post_meta( $post_id, 'wp_review_custom_location', true );
[172] Fix | Delete
$location = get_post_meta( $post_id, 'wp_review_location', true );
[173] Fix | Delete
if ( ! $custom_location && ! empty( $options['review_location'] ) ) {
[174] Fix | Delete
$location = $options['review_location'];
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
$location = apply_filters( 'wp_review_location', $location, $post_id );
[178] Fix | Delete
[179] Fix | Delete
if ( ! $location || 'custom' === $location ) {
[180] Fix | Delete
return $content;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
if ( ! is_singular() || ! is_main_query() ) {
[184] Fix | Delete
return $content;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
if ( ! wp_review_is_amp_page() && ! in_the_loop() ) {
[188] Fix | Delete
return $content;
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
$review = wp_review_get_review_box();
[192] Fix | Delete
[193] Fix | Delete
if ( 'bottom' == $location ) {
[194] Fix | Delete
global $multipage, $numpages, $page;
[195] Fix | Delete
if ( $multipage ) {
[196] Fix | Delete
if ( $page == $numpages ) {
[197] Fix | Delete
return $content . $review;
[198] Fix | Delete
} else {
[199] Fix | Delete
return $content;
[200] Fix | Delete
}
[201] Fix | Delete
} else {
[202] Fix | Delete
return $content . $review;
[203] Fix | Delete
}
[204] Fix | Delete
} elseif ( 'top' == $location ) {
[205] Fix | Delete
return $review . $content;
[206] Fix | Delete
} else {
[207] Fix | Delete
return $content;
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
/* Display the meta box data below 'the_content' hook. */
[211] Fix | Delete
add_filter( 'the_content', 'wp_review_inject_data' );
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Retrieve only total rating.
[215] Fix | Delete
* To be used on archive pages, etc.
[216] Fix | Delete
*
[217] Fix | Delete
* @since 1.0
[218] Fix | Delete
*
[219] Fix | Delete
* @param bool $echo Echo or not.
[220] Fix | Delete
* @param string $class CSS class.
[221] Fix | Delete
* @param int $post_id Post ID. Use current post ID if empty.
[222] Fix | Delete
* @param array $args Custom arguments. Use for filter.
[223] Fix | Delete
*/
[224] Fix | Delete
function wp_review_show_total( $echo = true, $class = 'review-total-only', $post_id = null, $args = array() ) {
[225] Fix | Delete
if ( empty( $post_id ) ) {
[226] Fix | Delete
$post_id = get_the_ID();
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
$rating_types = wp_review_get_rating_types();
[230] Fix | Delete
$type = wp_review_get_post_review_type( $post_id );
[231] Fix | Delete
$user_type = wp_review_get_post_user_review_type( $post_id );
[232] Fix | Delete
if ( ! $type && ! $user_type ) {
[233] Fix | Delete
return '';
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
wp_enqueue_style( 'wp_review-style' );
[237] Fix | Delete
[238] Fix | Delete
// Fix for themes.
[239] Fix | Delete
if ( false !== strpos( $class, 'latestPost-review-wrapper' ) ) {
[240] Fix | Delete
$args['color'] = '#fff';
[241] Fix | Delete
$args['inactive_color'] = '#dedcdc';
[242] Fix | Delete
}
[243] Fix | Delete
// Fix for rank-math.
[244] Fix | Delete
if ( false !== strpos( $class, 'rank-math-snippet' ) ) {
[245] Fix | Delete
$args['color'] = '#fff';
[246] Fix | Delete
$args['inactive_color'] = '#dedcdc';
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
$show_on_thumbnails_type = 'author';
[250] Fix | Delete
$show_on_thumbnails_type = apply_filters( 'wp_review_thumbnails_total', $show_on_thumbnails_type, $post_id, $args ); // Will override option.
[251] Fix | Delete
[252] Fix | Delete
$rating = '';
[253] Fix | Delete
$total = '';
[254] Fix | Delete
switch ( $show_on_thumbnails_type ) {
[255] Fix | Delete
case 'author':
[256] Fix | Delete
$total = get_post_meta( $post_id, 'wp_review_total', true );
[257] Fix | Delete
[258] Fix | Delete
if ( in_array( $type, array( 'point', 'percentage' ) ) ) {
[259] Fix | Delete
$rating = sprintf( $rating_types[ $type ]['value_text'], $total );
[260] Fix | Delete
} else {
[261] Fix | Delete
$rating = wp_review_rating( $total, $post_id, $args );
[262] Fix | Delete
}
[263] Fix | Delete
break;
[264] Fix | Delete
[265] Fix | Delete
case 'visitors':
[266] Fix | Delete
$total = get_post_meta( $post_id, 'wp_review_user_reviews', true );
[267] Fix | Delete
[268] Fix | Delete
if ( 'point' == $user_type || 'percentage' == $user_type ) {
[269] Fix | Delete
$rating = sprintf( $rating_types[ $user_type ]['value_text'], $total );
[270] Fix | Delete
} else {
[271] Fix | Delete
$rating = wp_review_rating( $total, $post_id, array( 'user_rating' => true ) ); // Return just output template.
[272] Fix | Delete
}
[273] Fix | Delete
break;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
$review = '';
[277] Fix | Delete
if ( ! empty( $rating ) && ! empty( $total ) ) {
[278] Fix | Delete
$style = '';
[279] Fix | Delete
if ( ! empty( $args['context'] ) && 'product-rating' === $args['context'] ) {
[280] Fix | Delete
$colors = wp_review_get_colors( $post_id );
[281] Fix | Delete
$style .= sprintf( ' background-color: %s;', esc_attr( $colors['color'] ) );
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
if ( trim( $style ) ) {
[285] Fix | Delete
$style = 'style="' . esc_attr( $style ) . '"';
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
$review .= '<div class="review-type-' . $type . ' ' . esc_attr( $class ) . ' wp-review-show-total wp-review-total-' . $post_id . ' wp-review-total-' . $type . '" ' . $style . '> ';
[289] Fix | Delete
$review .= $rating;
[290] Fix | Delete
$review .= '</div>';
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
$review = apply_filters( 'wp_review_show_total', $review, $post_id, $type, $total );
[294] Fix | Delete
$review = apply_filters( 'wp_review_total_output', $review, $post_id, $type, $total, $class, $args );
[295] Fix | Delete
[296] Fix | Delete
if ( $echo ) {
[297] Fix | Delete
echo $review; // WPCS: xss ok.
[298] Fix | Delete
} else {
[299] Fix | Delete
return $review;
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
* Gets post visitor reviews data.
[306] Fix | Delete
*
[307] Fix | Delete
* @param int $post_id Post ID.
[308] Fix | Delete
* @param bool $force Force fetching from comments instead of post meta.
[309] Fix | Delete
* @return array
[310] Fix | Delete
*/
[311] Fix | Delete
function mts_get_post_reviews( $post_id, $force = false ) {
[312] Fix | Delete
$post_reviews = get_post_meta( $post_id, 'wp_review_user_reviews', true );
[313] Fix | Delete
$review_count = (int) get_post_meta( $post_id, 'wp_review_review_count', true );
[314] Fix | Delete
$positive_count = (int) get_post_meta( $post_id, 'wp_review_positive_count', true );
[315] Fix | Delete
$negative_count = (int) get_post_meta( $post_id, 'wp_review_negative_count', true );
[316] Fix | Delete
[317] Fix | Delete
if ( ! $force && $post_reviews && $review_count ) {
[318] Fix | Delete
return array(
[319] Fix | Delete
'rating' => $post_reviews,
[320] Fix | Delete
'count' => $review_count,
[321] Fix | Delete
'positive_count' => $positive_count,
[322] Fix | Delete
'negative_count' => $negative_count,
[323] Fix | Delete
);
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
if ( is_numeric( $post_id ) && $post_id > 0 ) {
[327] Fix | Delete
$comments = get_comments(
[328] Fix | Delete
array(
[329] Fix | Delete
'post_id' => $post_id,
[330] Fix | Delete
'type' => WP_REVIEW_COMMENT_TYPE_VISITOR,
[331] Fix | Delete
'status' => 'approve',
[332] Fix | Delete
)
[333] Fix | Delete
);
[334] Fix | Delete
$rating = array_reduce( $comments, 'wpreview_visitor_ratings_callback', 0 );
[335] Fix | Delete
$count = count( $comments );
[336] Fix | Delete
$post_reviews = array(
[337] Fix | Delete
'rating' => $count > 0 ? round( $rating / $count, 2 ) : 0,
[338] Fix | Delete
'count' => $count,
[339] Fix | Delete
);
[340] Fix | Delete
[341] Fix | Delete
$positive_comments = get_comments(
[342] Fix | Delete
array(
[343] Fix | Delete
'post_id' => $post_id,
[344] Fix | Delete
'type' => WP_REVIEW_COMMENT_TYPE_VISITOR,
[345] Fix | Delete
'status' => 'approve',
[346] Fix | Delete
'fields' => 'ids',
[347] Fix | Delete
'meta_key' => WP_REVIEW_VISITOR_RATING_METAKEY,
[348] Fix | Delete
'meta_value' => 100,
[349] Fix | Delete
)
[350] Fix | Delete
);
[351] Fix | Delete
[352] Fix | Delete
$post_reviews['positive_count'] = count( $positive_comments );
[353] Fix | Delete
[354] Fix | Delete
$negative_comments = get_comments(
[355] Fix | Delete
array(
[356] Fix | Delete
'post_id' => $post_id,
[357] Fix | Delete
'type' => WP_REVIEW_COMMENT_TYPE_VISITOR,
[358] Fix | Delete
'status' => 'approve',
[359] Fix | Delete
'fields' => 'ids',
[360] Fix | Delete
'meta_key' => WP_REVIEW_VISITOR_RATING_METAKEY,
[361] Fix | Delete
'meta_value' => 0,
[362] Fix | Delete
)
[363] Fix | Delete
);
[364] Fix | Delete
[365] Fix | Delete
$post_reviews['negative_count'] = count( $negative_comments );
[366] Fix | Delete
[367] Fix | Delete
update_post_meta( $post_id, 'wp_review_user_reviews', $post_reviews['rating'] );
[368] Fix | Delete
update_post_meta( $post_id, 'wp_review_review_count', $post_reviews['count'] );
[369] Fix | Delete
update_post_meta( $post_id, 'wp_review_positive_count', $post_reviews['positive_count'] );
[370] Fix | Delete
update_post_meta( $post_id, 'wp_review_negative_count', $post_reviews['negative_count'] );
[371] Fix | Delete
[372] Fix | Delete
return $post_reviews;
[373] Fix | Delete
}
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
[377] Fix | Delete
/**
[378] Fix | Delete
* Gets post comment reviews data.
[379] Fix | Delete
*
[380] Fix | Delete
* @param int $post_id Post ID.
[381] Fix | Delete
* @param bool $force Force fetching from comments instead of post meta.
[382] Fix | Delete
* @return array
[383] Fix | Delete
*/
[384] Fix | Delete
function mts_get_post_comments_reviews( $post_id, $force = false ) {
[385] Fix | Delete
$post_reviews = get_post_meta( $post_id, 'wp_review_comments_rating_value', true );
[386] Fix | Delete
$review_count = (int) get_post_meta( $post_id, 'wp_review_comments_rating_count', true );
[387] Fix | Delete
$positive_count = (int) get_post_meta( $post_id, 'wp_review_comments_positive_count', true );
[388] Fix | Delete
$negative_count = (int) get_post_meta( $post_id, 'wp_review_comments_negative_count', true );
[389] Fix | Delete
[390] Fix | Delete
if ( ! $force && $post_reviews && $review_count ) {
[391] Fix | Delete
return array(
[392] Fix | Delete
'rating' => $post_reviews,
[393] Fix | Delete
'count' => $review_count,
[394] Fix | Delete
'positive_count' => $positive_count,
[395] Fix | Delete
'negative_count' => $negative_count,
[396] Fix | Delete
);
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
if ( is_numeric( $post_id ) && $post_id > 0 ) {
[400] Fix | Delete
$comments = get_comments(
[401] Fix | Delete
array(
[402] Fix | Delete
'post_id' => $post_id,
[403] Fix | Delete
'type' => WP_REVIEW_COMMENT_TYPE_COMMENT,
[404] Fix | Delete
'status' => 'approve',
[405] Fix | Delete
)
[406] Fix | Delete
);
[407] Fix | Delete
$rating = array_reduce( $comments, 'wpreview_comment_ratings_callback', 0 );
[408] Fix | Delete
$count = count( $comments );
[409] Fix | Delete
$post_reviews = array(
[410] Fix | Delete
'rating' => $count > 0 ? round( $rating / $count, 2 ) : 0,
[411] Fix | Delete
'count' => $count,
[412] Fix | Delete
);
[413] Fix | Delete
[414] Fix | Delete
$positive_comments = get_comments(
[415] Fix | Delete
array(
[416] Fix | Delete
'post_id' => $post_id,
[417] Fix | Delete
'type' => WP_REVIEW_COMMENT_TYPE_COMMENT,
[418] Fix | Delete
'status' => 'approve',
[419] Fix | Delete
'fields' => 'ids',
[420] Fix | Delete
'meta_key' => WP_REVIEW_COMMENT_RATING_METAKEY,
[421] Fix | Delete
'meta_value' => 100,
[422] Fix | Delete
)
[423] Fix | Delete
);
[424] Fix | Delete
[425] Fix | Delete
$post_reviews['positive_count'] = count( $positive_comments );
[426] Fix | Delete
[427] Fix | Delete
$negative_comments = get_comments(
[428] Fix | Delete
array(
[429] Fix | Delete
'post_id' => $post_id,
[430] Fix | Delete
'type' => WP_REVIEW_COMMENT_TYPE_COMMENT,
[431] Fix | Delete
'status' => 'approve',
[432] Fix | Delete
'fields' => 'ids',
[433] Fix | Delete
'meta_key' => WP_REVIEW_COMMENT_RATING_METAKEY,
[434] Fix | Delete
'meta_value' => 0,
[435] Fix | Delete
)
[436] Fix | Delete
);
[437] Fix | Delete
[438] Fix | Delete
$post_reviews['negative_count'] = count( $negative_comments );
[439] Fix | Delete
[440] Fix | Delete
update_post_meta( $post_id, 'wp_review_comments_rating_value', $post_reviews['rating'] );
[441] Fix | Delete
update_post_meta( $post_id, 'wp_review_comments_rating_count', $post_reviews['count'] );
[442] Fix | Delete
update_post_meta( $post_id, 'wp_review_comments_positive_count', $post_reviews['positive_count'] );
[443] Fix | Delete
update_post_meta( $post_id, 'wp_review_comments_negative_count', $post_reviews['negative_count'] );
[444] Fix | Delete
[445] Fix | Delete
return $post_reviews;
[446] Fix | Delete
}
[447] Fix | Delete
}
[448] Fix | Delete
[449] Fix | Delete
[450] Fix | Delete
/**
[451] Fix | Delete
* Gets post visitor feature reviews data.
[452] Fix | Delete
*
[453] Fix | Delete
* @param int $post_id Post ID.
[454] Fix | Delete
* @param bool $force Force fetching from comments instead of post meta.
[455] Fix | Delete
* @param string $type Accepts `user` or `comment`.
[456] Fix | Delete
* @return array
[457] Fix | Delete
*/
[458] Fix | Delete
function wp_review_get_post_feature_reviews( $post_id = null, $force = false, $type = 'user' ) {
[459] Fix | Delete
if ( ! $post_id ) {
[460] Fix | Delete
$post_id = get_the_ID();
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
$post_meta_key = "wp_review_{$type}_feature_reviews";
[464] Fix | Delete
$reviews = get_post_meta( $post_id, $post_meta_key, true );
[465] Fix | Delete
if ( ! $force && $reviews ) {
[466] Fix | Delete
return $reviews;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
$features = wp_review_get_review_items( $post_id );
[470] Fix | Delete
if ( ! $features ) {
[471] Fix | Delete
return array();
[472] Fix | Delete
}
[473] Fix | Delete
$comments = get_comments(
[474] Fix | Delete
array(
[475] Fix | Delete
'post_id' => $post_id,
[476] Fix | Delete
'type' => 'comment' === $type ? WP_REVIEW_COMMENT_TYPE_COMMENT : WP_REVIEW_COMMENT_TYPE_VISITOR,
[477] Fix | Delete
'status' => 'approve',
[478] Fix | Delete
)
[479] Fix | Delete
);
[480] Fix | Delete
$reviews = array();
[481] Fix | Delete
foreach ( $features as $value ) {
[482] Fix | Delete
$reviews[ $value['id'] ] = array(
[483] Fix | Delete
'total' => 0,
[484] Fix | Delete
'count' => 0,
[485] Fix | Delete
'positive' => 0,
[486] Fix | Delete
'negative' => 0,
[487] Fix | Delete
);
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
foreach ( $comments as $comment ) {
[491] Fix | Delete
$data = get_comment_meta( $comment->comment_ID, WP_REVIEW_COMMENT_FEATURES_RATING_METAKEY, true );
[492] Fix | Delete
if ( ! $data ) {
[493] Fix | Delete
continue;
[494] Fix | Delete
}
[495] Fix | Delete
foreach ( $data as $key => $value ) {
[496] Fix | Delete
if ( empty( $reviews[ $key ] ) ) {
[497] Fix | Delete
continue;
[498] Fix | Delete
}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function