PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.4
ShopBuilder – WooCommerce Builder For Elementor v3.2.4
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 3.2.4, at app/Controllers/Hooks/BuilderHooks.php

200 lines 4.9 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\Traits\SingletonTrait;
15
16 /**
17 * Builder Frontend.
18 */
19 class BuilderHooks {
20 /**
21 * Builder page id.
22 *
23 * @var integer
24 */
25 private $builder_page_id = 0;
26
27 /**
28 * Page Edit By.
29 *
30 * @var string
31 */
32 private $page_edit_with = '';
33
34 /**
35 * Singleton.
36 */
37 use SingletonTrait;
38
39 /**
40 * Final constructor.
41 */
42 private function __construct() {
43 // Template Redirect hook run after the global query.
44 add_action( 'template_redirect', [ $this, 'frontend_init' ] );
45 add_filter( 'rtsb/builder/set/current/page/type', [ $this, 'builder_page_type' ] );
46 add_filter( 'body_class', [ $this, 'product_page_body_class' ] );
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-page';
59 }
60
61 if ( BuilderFns::is_product() ) {
62 $classes[] = 'single-product';
63 }
64
65 if ( BuilderFns::is_shop() ) {
66 $classes[] = 'woocommerce-shop';
67 }
68
69 if ( BuilderFns::is_cart() ) {
70 $classes[] = 'woocommerce-cart';
71 } else {
72 $classes[] = 'woocommerce';
73 }
74
75 if ( BuilderFns::is_checkout() ) {
76 $classes[] = 'woocommerce-checkout ';
77 }
78
79 if ( rtsb()->has_pro() ) {
80 $disable_cart = Fns::is_guest_feature_disabled( 'hide_cart_page', '' );
81 $disable_checkout = Fns::is_guest_feature_disabled( 'hide_checkout_page', '' );
82
83 if ( $disable_cart || $disable_checkout ) {
84 $classes[] = 'rtsb-not-visible';
85 }
86 }
87
88 $hide_notification = Fns::get_option( 'general', 'notification', 'hide_notification', '' );
89
90 if ( 'on' === $hide_notification ) {
91 $classes[] = 'rtsb-notifications-hidden';
92 }
93
94 return $classes;
95 }
96 /**
97 * Undocumented function
98 *
99 * @return void
100 */
101 public function frontend_init() {
102 $this->builder_page_id = BuilderFns::builder_page_id_by_page();
103 $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id );
104 if ( $this->builder_page_id ) {
105 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
106 $this->elementor_frontend();
107 } elseif ( 'gutenberg' === $this->page_edit_with ) {
108 $this->gutenberg_frontend();
109 }
110 }
111 }
112 /**
113 * Appl for gutenberg.
114 *
115 * @return void
116 */
117 public function elementor_frontend() {
118 add_action( 'rtsb/builder/before/header', [ $this, 'el_body_class' ] );
119 add_action( 'rtsb/builder/template/main/content', [ $this, 'elementor_template_main_content' ] );
120 }
121
122 /**
123 * Appl for Elementor.
124 *
125 * @return void
126 */
127 public function gutenberg_frontend() {
128 add_action( 'rtsb/builder/template/main/content', [ $this, 'gutenberg_template_main_content' ] );
129 }
130 /**
131 * Apply For the supported builder page.
132 *
133 * @param string $type string.
134 * @return string
135 */
136 public function builder_page_type( $type ) {
137
138 if ( BuilderFns::is_shop() ) {
139 $type = 'shop';
140 } elseif ( BuilderFns::is_archive() ) {
141 $type = 'archive';
142 } elseif ( BuilderFns::is_product() ) {
143 $type = 'product';
144 } elseif ( BuilderFns::is_checkout() ) {
145 $type = 'checkout';
146 wp_enqueue_script( 'wc-checkout' );
147 } elseif ( BuilderFns::is_cart() ) {
148 $type = 'cart';
149 }
150 wp_enqueue_style( Fns::optimized_handle( 'rtsb-frontend' ) );
151 wp_enqueue_script( Fns::optimized_handle( 'rtsb-public' ) );
152
153 return apply_filters( 'rtsb/builder/set/current/page/type/external', $type );
154 }
155
156 /**
157 * Appl for Elementor.
158 *
159 * @return void
160 */
161 public function el_body_class() {
162 $page_template = get_post_meta( $this->builder_page_id, '_wp_page_template', true );
163 if ( 'elementor_canvas' === $page_template ) {
164 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-canvas' );
165 } elseif ( 'elementor_header_footer' === $page_template ) {
166 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-full-width' );
167 }
168 }
169
170 /**
171 * Apply for Elementor.
172 *
173 * @return void
174 */
175 public function elementor_template_main_content() {
176 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
177 echo BuilderFns::get_builder_content( $this->builder_page_id );
178 }
179 /**
180 * Apply for Gutenberg.
181 *
182 * @return void
183 */
184 public function gutenberg_template_main_content() {
185 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
186 $output = '';
187 $content = get_the_content( null, false, $this->builder_page_id );
188 if ( has_blocks( $content ) ) {
189 $blocks = parse_blocks( $content );
190 foreach ( $blocks as $block ) {
191 $output .= render_block( $block );
192 }
193 } else {
194 $content = apply_filters( 'the_content', $content );
195 $output = str_replace( ']]>', ']]&gt;', $content );
196 }
197 echo wp_kses_post( $output );
198 }
199 }
200