-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake-rating-post.php
44 lines (38 loc) · 1.21 KB
/
fake-rating-post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
add_action('wp_head', function() {
if ( is_single() ) :
global $post;
$get_rating = get_post_meta($post->ID, '_fake_rating', true);
if ( empty($get_rating) || $get_rating == '5' ) {
$rating = [
'3.8', '3.9', '4', '4.2', '4.2', '4.3', '4.5',
'4.6', '4.7', '4.8'
];
shuffle($rating);
shuffle($rating);
shuffle($rating);
shuffle($rating);
shuffle($rating);
$get_rating = $rating[0];
update_post_meta($post->ID, '_fake_rating', $get_rating);
}
$get_count = (int) get_post_meta($post->ID, '_fake_rating_count', true);
if ( empty($get_count) || $get_count < 10 || $get_count >= 1000 ) {
$get_count = rand(50, 900);
update_post_meta($post->ID, '_fake_rating_count', $get_count);
}
$rating["@context"] = "https://schema.org/";
$rating["@type"] = "Book";
$rating["name"] = get_bloginfo('name');
$rating["aggregateRating"] = [
"@type" => "AggregateRating",
"ratingValue" => $get_rating,
"ratingCount" => $get_count,
"bestRating" => "5",
"worstRating" => "1"
];
?>
<script type='application/ld+json'><?php echo json_encode($rating, 128);?></script>
<?php
endif;
});