PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.1
ShopBuilder – WooCommerce Builder For Elementor v1.0.1
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 1.0.1, 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_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 return $classes;
72 }
73 /**
74 * Undocumented function
75 *
76 * @return void
77 */
78 public function frontend_init() {
79 $this->builder_page_id = BuilderFns::builder_page_id_by_page();
80 $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id );
81 if ( $this->builder_page_id ) {
82 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
83 $this->elementor_frontend();
84 } else {
85 $this->gutenberg_frontend();
86 }
87 }
88 }
89 /**
90 * Appl for gutenberg.
91 *
92 * @return void
93 */
94 public function elementor_frontend() {
95 add_action( 'rtsb_builder_before_header', [ $this, 'el_body_class' ] );
96 add_action( 'rtsb_builder_template_main_content', [ $this, 'elementor_template_main_content' ] );
97 }
98
99 /**
100 * Appl for Elementor.
101 *
102 * @return void
103 */
104 public function gutenberg_frontend() {
105 add_action( 'rtsb_builder_template_main_content', [ $this, 'gutenberg_template_main_content' ] );
106 }
107 /**
108 * Apply For the supported builder page.
109 *
110 * @param string $type string.
111 * @return string
112 */
113 public function builder_page_type( $type ) {
114 wp_enqueue_style( 'rtsb-frontend' );
115 wp_enqueue_script( 'rtsb-public' );
116
117 if ( is_shop() ) {
118 $type = 'shop';
119 } elseif ( is_product() ) {
120 $type = 'product';
121 } elseif ( is_product_taxonomy() ) {
122 $type = 'archive';
123 } elseif ( is_checkout() ) {
124 $type = 'checkout';
125 } elseif ( is_cart() ) {
126 $type = 'cart';
127 }
128 /*
129 PRo
130 elseif ( is_account_page() ) {
131 $type = 'myaccount';
132 }
133 */
134 return $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 * Appl 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