PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / trunk
WP Popular Posts vtrunk
4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / src / Traits / QueriesPosts.php
wordpress-popular-posts / src / Traits Last commit date
QueriesPosts.php 4 years ago
QueriesPosts.php
60 lines
1 <?php
2 namespace WordPressPopularPosts\Traits;
3
4 use WordPressPopularPosts\Query;
5
6 trait QueriesPosts
7 {
8 /**
9 * Query object.
10 *
11 * @since 6.0.0
12 * @var \WordPressPopularPosts\Query
13 * @access private
14 */
15 private $query;
16
17 /**
18 * Gets Query object from cache if it exists,
19 * otherwise a new Query object will be
20 * instantiated and returned.
21 *
22 * @since 6.0.0
23 * @param array
24 * @return Query
25 */
26 protected function maybe_query(array $params)
27 {
28 // Return cached results
29 if ( $this->config['tools']['cache']['active'] ) {
30 $key = 'wpp_' . md5(json_encode($params));
31 $this->query = \WordPressPopularPosts\Cache::get($key);
32
33 if ( false === $this->query ) {
34 $this->query = new Query($params);
35
36 $time_value = $this->config['tools']['cache']['interval']['value'];
37 $time_unit = $this->config['tools']['cache']['interval']['time'];
38
39 // No popular posts found, check again in 1 minute
40 if ( ! $this->query->get_posts() ) {
41 $time_value = 1;
42 $time_unit = 'minute';
43 }
44
45 \WordPressPopularPosts\Cache::set(
46 $key,
47 $this->query,
48 $time_value,
49 $time_unit
50 );
51 }
52 } // Get real-time popular posts
53 else {
54 $this->query = new Query($params);
55 }
56
57 return $this->query;
58 }
59 }
60