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

181 lines 4.3 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 * Page Edit By.
28 *
29 * @var string
30 */
31 private $page_edit_with = '';
32 /**
33 * Singleton.
34 */
35 use SingletonTrait;
36 /**
37 * Final constructor.
38 */
39 private function __construct() {
40 // Template Redirect hook run after the global query.
41 add_action( 'template_redirect', [ $this, 'frontend_init' ] );
42 add_filter( 'rtsb/builder/set/current/page/type', [ $this, 'builder_page_type' ] );
43 add_filter( 'body_class', [ $this, 'product_page_body_class' ] );
44 }
45
46 /**
47 * Builder page Body class.
48 *
49 * @param array $classes class list.
50 * @return array.
51 */
52 public function product_page_body_class( $classes ) {
53 $classes[] = 'rtsb-shopbuilder-plugin rtsb_theme_' . rtsb()->current_theme;
54 if ( Fns::is_woocommerce() || BuilderFns::is_builder_preview() ) {
55 $classes[] = 'woocommerce';
56 $classes[] = 'woocommerce-page';
57 }
58
59 if ( BuilderFns::is_product() ) {
60 $classes[] = 'single-product';
61 }
62
63 if ( BuilderFns::is_shop() ) {
64 $classes[] = 'woocommerce-shop';
65 }
66
67 if ( BuilderFns::is_cart() ) {
68 $classes[] = 'woocommerce-cart';
69 }
70
71 if ( BuilderFns::is_checkout() ) {
72 $classes[] = 'woocommerce-checkout ';
73 }
74
75 return $classes;
76 }
77 /**
78 * Undocumented function
79 *
80 * @return void
81 */
82 public function frontend_init() {
83 $this->builder_page_id = BuilderFns::builder_page_id_by_page();
84 $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id );
85 if ( $this->builder_page_id ) {
86 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
87 $this->elementor_frontend();
88 } else {
89 $this->gutenberg_frontend();
90 }
91 }
92 }
93 /**
94 * Appl for gutenberg.
95 *
96 * @return void
97 */
98 public function elementor_frontend() {
99 add_action( 'rtsb/builder/before/header', [ $this, 'el_body_class' ] );
100 add_action( 'rtsb/builder/template/main/content', [ $this, 'elementor_template_main_content' ] );
101 }
102
103 /**
104 * Appl for Elementor.
105 *
106 * @return void
107 */
108 public function gutenberg_frontend() {
109 add_action( 'rtsb/builder/template/main/content', [ $this, 'gutenberg_template_main_content' ] );
110 }
111 /**
112 * Apply For the supported builder page.
113 *
114 * @param string $type string.
115 * @return string
116 */
117 public function builder_page_type( $type ) {
118
119 if ( BuilderFns::is_shop() ) {
120 $type = 'shop';
121 } elseif ( BuilderFns::is_archive() ) {
122 $type = 'archive';
123 } elseif ( BuilderFns::is_product() ) {
124 $type = 'product';
125 } elseif ( BuilderFns::is_checkout() ) {
126 $type = 'checkout';
127 wp_enqueue_script( 'wc-checkout' );
128 } elseif ( BuilderFns::is_cart() ) {
129 $type = 'cart';
130 }
131 wp_enqueue_style( 'rtsb-frontend' );
132 wp_enqueue_script( 'rtsb-public' );
133
134 return apply_filters( 'rtsb/builder/set/current/page/type/external', $type );
135 }
136
137 /**
138 * Appl for Elementor.
139 *
140 * @return void
141 */
142 public function el_body_class() {
143 $page_template = get_post_meta( $this->builder_page_id, '_wp_page_template', true );
144 if ( 'elementor_canvas' === $page_template ) {
145 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-canvas' );
146 } elseif ( 'elementor_header_footer' === $page_template ) {
147 \Elementor\Plugin::$instance->frontend->add_body_class( 'elementor-template-full-width' );
148 }
149 }
150
151 /**
152 * Apply for Elementor.
153 *
154 * @return void
155 */
156 public function elementor_template_main_content() {
157 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
158 echo BuilderFns::get_builder_content( $this->builder_page_id );
159 }
160 /**
161 * Apply for Gutenberg.
162 *
163 * @return void
164 */
165 public function gutenberg_template_main_content() {
166 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
167 $output = '';
168 $content = get_the_content( null, false, $this->builder_page_id );
169 if ( has_blocks( $content ) ) {
170 $blocks = parse_blocks( $content );
171 foreach ( $blocks as $block ) {
172 $output .= render_block( $block );
173 }
174 } else {
175 $content = apply_filters( 'the_content', $content );
176 $output = str_replace( ']]>', ']]&gt;', $content );
177 }
178 echo wp_kses_post( $output );
179 }
180 }
181