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-block.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes; |
| 4 | |
| 5 | use WP_Rplg_Google_Reviews\Includes\Core\Core; |
| 6 | |
| 7 | class Feed_Block { |
| 8 | |
| 9 | private $core; |
| 10 | private $view; |
| 11 | private $assets; |
| 12 | private $feed_deserializer; |
| 13 | |
| 14 | public function __construct(Feed_Deserializer $feed_deserializer, Core $core, View $view, Assets $assets) { |
| 15 | $this->core = $core; |
| 16 | $this->view = $view; |
| 17 | $this->assets = $assets; |
| 18 | $this->feed_deserializer = $feed_deserializer; |
| 19 | } |
| 20 | |
| 21 | public function register() { |
| 22 | add_action('init', [$this, 'register_block'], 999); |
| 23 | add_action('block_categories_all', [$this, 'register_category']); |
| 24 | } |
| 25 | |
| 26 | public function register_block() { |
| 27 | |
| 28 | $assets = require(GRW_PLUGIN_PATH . 'build/index.asset.php'); |
| 29 | |
| 30 | wp_register_script( |
| 31 | 'grw-reviews-block-js', |
| 32 | plugins_url('build/index.js', GRW_PLUGIN_FILE), |
| 33 | array('wp-plugins', 'wp-edit-post', 'wp-element'), |
| 34 | $this->assets->version() |
| 35 | ); |
| 36 | |
| 37 | wp_localize_script('grw-reviews-block-js', 'grwBlockData', array( |
| 38 | 'feeds' => $this->feed_deserializer->get_all_feeds_short(), |
| 39 | 'builderUrl' => admin_url('admin.php?page=grw-builder') |
| 40 | )); |
| 41 | |
| 42 | register_block_type(GRW_PLUGIN_PATH, [ |
| 43 | 'editor_script' => 'grw-reviews-block-js', |
| 44 | 'render_callback' => [$this, 'render'], |
| 45 | 'attributes' => ['id' => ['type' => 'string']] |
| 46 | ]); |
| 47 | } |
| 48 | |
| 49 | public function register_category($cats) { |
| 50 | return array_merge($cats, [['slug' => 'grw', 'title' => 'Google Reviews Block']]); |
| 51 | } |
| 52 | |
| 53 | public function render($atts) { |
| 54 | if (isset($atts['id'])) { |
| 55 | |
| 56 | $feed = $this->feed_deserializer->get_feed($atts['id']); |
| 57 | if (!$feed) { |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | $data = $this->core->get_reviews($feed); |
| 62 | return $this->view->render($feed->ID, $data['businesses'], $data['reviews'], $data['options']); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 |