PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.2
ShopBuilder – WooCommerce Builder For Elementor v2.0.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
← All changes | app/Controllers/Admin/Ajax/ModalTemplate.php +149 -359 3.4.2 → 2.0.2 View file →
@@ -3,11 +3,9 @@
3 3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4 4
5 5 use Elementor\Plugin;
6 6 use RadiusTheme\SB\Helpers\BuilderFns;
7 -use RadiusTheme\SB\Helpers\Cache;
8 7 use RadiusTheme\SB\Helpers\Fns;
9 -use RadiusTheme\SB\Models\TemplateSettings;
10 8 use RadiusTheme\SB\Traits\SingletonTrait;
11 9 use Elementor\Core\Files\Uploads_Manager;
12 10
13 11 // Do not allow directly accessing this file.
@@ -29,9 +27,9 @@
29 27 */
30 28 private function __construct() {
31 29 add_action( 'wp_ajax_rtsb_builder_modal_template', [ $this, 'response' ] );
32 30 add_action( 'wp_ajax_rtsb_modal_product_search', [ $this, 'product_search' ] );
33 - add_action( 'wp_ajax_rtsb_modal_term_search', [ $this, 'term_search' ] );
31 + add_action( 'wp_ajax_rtsb_modal_category_search', [ $this, 'category_search' ] );
34 32 }
35 33
36 34 /**
37 35 * Popups For Create Template
@@ -37,11 +35,11 @@
37 35 * Popups For Create Template
38 36 *
39 37 * @return void
40 38 */
41 - public function response() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
39 + public function response() {
42 40 $title = '<h2>' . esc_html__( 'Template Settings', 'shopbuilder' ) . '</h2>';
43 - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
41 + if ( ! Fns::verify_nonce() ) {
44 42 $return = [
45 43 'success' => false,
46 44 'title' => $title,
47 45 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
@@ -48,26 +46,8 @@
48 46 ];
49 47 wp_send_json( $return );
50 48 }
51 49
52 - if ( ! current_user_can( 'manage_options' ) ) {
53 - $return = [
54 - 'success' => false,
55 - 'title' => $title,
56 - 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
57 - ];
58 - wp_send_json( $return );
59 - }
60 - if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
61 - $return = [
62 - 'success' => true,
63 - 'title' => $title,
64 - 'content' => '<h2 style="text-align: center;">' . esc_html__( 'Permission Denied. Please Install elementor', 'shopbuilder' ) . '</h2>',
65 - ];
66 -
67 - wp_send_json( $return );
68 - }
69 -
70 50 add_filter( 'option_' . Uploads_Manager::UNFILTERED_FILE_UPLOADS_KEY, '__return_true' );
71 51 Plugin::$instance->files_manager->clear_cache();
72 52
73 53 // user capability check.
@@ -73,23 +53,21 @@
73 53 // user capability check.
74 54 $user = wp_get_current_user();
75 55 $allowed_roles = [ 'editor', 'administrator', 'author' ];
76 56
77 - if ( ! array_intersect( $allowed_roles, Fns::get_current_user_roles() ) ) {
78 - wp_die( esc_html__( 'You don\'t have permission to perform this action', 'shopbuilder' ) );
57 + if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
58 + wp_die( __( 'You don\'t have permission to perform this action', 'rttpg' ) );
79 59 }
80 60
81 61 // Check if the user is not logged in and the provided 'user_id' in the request does not match the currently logged-in user's ID.
82 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.PHP.YodaConditions.NotYoda
83 62 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
84 - wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) );
63 + wp_die( __( 'You don\'t have proper authorization to perform this action', 'rttpg' ) );
85 64 }
86 65
87 - $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : null;
88 - $layout_id = isset( $_REQUEST['layout_id'] ) ? absint( $_REQUEST['layout_id'] ) : null;
66 + $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
67 + $layout_id = isset( $_POST['layout_id'] ) ? absint( $_POST['layout_id'] ) : null;
89 68
90 69 $template_type = null;
91 - $product_page_for = 'all_products';
92 70 $template_default = null;
93 71 $url = '';
94 72 $tmp_title = '';
95 73 $_rtsb_import_id = '';
@@ -95,18 +73,15 @@
95 73 $_rtsb_import_id = '';
96 74 $edit_by = did_action( 'elementor/loaded' ) ? 'elementor' : 'elementor';
97 75 if ( $post_id ) {
98 76 $tmp_title = get_the_title( $post_id );
99 - $template_type = get_post_meta( $post_id, BuilderFns::template_type_meta_key(), true );
100 - $options = BuilderFns::option_name( $template_type );
101 - $template_default = TemplateSettings::instance()->get_option( $options );
77 + $type = get_post_meta( $post_id, BuilderFns::template_type_meta_key() );
78 + $template_type = isset( $type[0] ) ? $type[0] : '';
79 + $template_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) );
102 80 $edit_by = Fns::page_edit_with( $post_id );
103 81 $action = 'edit';
104 - if ( rtsb()->has_pro() ) {
105 - $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
106 - }
107 82
108 - /* This Condition Will remove after release Gutenberg Addons. */
83 + // TODO:: This Condition Will remove after release Gutenberg Addons.
109 84 if ( 'gutenberg' == $edit_by ) {
110 85 $action = 'elementor';
111 86 $edit_by = 'elementor';
112 87 }
@@ -124,8 +99,21 @@
124 99 );
125 100
126 101 $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true );
127 102 }
103 +
104 + $status = $_REQUEST['status'] ?? '';
105 + $post_args = [ 'timeout' => 120 ];
106 + $post_args['body'] = [
107 + 'status' => $status,
108 + ];
109 + $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
110 +
111 + if ( is_wp_error( $layoutRequest ) ) {
112 + wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] );
113 + }
114 + $layoutData = json_decode( $layoutRequest['body'], true );
115 +
128 116 ob_start();
129 117
130 118 ?>
131 119 <form action="<?php echo esc_url( admin_url( 'edit.php?post_type=rtsb_builder' ) ); ?>" autocomplete="off" data-imported-id="<?php echo esc_attr( $_rtsb_import_id ); ?>">
@@ -141,9 +129,10 @@
141 129 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
142 130 value="<?php echo esc_attr( $tmp_title ); ?>"
143 131 autocomplete="off"
144 132 >
145 - <span class="message" style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
133 + <span class="message"
134 + style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
146 135 </div>
147 136 <div class="rtsb-template-type rtsb-tb-field-wraper">
148 137 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
149 138 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
@@ -155,118 +144,37 @@
155 144 <?php } ?>
156 145 </select>
157 146 </div>
158 147
159 - <div class="rtsb-product-page-for rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;" >
160 - <label for="product_page_for">
161 - <?php esc_html_e( 'Product Template For', 'shopbuilder' ); ?>
162 - <?php if ( ! rtsb()->has_pro() ) { ?>
163 - <div class="card-label">
164 - <span class="rtsb-btn-import pro-btn">
165 - <?php echo esc_html( 'PRO' ); ?>
166 - </span>
167 - </div>
168 - <?php } ?>
169 - </label>
170 -
171 - <select class="rtsb-field" id="product_page_for" name="product_page_for">
172 - <?php
173 - $builder_page_types = [
174 - 'all_products' => esc_html__( 'All Products', 'shopbuilder' ),
175 - 'product_cats' => esc_html__( 'Product Categories', 'shopbuilder' ),
176 - 'product_brands' => esc_html__( 'Product Brands', 'shopbuilder' ),
177 - 'product_tags' => esc_html__( 'Product Tags', 'shopbuilder' ),
178 - 'specific_products' => esc_html__( 'Selected Products', 'shopbuilder' ),
179 - ];
180 - // Only expose the brand option when the `product_brand` taxonomy is
181 - // registered (WC 9.4+ native, or a brand plugin). Hides gracefully
182 - // on sites without brand support.
183 - if ( ! taxonomy_exists( 'product_brand' ) ) {
184 - unset( $builder_page_types['product_brands'] );
185 - }
186 - foreach ( $builder_page_types as $key => $value ) {
187 - ?>
188 - <option <?php echo esc_attr( $key === $product_page_for ? 'selected="selected"' : '' ); ?> value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $value ); ?> </option>
189 - <?php } ?>
190 - </select>
191 - </div>
192 -
193 - <?php if ( ! rtsb()->has_pro() ) { ?>
194 - <div class="rtsb-product-page-for rtsb-tb-field-wraper" style="display:none;" >
195 - <label for="product_page_for"> </label>
196 - <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Product Categories, Product Tags, Selected Products</span>
197 - </div>
198 - <?php } ?>
199 -
200 - <!-- Product Page For Categories -->
201 - <div class="rtsb-categories-page-field rtsb-product-page-for-the-categories rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
148 + <div class="rtsb-product-page-field rtsb-tb-field-wraper" style="display:none;">
202 149 <?php
203 - $default_items_link = '';
204 - $default_items = '';
205 - $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
206 - if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
207 - foreach ( $categories_name as $c_name ) {
208 - $cat = get_term_by( 'slug', $c_name, 'product_cat' );
209 - $title_cat = $cat->name;
210 - $link = get_term_link( $cat );
211 - if ( ! is_wp_error( $link ) ) {
212 - $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title_cat . '</a>';
213 - }
214 - $default_items .= '<option selected="selected" value="' . $c_name . '">' . $title_cat . '</option>';
215 - }
150 + $default_items = '';
151 + $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
152 + if ( $product_id ) {
153 + $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>';
216 154 }
217 155 ?>
218 - <label for="rtsb_page_for_the_products">
219 - <?php esc_html_e( 'Select Product Categories', 'shopbuilder' ); ?>
220 - <?php if ( ! rtsb()->has_pro() ) { ?>
221 - <div class="card-label">
222 - <span class="rtsb-btn-import pro-btn">
223 - <?php echo esc_html( 'PRO' ); ?>
224 - </span>
225 - </div>
226 - <?php } ?>
227 - </label>
228 - <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple">
229 - <?php Fns::print_html( $default_items, true ); ?>
156 + <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Product For Preview', 'shopbuilder' ); ?></label>
157 + <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
158 + <?php echo Fns::print_html( $default_items, true ); ?>
230 159 </select>
231 - <p style="margin:0;">Select a Product Category to apply this template. You can select multiple Categories. Keep it blank to apply to all Categories.
232 - <?php
233 - if ( ! empty( $default_items_link ) ) {
234 - ?>
235 - <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Category Archive Pages: ' . $default_items_link ); ?> </span>
236 - <?php
237 - }
238 - ?>
239 - </p>
160 + <p style="margin:0;"> This Product is only used for preview And Elementor edit page. </p>
240 161 </div>
241 162
242 - <?php if ( ! rtsb()->has_pro() ) { ?>
243 - <div class="rtsb-categories-page-field rtsb-product-page-for-the-categories rtsb-tb-field-wraper" style="display:none;">
244 - <label for="product_page_for"> </label>
245 - <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Categories Base Prodcut Page.</span>
246 - </div>
247 - <?php } ?>
248 -
249 - <!-- Product Page for Selected Product Tags-->
250 - <div class="rtsb-product-tags-page-field rtsb-product-page-for-the-tags rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
163 + <div class="rtsb-product-page-field rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
251 164 <?php
252 165 $default_items_link = '';
253 166 $default_items = '';
254 - $tags_name = apply_filters( 'rtsb/template/builder/selected/tags', [], $post_id, $template_type );
255 - if ( ! empty( $tags_name ) && is_array( $tags_name ) ) {
256 - foreach ( $tags_name as $tg_name ) {
257 - $tag = get_term_by( 'slug', $tg_name, 'product_tag' );
258 - $title_tag = $tag->name;
259 - $link = get_term_link( $tag );
260 - if ( ! is_wp_error( $link ) ) {
261 - $default_items_link .= '<a target="_blank" href="' . get_term_link( $tag ) . '">' . $title_tag . '</a>';
262 - }
263 - $default_items .= '<option selected="selected" value="' . $tg_name . '">' . $title_tag . '</option>';
167 + $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
168 + if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
169 + foreach ( $product_ids as $p_id ) {
170 + $title = get_the_title( $p_id );
171 + $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $title . '</a>';
172 + $default_items .= '<option selected="selected" value="' . $p_id . '">' . $title . ' - ( ID ' . $p_id . ' )</option>';
264 173 }
265 174 }
266 175 ?>
267 - <label for="rtsb_page_for_the_products_tags">
268 - <?php esc_html_e( 'Select Product Tags', 'shopbuilder' ); ?>
176 + <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Layout For the Products ', 'shopbuilder' ); ?>
269 177 <?php if ( ! rtsb()->has_pro() ) { ?>
270 178 <div class="card-label">
271 179 <span class="rtsb-btn-import pro-btn">
272 180 <?php echo esc_html( 'PRO' ); ?>
@@ -273,47 +181,34 @@
273 181 </span>
274 182 </div>
275 183 <?php } ?>
276 184 </label>
277 - <select class="rtsb-field" id="rtsb_page_for_the_products_tags" name="rtsb_page_for_the_products_tags" multiple="multiple">
185 + <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple">
278 186 <?php Fns::print_html( $default_items, true ); ?>
279 187 </select>
280 - <p style="margin:0;">Select a Product Tags to apply this template. You can select multiple Tags. Keep it blank to apply to All.
281 - <?php
282 - if ( ! empty( $default_items_link ) ) {
283 - ?>
284 - <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Tags Archive Pages: ' . $default_items_link ); ?> </span>
285 - <?php
286 - }
287 - ?>
188 + <p style="margin:0;"> The Products Display in this layout. <span style="display:inline-flex; gap :10px"> <?php echo ! empty( $default_items_link ) ? 'Visit: ' . $default_items_link : ''; ?> </span>
288 189 </p>
289 190 </div>
290 191
291 -
292 - <!-- Product Page for Selected Product Brands -->
293 - <?php if ( taxonomy_exists( 'product_brand' ) ) : ?>
294 - <div class="rtsb-product-brands-page-field rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
192 + <div class="rtsb-categories-page-field rtsb-page-for-the-categories rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
295 193 <?php
296 194 $default_items_link = '';
297 195 $default_items = '';
298 - $brands_name = apply_filters( 'rtsb/template/builder/selected/brands', [], $post_id, $template_type );
299 - if ( ! empty( $brands_name ) && is_array( $brands_name ) ) {
300 - foreach ( $brands_name as $b_name ) {
301 - $brand = get_term_by( 'slug', $b_name, 'product_brand' );
302 - if ( empty( $brand ) || is_wp_error( $brand ) ) {
303 - continue;
304 - }
305 - $title_brand = $brand->name;
306 - $link = get_term_link( $brand );
196 + $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
197 + if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
198 + foreach ( $categories_name as $c_name ) {
199 + $cat = get_term_by( 'slug', $c_name, 'product_cat' );
200 + $title = $cat->name;
201 + $link = get_term_link( $cat );
307 202 if ( ! is_wp_error( $link ) ) {
308 - $default_items_link .= '<a target="_blank" href="' . esc_url( $link ) . '">' . esc_html( $title_brand ) . '</a>';
203 + $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title . '</a>';
309 204 }
310 - $default_items .= '<option selected="selected" value="' . esc_attr( $b_name ) . '">' . esc_html( $title_brand ) . '</option>';
205 + $default_items .= '<option selected="selected" value="' . $c_name . '">' . $title . '</option>';
311 206 }
312 207 }
313 208 ?>
314 - <label for="rtsb_page_for_the_product_brands">
315 - <?php esc_html_e( 'Select Product Brands', 'shopbuilder' ); ?>
209 + <label for="rtsb_page_for_the_products">
210 + <?php esc_html_e( 'Layout For the Products categories', 'shopbuilder' ); ?>
316 211 <?php if ( ! rtsb()->has_pro() ) { ?>
317 212 <div class="card-label">
318 213 <span class="rtsb-btn-import pro-btn">
319 214 <?php echo esc_html( 'PRO' ); ?>
@@ -320,88 +215,15 @@
320 215 </span>
321 216 </div>
322 217 <?php } ?>
323 218 </label>
324 - <select class="rtsb-field" id="rtsb_page_for_the_product_brands" name="rtsb_page_for_the_product_brands" multiple="multiple">
219 + <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple">
325 220 <?php Fns::print_html( $default_items, true ); ?>
326 221 </select>
327 - <p style="margin:0;">Select a Product Brand to apply this template. You can select multiple Brands. Keep it blank to apply to all.
328 - <?php
329 - if ( ! empty( $default_items_link ) ) {
330 - ?>
331 - <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Brand Archive Pages: ' . $default_items_link ); ?> </span>
332 - <?php
333 - }
334 - ?>
222 + <p style="margin:0;"> The Product Categories Display in this layout. <span style="display:inline-flex; gap :10px"> <?php echo ! empty( $default_items_link ) ? 'Visit: ' . $default_items_link : ''; ?> </span>
335 223 </p>
336 224 </div>
337 225
338 - <?php if ( ! rtsb()->has_pro() ) { ?>
339 - <div class="rtsb-product-brands-page-field rtsb-tb-field-wraper" style="display:none;">
340 - <label for="product_page_for"> </label>
341 - <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Brand Base Product Page.</span>
342 - </div>
343 - <?php } ?>
344 - <?php endif; ?>
345 -
346 - <?php do_action( 'rtsb/builder/modal/extra_fields', $post_id, $template_type, $product_page_for ); ?>
347 -
348 - <!-- Product Page for Selected Product -->
349 - <div class="rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
350 - <?php
351 - $default_items_link = '';
352 - $default_items = '';
353 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
354 - if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
355 - foreach ( $product_ids as $p_id ) {
356 - $p_title = get_the_title( $p_id );
357 - $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $p_title . '</a>';
358 - $default_items .= '<option selected="selected" value="' . $p_id . '">' . $p_title . ' - ( ID ' . $p_id . ' )</option>';
359 - }
360 - }
361 - ?>
362 - <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Select Products ', 'shopbuilder' ); ?>
363 - <?php if ( ! rtsb()->has_pro() ) { ?>
364 - <div class="card-label">
365 - <span class="rtsb-btn-import pro-btn">
366 - <?php echo esc_html( 'PRO' ); ?>
367 - </span>
368 - </div>
369 - <?php } ?>
370 - </label>
371 - <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple">
372 - <?php Fns::print_html( $default_items, true ); ?>
373 - </select>
374 - <p style="margin:0;">Select a Product to apply this template. You can select multiple Products. Keep it blank to apply to all Products.
375 - <?php
376 - if ( ! empty( $default_items_link ) ) {
377 - ?>
378 - <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Product Pages: ' . $default_items_link ); ?> </span>
379 - <?php
380 - }
381 - ?>
382 - </p>
383 - </div>
384 -
385 - <div class="rtsb-product-page-preview-field rtsb-tb-field-wraper" style="display:none;">
386 - <?php
387 - $default_items = '';
388 - $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
389 - if ( $product_id && get_post_status( $product_id ) ) {
390 - $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>';
391 - }
392 - if ( $product_id && ! get_post_status( $product_id ) ) {
393 - delete_post_meta( $post_id, BuilderFns::$product_template_meta );
394 - }
395 - ?>
396 - <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Preview Product', 'shopbuilder' ); ?></label>
397 - <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
398 - <?php Fns::print_html( $default_items, true ); ?>
399 - </select>
400 - <p style="margin:0;">Select a Product for preview and Elementor editing purposes only.</p>
401 - </div>
402 -
403 -
404 226 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
405 227 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
406 228 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
407 229 required>
@@ -412,65 +234,33 @@
412 234 </div>
413 235 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
414 236 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
415 237 <?php
416 - $singleton_types = apply_filters(
417 - 'rtsb/builder/singleton_types',
418 - array_keys( BuilderFns::builder_page_types() )
419 - );
420 - $is_pool_type = $template_type && ! in_array( $template_type, $singleton_types, true );
421 - if ( $post_id && $is_pool_type ) {
422 - $template_default = 'on' === get_post_meta( $post_id, '_rtsb_tb_enabled_in_pool', true ) ? $post_id : 0;
423 - }
424 238 if ( $post_id && 'product' === $template_type ) {
425 - if ( 'specific_products' === $product_page_for ) {
426 - $set_default = BuilderFns::get_specific_product_as_default( $post_id );
427 - if ( $set_default ) {
428 - $template_default = $post_id;
429 - }
430 - if ( ! $set_default && $template_default === $post_id ) {
431 - $template_default = '';
432 - }
433 - } else {
434 - $set_default_option_name = '';
435 - if ( 'product_cats' === $product_page_for ) {
436 - $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
437 - } elseif ( 'product_tags' === $product_page_for ) {
438 - $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
439 - } elseif ( 'product_brands' === $product_page_for ) {
440 - $set_default_option_name = BuilderFns::option_name_product_page_specific_brand_set_default( $post_id );
441 - }
442 - $default_id = ! empty( $set_default_option_name ) && TemplateSettings::instance()->get_option( $set_default_option_name );
443 - if ( $default_id ) {
444 - $template_default = $post_id;
445 - }
239 + $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
240 + $set_default = BuilderFns::get_specific_product_as_default( $post_id );
241 + if ( ! empty( $product_ids ) && $set_default ) {
242 + $template_default = $post_id;
446 243 }
447 244 } elseif ( $post_id && 'archive' === $template_type ) {
448 - $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
245 + $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
449 246 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
450 247 if ( ! empty( $categories_name ) && $set_default ) {
451 248 $template_default = $post_id;
452 - } else {
453 - $option_name = BuilderFns::option_name( $template_type );
454 - $is_set_default = TemplateSettings::instance()->get_option( $option_name );
455 - $set_default = $is_set_default;
456 249 }
457 - if ( ! $set_default && $template_default === $post_id ) {
458 - $template_default = '';
459 - }
460 250 }
461 251
462 - $template_default = apply_filters( 'rtsb/builder/modal/template_default', $template_default, $post_id, $template_type );
463 252 ?>
464 253 <span class="rtsb-switch-wrapper"
465 - title="<?php esc_html_e( 'Switch on to set as active template', 'shopbuilder' ); ?>">
254 + title="<?php esc_html_e( 'Only publish post can set default ', 'shopbuilder' ); ?>">
466 255 <label class="rtsb-switch">
467 256 <input class="rtsb_set_default rtsb-field"
468 257 type="checkbox"
469 258 id="default_template"
259 + class="rtsb-field"
470 260 name="default_template"
471 261 value="default_template"
472 - <?php echo esc_attr( ( $post_id && ( absint( $post_id ) === absint( $template_default ) ) ) ? 'checked' : '' ); ?>
262 + <?php echo esc_attr( ( $post_id && absint( $post_id ) === absint( $template_default ) ) ? 'checked' : '' ); ?>
473 263 >
474 264 <span class="rtsb-slider rtsb-round ">
475 265 <span class="rtsb-loader"></span>
476 266 </span>
@@ -477,29 +267,32 @@
477 267 </label>
478 268 </span>
479 269 </div>
480 270 <!-- TODO: Moday Layout -->
481 - <?php
482 - if ( ! $post_id ) {
483 - if ( defined( 'ELEMENTOR_PATH' ) && class_exists( '\Elementor\Utils' ) ) {
484 - $placeholderImageSrc = \Elementor\Utils::get_placeholder_image_src();
485 - } else {
486 - $placeholderImageSrc = '#';
487 - }
488 - ?>
489 - <div class="set-default-layout-wrapper rtsb-tb-field-wraper" style="opacity: 0" >
490 - <div style="display: flex; justify-content: space-between;">
491 - <label>
492 - <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
493 - <span id="modallabelPrefix"></span>
494 - </label>
495 - <div class="rtsb-tb-button-wrapper">
496 - <a class="btn" href="https://shopbuilderwp.com/themes/" target="_blank" style="opacity: 1; visibility: visible;">View Out Themes</a>
497 - </div>
271 + <?php if ( ! $post_id ) { ?>
272 + <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
273 + <label>
274 + <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
275 + <span id="modallabelPrefix"></span>
276 + </label>
277 + <div class="set-default-layout">
278 + <?php
279 + $default_item = [
280 + 'template_type' => 'default',
281 + 'image_url' => \Elementor\Utils::get_placeholder_image_src(),
282 + 'preview_link' => '',
283 + 'title' => __( 'Blank Template', 'shopbuilder' ),
284 + ];
285 +
286 + $this->get_modal_card_html( $default_item );
287 +
288 + if ( ! empty( $layoutData['layouts'] ) ) {
289 + foreach ( $layoutData['layouts'] as $item ) {
290 + $this->get_modal_card_html( $item );
291 + }
292 + }
293 + ?>
498 294 </div>
499 - <div class="set-default-layout" data-has-pro="<?php echo esc_attr( rtsb()->has_pro() ); ?>" data-rest-url="<?php echo esc_url( rtsb()->BASE_API ); ?>" data-placeholder-image-src="<?php echo esc_url( $placeholderImageSrc ); ?>">
500 - <!-- Layout Will Add Via Ajax-->
501 - </div>
502 295 </div>
503 296 <?php } ?>
504 297 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
505 298 </div>
@@ -514,17 +307,9 @@
514 307 <?php esc_html_e( 'Save', 'shopbuilder' ); ?>
515 308 </button>
516 309 </div>
517 310 <div class="rtsb-tb-button-wrapper rtsb-tb-edit-button-wrapper">
518 - <a href="<?php echo esc_url( $url ); ?>" class="btn">
519 - <?php
520 - printf(
521 - /* translators: %s: Edit */
522 - esc_html__( 'Edit with %s', 'shopbuilder' ),
523 - esc_html( $edit_by )
524 - );
525 - ?>
526 - </a>
311 + <a href="<?php echo esc_url( $url ); ?>" class="btn"> <?php esc_html_e( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' ); ?> </a>
527 312 </div>
528 313 </div>
529 314 <?php
530 315 $footer = ob_get_clean();
@@ -537,20 +322,55 @@
537 322 wp_send_json( $return );
538 323 wp_die();
539 324 }
540 325
326 + public function default_layout_template_html( $key, $is_checked, $builder, $value = [] ) {
327 + $layout_type = $key . ( $builder ? '_' . $builder : null );
328 + ?>
329 + <!-- Elementor -->
330 + <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
331 + data-layout-type='<?php echo esc_attr( $layout_type ); ?>'>
332 + <input <?php echo esc_attr( $is_checked ); ?>
333 + class="rtsb-field" type="radio"
334 + value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
335 + name="import_default_layout"/>
336 +
337 + <span class="checkmark dashicons"></span>
338 + <div class="image-wrapper">
339 + <?php if ( ! empty( $value['image'] ) ) { ?>
340 + <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
341 + <?php } ?>
342 + </div>
343 + <?php if ( ! empty( $value['text_label'] ) ) { ?>
344 + <div class="image-label">
345 + <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
346 + <?php if ( ! empty( $value['live_preview'] ) ) { ?>
347 + <a target="_blank" class="btn-live-preview" href="<?php echo esc_url( $value['live_preview'] ); ?>">
348 + <span class="dashicons dashicons-visibility"></span>
349 + <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
350 + </a>
351 + <?php } ?>
352 + </div>
353 + <?php } ?>
354 + </label>
355 + <?php
356 + }
357 +
541 358 /**
542 359 * Get Modal Card Markup.
543 360 *
544 - * @param array $item Item.
361 + * @param $item
362 + * @param $checked
545 363 *
546 364 * @return void
547 365 */
548 366 public function get_modal_card_html( $item ) {
367 +
549 368 ?>
550 369 <div class="layout-container rtsb-template-item type-<?php echo esc_attr( $item['template_type'] ); ?>"
551 370 data-layout-type='<?php echo esc_attr( $item['template_type'] ); ?>'>
552 371 <input class="rtsb-field" type="hidden" value="<?php echo esc_attr( $item['id'] ?? '' ); ?>" name="import_default_layout"/>
372 +
553 373 <div class="image-wrapper">
554 374 <?php if ( $item['image_url'] ) : ?>
555 375 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
556 376 <?php endif; ?>
@@ -555,10 +375,9 @@
555 375 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
556 376 <?php endif; ?>
557 377
558 378 <?php if ( 'default' != $item['template_type'] && ( ! rtsb()->has_pro() ) ) : ?>
559 - <div class="card-label lllllll">
560 - label
379 + <div class="card-label">
561 380 <span class="rtsb-btn-import <?php echo esc_attr( $item['status'] ?? 'free' ); ?>-btn">
562 381 <?php echo esc_html( $item['status'] ?? 'Free' ); ?>
563 382 </span>
564 383 </div>
@@ -576,12 +395,9 @@
576 395 <?php echo esc_html__( 'Preview', 'shopbuilder' ); ?>
577 396 </a>
578 397
579 398
580 - <?php
581 - // phpcs:ignore WordPress.PHP.YodaConditions.NotYoda
582 - if ( rtsb()->has_pro() || $item['status'] == 'free' ) :
583 - ?>
399 + <?php if ( rtsb()->has_pro() || $item['status'] == 'free' ) : ?>
584 400 <a class="rtsb-btn-import import-btn rtsb-import-layout">
585 401 <svg width="22" height="20" viewBox="0 0 22 20" fill="none" xmlns="http://www.w3.org/2000/svg">
586 402 <path d="M11 12.2295C10.9048 12.2296 10.8106 12.2113 10.7226 12.1757C10.6347 12.14 10.5547 12.0878 10.4874 12.0219C10.4201 11.956 10.3668 11.8778 10.3304 11.7917C10.294 11.7056 10.2753 11.6134 10.2754 11.5202L10.2754 0.912773C10.2754 0.72466 10.3517 0.544251 10.4876 0.411235C10.6235 0.278219 10.8078 0.203491 11 0.203491C11.1922 0.203491 11.3765 0.278219 11.5124 0.411235C11.6483 0.544251 11.7246 0.72466 11.7246 0.912773L11.7246 11.5202C11.7246 11.7083 11.6483 11.8887 11.5124 12.0218C11.3765 12.1548 11.1922 12.2295 11 12.2295Z"
587 403 fill="white"></path>
@@ -633,9 +449,9 @@
633 449 *
634 450 * @return void
635 451 */
636 452 public function product_search() {
637 - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
453 + if ( ! Fns::verify_nonce() ) {
638 454 $return = [
639 455 'success' => false,
640 456 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
641 457 ];
@@ -640,15 +456,8 @@
640 456 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
641 457 ];
642 458 wp_send_json( $return );
643 459 }
644 - if ( ! current_user_can( 'manage_options' ) ) {
645 - $return = [
646 - 'success' => false,
647 - 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
648 - ];
649 - wp_send_json( $return );
650 - }
651 460 global $wpdb;
652 461 $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
653 462 if ( empty( $search ) ) {
654 463 $return = [
@@ -656,33 +465,30 @@
656 465 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ),
657 466 ];
658 467 wp_send_json( $return );
659 468 }
660 - /** @noinspection SqlNoDataSourceInspection */
661 - /** @noinspection SqlResolve */
662 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
663 - $query = $wpdb->prepare(
664 - "SELECT ID, post_title
665 - FROM $wpdb->posts
666 - WHERE post_type = 'product'
667 - AND post_status = 'publish'
668 - AND post_title LIKE %s
469 + $query = $wpdb->prepare(
470 + "SELECT ID, post_title
471 + FROM $wpdb->posts
472 + WHERE post_type = 'product'
473 + AND post_status = 'publish'
474 + AND post_title LIKE %s
669 475 LIMIT %d",
670 476 '%' . $search . '%',
671 477 10
672 478 );
673 - $cache_key = md5( $query );
674 - $_product = wp_cache_get( $cache_key, Cache::group() );
479 +
480 + $_product = wp_cache_get( md5( $query ), 'rtsb-product-query' );
675 481 if ( false === $_product ) {
676 - $_product = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
677 - wp_cache_set( $cache_key, $_product, Cache::group(), 12 * HOUR_IN_SECONDS );
678 - Cache::set_data_cache_key( $cache_key );
482 + $_product = $wpdb->get_results( $query );
483 + wp_cache_set( md5( $query ), $_product, 'rtsb-product-query' );
679 484 }
485 +
680 486 $product_list = [];
681 487 foreach ( $_product as $product ) {
682 488 $product_list['items'][] = [
683 489 'id' => $product->ID,
684 - 'text' => html_entity_decode( $product->post_title, ENT_QUOTES | ENT_HTML5 ) . ' - (ID#' . $product->ID . ')',
490 + 'text' => $product->post_title . ' - ( ID ' . $product->ID . ' )',
685 491 ];
686 492 }
687 493
688 494 wp_send_json_success( $product_list );
@@ -693,11 +499,11 @@
693 499 * Popups For Create Template
694 500 *
695 501 * @return void
696 502 */
697 - public function term_search() {
503 + public function category_search() {
698 504
699 - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
505 + if ( ! Fns::verify_nonce() ) {
700 506 $return = [
701 507 'success' => false,
702 508 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
703 509 ];
@@ -702,33 +508,17 @@
702 508 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
703 509 ];
704 510 wp_send_json( $return );
705 511 }
706 -
707 - if ( ! current_user_can( 'manage_options' ) ) {
708 - $return = [
709 - 'success' => false,
710 - 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
711 - ];
712 - wp_send_json( $return );
713 - }
714 -
715 - $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
716 - $taxonomy = isset( $_REQUEST['taxonomy'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
717 - if ( ! $taxonomy ) {
718 - $return = [
719 - 'success' => false,
720 - 'content' => esc_html__( 'Invalid taxonomy', 'shopbuilder' ),
721 - ];
722 - wp_send_json( $return );
723 - }
724 - $args = [
725 - 'taxonomy' => [ $taxonomy ], // taxonomy name.
512 + $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
513 + $args = [
514 + 'taxonomy' => [ 'product_cat' ], // taxonomy name
726 515 'orderby' => 'name',
727 516 'order' => 'ASC',
728 517 'hide_empty' => false,
729 518 'name__like' => $search,
730 519 ];
520 +
731 521 $terms = get_terms( $args );
732 522 $count = count( $terms );
733 523 $term_list = [];
734 524 if ( $count > 0 ) {
@@ -734,9 +524,9 @@
734 524 if ( $count > 0 ) {
735 525 foreach ( $terms as $term ) {
736 526 $term_list['items'][] = [
737 527 'id' => $term->slug,
738 - 'text' => html_entity_decode( $term->name, ENT_QUOTES | ENT_HTML5 ),
528 + 'text' => $term->name,
739 529 ];
740 530 }
741 531 }
742 532 wp_send_json_success( $term_list );