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

204 lines 5.0 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 // $indexToRemove = array_search( 'woocommerce' , $classes);
72 // if ($indexToRemove !== false) {
73 // unset($classes[$indexToRemove]);
74 // }
75 } else{
76 $classes[] = 'woocommerce';
77 }
78
79 if ( BuilderFns::is_checkout() ) {
80 $classes[] = 'woocommerce-checkout ';
81 }
82
83 if ( rtsb()->has_pro() ) {
84 $disable_cart = Fns::is_guest_feature_disabled( 'hide_cart_page', '' );
85 $disable_checkout = Fns::is_guest_feature_disabled( 'hide_checkout_page', '' );
86
87 if ( $disable_cart || $disable_checkout ) {
88 $classes[] = 'rtsb-not-visible';
89 }
90 }
91
92 $hide_notification = Fns::get_option( 'general', 'notification', 'hide_notification', '' );
93
94 if ( 'on' === $hide_notification ) {
95 $classes[] = 'rtsb-notifications-hidden';
96 }
97
98 return $classes;
99 }
100 /**
101 * Undocumented function
102 *
103 * @return void
104 */
105 public function frontend_init() {
106 $this->builder_page_id = BuilderFns::builder_page_id_by_page();
107 $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id );
108 if ( $this->builder_page_id ) {
109 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
110 $this->elementor_frontend();
111 } else {
112 $this->gutenberg_frontend();
113 }
114 }
115 }
116 /**
117 * Appl for gutenberg.
118 *
119 * @return void
120 */
121 public function elementor_frontend() {
122 add_action( 'rtsb/builder/before/header', [ $this, 'el_body_class' ] );
123 add_action( 'rtsb/builder/template/main/content', [ $this, 'elementor_template_main_content' ] );
124 }
125
126 /**
127 * Appl for Elementor.
128 *
129 * @return void
130 */
131 public function gutenberg_frontend() {
132 add_action( 'rtsb/builder/template/main/content', [ $this, 'gutenberg_template_main_content' ] );
133 }
134 /**
135 * Apply For the supported builder page.
136 *
137 * @param string $type string.
138 * @return string
139 */
140 public function builder_page_type( $type ) {
141
142 if ( BuilderFns::is_shop() ) {
143 $type = 'shop';
144 } elseif ( BuilderFns::is_archive() ) {
145 $type = 'archive';
146 } elseif ( BuilderFns::is_product() ) {
147 $type = 'product';
148 } elseif ( BuilderFns::is_checkout() ) {
149 $type = 'checkout';
150 wp_enqueue_script( 'wc-checkout' );
151 } elseif ( BuilderFns::is_cart() ) {
152 $type = 'cart';
153 }
154 wp_enqueue_style( 'rtsb-frontend' );
155 wp_enqueue_script( 'rtsb-public' );
156
157 return apply_filters( 'rtsb/builder/set/current/page/type/external', $type );
158 }
159
160 /**
161 * Appl for Elementor.
162 *
163 * @return void
164 */
165 public function el_body_class() {
166 $page_template = get_post_meta( $this->builder_page_id, '_wp_page_template', true );
167 if ( 'elementor_canvas' === $page_template ) {
168 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-canvas' );
169 } elseif ( 'elementor_header_footer' === $page_template ) {
170 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-full-width' );
171 }
172 }
173
174 /**
175 * Apply for Elementor.
176 *
177 * @return void
178 */
179 public function elementor_template_main_content() {
180 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
181 echo BuilderFns::get_builder_content( $this->builder_page_id );
182 }
183 /**
184 * Apply for Gutenberg.
185 *
186 * @return void
187 */
188 public function gutenberg_template_main_content() {
189 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
190 $output = '';
191 $content = get_the_content( null, false, $this->builder_page_id );
192 if ( has_blocks( $content ) ) {
193 $blocks = parse_blocks( $content );
194 foreach ( $blocks as $block ) {
195 $output .= render_block( $block );
196 }
197 } else {
198 $content = apply_filters( 'the_content', $content );
199 $output = str_replace( ']]>', ']]&gt;', $content );
200 }
201 echo wp_kses_post( $output );
202 }
203 }
204