admin
2 years ago
core
2 years ago
class-activator.php
3 years ago
class-assets.php
2 years ago
class-builder-page.php
3 years ago
class-deactivator.php
3 years ago
class-debug-info.php
2 years ago
class-feed-ajax.php
2 years ago
class-feed-block.php
2 years ago
class-feed-deserializer.php
2 years ago
class-feed-old.php
4 years ago
class-feed-page.php
3 years ago
class-feed-serializer.php
3 years ago
class-feed-shortcode.php
3 years ago
class-feed-widget.php
4 years ago
class-plugin-overview-ajax.php
3 years ago
class-plugin-overview.php
3 years ago
class-plugin-settings.php
2 years ago
class-plugin-support.php
3 years ago
class-plugin.php
2 years ago
class-post-types.php
3 years ago
class-reviews-cron.php
2 years ago
class-settings-save.php
3 years ago
class-view.php
2 years ago
index.php
4 years ago
page-setting-fig.php
3 years ago
page-setting-support.php
4 years ago
class-feed-deserializer.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes; |
| 4 | |
| 5 | class Feed_Deserializer { |
| 6 | |
| 7 | private $wp_query; |
| 8 | |
| 9 | public function __construct(\WP_Query $wp_query) { |
| 10 | $this->wp_query = $wp_query; |
| 11 | } |
| 12 | |
| 13 | public function get_feed($post_id, $args = array()) { |
| 14 | $default_args = array( |
| 15 | 'post_type' => Post_Types::FEED_POST_TYPE, |
| 16 | 'p' => $post_id, |
| 17 | 'posts_per_page' => 1, |
| 18 | 'no_found_rows' => true, |
| 19 | ); |
| 20 | |
| 21 | $args = wp_parse_args($args, $default_args); |
| 22 | $this->wp_query->query($args); |
| 23 | |
| 24 | if (!$this->wp_query->have_posts()) { |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | return $this->wp_query->posts[0]; |
| 29 | } |
| 30 | |
| 31 | public function get_all_feeds($args = array()) { |
| 32 | $default_args = array( |
| 33 | 'post_type' => Post_Types::FEED_POST_TYPE, |
| 34 | 'fields' => array('ID', 'post_title', 'post_content'), |
| 35 | 'posts_per_page' => 300, |
| 36 | 'no_found_rows' => true, |
| 37 | ); |
| 38 | |
| 39 | $args = wp_parse_args($args, $default_args); |
| 40 | $this->wp_query->query($args); |
| 41 | |
| 42 | if (!$this->wp_query->have_posts()) { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | return $this->wp_query->posts; |
| 47 | } |
| 48 | |
| 49 | public function get_all_feeds_short($args = array()) { |
| 50 | $short = array(); |
| 51 | $feeds = $this->get_all_feeds($args); |
| 52 | if (is_array($feeds) || is_object($feeds)) { |
| 53 | foreach ($feeds as $feed) { |
| 54 | $item = ['id' => $feed->ID, 'name' => $feed->post_title]; |
| 55 | array_push($short, $item); |
| 56 | } |
| 57 | } |
| 58 | return $short; |
| 59 | } |
| 60 | |
| 61 | public function get_feed_count($args = array()) { |
| 62 | $default_args = array( |
| 63 | 'post_type' => Post_Types::FEED_POST_TYPE, |
| 64 | 'posts_per_page' => -1, |
| 65 | 'no_found_rows' => true, |
| 66 | ); |
| 67 | |
| 68 | $args = wp_parse_args($args, $default_args); |
| 69 | $this->wp_query->query($args); |
| 70 | |
| 71 | if (!$this->wp_query->have_posts()) { |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | return count($this->wp_query->posts); |
| 76 | } |
| 77 | |
| 78 | } |
| 79 |