PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.2
ShopBuilder – WooCommerce Builder For Elementor v2.1.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / Hooks / BuilderHooks.php

BuilderHooks.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.2, at app/Controllers/Hooks/BuilderHooks.php

195 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main initialization class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Controllers\Hooks;
9
10 defined( 'ABSPATH' ) || exit();
11
12 use RadiusTheme\SB\Helpers\Fns;
13 use RadiusTheme\SB\Helpers\BuilderFns;
14 use RadiusTheme\SB\Models\GeneralList;
15 use RadiusTheme\SB\Traits\SingletonTrait;
16 use RadiusTheme\SBPRO\Helpers\FnsPro;
17
18 /**
19 * Builder Frontend.
20 */
21 class BuilderHooks {
22 /**
23 * Builder page id.
24 *
25 * @var integer
26 */
27 private $builder_page_id = 0;
28 /**
29 * Page Edit By.
30 *
31 * @var string
32 */
33 private $page_edit_with = '';
34 /**
35 * Singleton.
36 */
37 use SingletonTrait;
38 /**
39 * Final constructor.
40 */
41 private function __construct() {
42 // Template Redirect hook run after the global query.
43 add_action( 'template_redirect', [ $this, 'frontend_init' ] );
44 add_filter( 'rtsb/builder/set/current/page/type', [ $this, 'builder_page_type' ] );
45 add_filter( 'body_class', [ $this, 'product_page_body_class' ] );
46 add_filter('rtsb/multi/step/checkout/widget',[__CLASS__,'multi_step_checkout_widget_builder_hooks']);
47 }
48
49 /**
50 * Builder page Body class.
51 *
52 * @param array $classes class list.
53 * @return array.
54 */
55 public function product_page_body_class( $classes ) {
56 $classes[] = 'rtsb-shopbuilder-plugin rtsb_theme_' . rtsb()->current_theme;
57 if ( Fns::is_woocommerce() || BuilderFns::is_builder_preview() ) {
58 $classes[] = 'woocommerce';
59 $classes[] = 'woocommerce-page';
60 }
61
62 if ( BuilderFns::is_product() ) {
63 $classes[] = 'single-product';
64 }
65
66 if ( BuilderFns::is_shop() ) {
67 $classes[] = 'woocommerce-shop';
68 }
69
70 if ( BuilderFns::is_cart() ) {
71 $classes[] = 'woocommerce-cart';
72 }
73
74 if ( BuilderFns::is_checkout() ) {
75 $classes[] = 'woocommerce-checkout ';
76 }
77
78 $hide_notification = Fns::get_option( 'general', 'notification', 'hide_notification', '' );
79
80 if ( 'on' === $hide_notification ) {
81 $classes[] = 'rtsb-notifications-hidden';
82 }
83
84 return $classes;
85 }
86 /**
87 * Undocumented function
88 *
89 * @return void
90 */
91 public function frontend_init() {
92 $this->builder_page_id = BuilderFns::builder_page_id_by_page();
93 $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id );
94 if ( $this->builder_page_id ) {
95 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
96 $this->elementor_frontend();
97 } else {
98 $this->gutenberg_frontend();
99 }
100 }
101 }
102 /**
103 * Appl for gutenberg.
104 *
105 * @return void
106 */
107 public function elementor_frontend() {
108 add_action( 'rtsb/builder/before/header', [ $this, 'el_body_class' ] );
109 add_action( 'rtsb/builder/template/main/content', [ $this, 'elementor_template_main_content' ] );
110 }
111
112 /**
113 * Appl for Elementor.
114 *
115 * @return void
116 */
117 public function gutenberg_frontend() {
118 add_action( 'rtsb/builder/template/main/content', [ $this, 'gutenberg_template_main_content' ] );
119 }
120 /**
121 * Apply For the supported builder page.
122 *
123 * @param string $type string.
124 * @return string
125 */
126 public function builder_page_type( $type ) {
127
128 if ( BuilderFns::is_shop() ) {
129 $type = 'shop';
130 } elseif ( BuilderFns::is_archive() ) {
131 $type = 'archive';
132 } elseif ( BuilderFns::is_product() ) {
133 $type = 'product';
134 } elseif ( BuilderFns::is_checkout() ) {
135 $type = 'checkout';
136 wp_enqueue_script( 'wc-checkout' );
137 } elseif ( BuilderFns::is_cart() ) {
138 $type = 'cart';
139 }
140 wp_enqueue_style( 'rtsb-frontend' );
141 wp_enqueue_script( 'rtsb-public' );
142
143 return apply_filters( 'rtsb/builder/set/current/page/type/external', $type );
144 }
145
146 /**
147 * Appl for Elementor.
148 *
149 * @return void
150 */
151 public function el_body_class() {
152 $page_template = get_post_meta( $this->builder_page_id, '_wp_page_template', true );
153 if ( 'elementor_canvas' === $page_template ) {
154 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-canvas' );
155 } elseif ( 'elementor_header_footer' === $page_template ) {
156 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-full-width' );
157 }
158 }
159
160 /**
161 * Apply for Elementor.
162 *
163 * @return void
164 */
165 public function elementor_template_main_content() {
166 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
167 echo BuilderFns::get_builder_content( $this->builder_page_id );
168 }
169 /**
170 * Apply for Gutenberg.
171 *
172 * @return void
173 */
174 public function gutenberg_template_main_content() {
175 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
176 $output = '';
177 $content = get_the_content( null, false, $this->builder_page_id );
178 if ( has_blocks( $content ) ) {
179 $blocks = parse_blocks( $content );
180 foreach ( $blocks as $block ) {
181 $output .= render_block( $block );
182 }
183 } else {
184 $content = apply_filters( 'the_content', $content );
185 $output = str_replace( ']]>', ']]&gt;', $content );
186 }
187 echo wp_kses_post( $output );
188 }
189
190 public static function multi_step_checkout_widget_builder_hooks() {
191
192 return ! FnsPro::checkout_page_has_multi_step_widget();
193 }
194 }
195