SBR_Elementor_Base.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SmashBalloon\Reviews\Common\Integrations\Elementor; |
| 4 | |
| 5 | use SmashBalloon\Reviews\Vendor\Smashballoon\Framework\Packages\Blocks\RecommendedElementorWidgets; |
| 6 | use SmashBalloon\Reviews\Vendor\Smashballoon\Framework\Packages\Blocks\SB_Feed_Blocks_Registry; |
| 7 | use SmashBalloon\Reviews\Vendor\Smashballoon\Framework\Packages\Blocks\SB_Block_Utils; |
| 8 | use SmashBalloon\Reviews\Vendor\Smashballoon\Framework\Packages\Blocks\SB_Elementor_Editor_Assets; |
| 9 | use SmashBalloon\Reviews\Common\Customizer\DB; |
| 10 | |
| 11 | class SBR_Elementor_Base { |
| 12 | private static $instance; |
| 13 | |
| 14 | public static function register() |
| 15 | { |
| 16 | if (null === self::$instance) { |
| 17 | self::$instance = new SBR_Elementor_Base(); |
| 18 | self::$instance->apply_hooks(); |
| 19 | } |
| 20 | return self::$instance; |
| 21 | } |
| 22 | |
| 23 | private function apply_hooks() |
| 24 | { |
| 25 | add_action('init', array( $this, 'init_elementor_integration' ), 4); |
| 26 | } |
| 27 | |
| 28 | public function init_elementor_integration() |
| 29 | { |
| 30 | if (! did_action('elementor/loaded')) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | $recommended = new RecommendedElementorWidgets('reviews'); |
| 35 | $recommended->setup(); |
| 36 | |
| 37 | $registry = SB_Feed_Blocks_Registry::instance(); |
| 38 | $registry->register_elementor_widget( |
| 39 | array( |
| 40 | 'blockId' => 'reviews', |
| 41 | 'widgetName' => 'sb-reviews-feed', |
| 42 | 'globalVar' => 'sbrElementorData', |
| 43 | 'feedInitFn' => 'sbr_init', |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | add_action('elementor/widgets/register', array( $this, 'register_widgets' )); |
| 48 | add_action('elementor/frontend/after_register_scripts', array( $this, 'enqueue_frontend_assets' )); |
| 49 | add_action('elementor/elements/categories_registered', array( $this, 'add_smashballoon_categories' )); |
| 50 | |
| 51 | add_action( |
| 52 | 'elementor/editor/after_enqueue_scripts', |
| 53 | function () { |
| 54 | SB_Elementor_Editor_Assets::enqueue_shared_elementor_styles(SBRVER); |
| 55 | } |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | public function register_widgets($widgets_manager) |
| 60 | { |
| 61 | $widgets_manager->register(new SBR_Modern_Elementor_Widget()); |
| 62 | } |
| 63 | |
| 64 | public function enqueue_frontend_assets() |
| 65 | { |
| 66 | sbr_scripts_enqueue(); |
| 67 | |
| 68 | // SMASH-1052: skip the per-feed shortcode-location scans on this |
| 69 | // sitewide front-end hook (every Elementor page). The localized |
| 70 | // sbrElementorData.feeds payload only needs id + feed_name; the |
| 71 | // instance_count / location_summary fields are never read here. |
| 72 | $feeds = DB::get_feeds_list(array(), true); |
| 73 | |
| 74 | $data = array( |
| 75 | 'feeds' => ! empty($feeds) ? $feeds : array(), |
| 76 | 'feed_url' => admin_url('admin.php?page=sbr'), |
| 77 | 'is_pro_active' => function_exists('sbr_is_pro') && sbr_is_pro(), |
| 78 | 'nonce' => wp_create_nonce('sbr-blocks'), |
| 79 | ); |
| 80 | |
| 81 | wp_localize_script('sbr_scripts', 'sbrElementorData', $data); |
| 82 | |
| 83 | SB_Feed_Blocks_Registry::instance()->enqueue_elementor_assets(); |
| 84 | } |
| 85 | |
| 86 | public function add_smashballoon_categories($elements_manager) |
| 87 | { |
| 88 | $elements_manager->add_category( |
| 89 | SB_Block_Utils::CATEGORY_SLUG, |
| 90 | array( |
| 91 | 'title' => esc_html__('Smash Balloon', 'reviews-feed'), |
| 92 | 'icon' => 'fa fa-plug', |
| 93 | ) |
| 94 | ); |
| 95 | } |
| 96 | } |
| 97 |