PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.2
ShopBuilder – WooCommerce Builder For Elementor v2.6.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/CreateTemplate.php +34 -23 2.1.7 → 2.6.2 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2
3 3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4 4
5 -use Elementor\Core\Files\Uploads_Manager;
6 5 use Elementor\Plugin;
7 6 use Elementor\TemplateLibrary\Source_Base;
8 7 use RadiusTheme\SB\Helpers\BuilderFns;
8 +use RadiusTheme\SB\Helpers\Cache;
9 9 use RadiusTheme\SB\Helpers\Fns;
10 10 use RadiusTheme\SB\Models\TemplateSettings;
11 11 use RadiusTheme\SB\Traits\SingletonTrait;
12 12
@@ -67,20 +67,20 @@
67 67 *
68 68 * @return void
69 69 */
70 70 public function response() {
71 - $page_type = isset( $_POST['page_type'] ) ? sanitize_text_field( wp_unslash( $_POST['page_type'] ) ) : null; //rtsb_tb_template_type - it represent to template type
71 + Cache::clear_transient_cache();
72 + $page_type = isset( $_POST['page_type'] ) ? sanitize_text_field( wp_unslash( $_POST['page_type'] ) ) : null; // rtsb_tb_template_type - it represent to template type
72 73 $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null;
73 74 $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null;
74 75 $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null;
75 76 $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null;
76 77 $default_template = isset( $_POST['default_template'] ) ? sanitize_text_field( wp_unslash( $_POST['default_template'] ) ) : null;
77 - $import_layout = isset( $_POST['import_default_layout'] ) ? sanitize_text_field( $_POST['import_default_layout'] ) : null;
78 + $import_layout = isset( $_POST['import_default_layout'] ) ? sanitize_text_field( $_POST['import_default_layout'] ) : null; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
78 79 $product_id = isset( $_POST['preview_product_id'] ) ? absint( $_POST['preview_product_id'] ) : null;
79 -
80 80 $url = '#';
81 81
82 - if ( ! Fns::verify_nonce() || ! $page_type ) {
82 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! $page_type ) {
83 83 $return = [
84 84 'success' => false,
85 85 'post_id' => $page_id,
86 86 ];
@@ -86,9 +86,9 @@
86 86 ];
87 87 wp_send_json( $return );
88 88
89 89 }
90 - if ( ! current_user_can( 'manage_options' ) ) {
90 + if ( ! current_user_can( 'manage_options' ) ) {
91 91 $return = [
92 92 'success' => false,
93 93 'post_id' => $page_id,
94 94 ];
@@ -94,21 +94,25 @@
94 94 ];
95 95 wp_send_json( $return );
96 96 }
97 97
98 - add_filter( 'pre_option_elementor_unfiltered_files_upload', function () {
99 - return '1';
100 - }, 99 );
98 + add_filter(
99 + 'pre_option_elementor_unfiltered_files_upload',
100 + function () {
101 + return '1';
102 + },
103 + 99
104 + );
101 105
102 106 Plugin::$instance->files_manager->clear_cache();
103 107 add_filter( 'rtsb_import_status', '__return_true' );
104 108
105 - $status = $_REQUEST['status'] ?? '';
109 + $status = sanitize_text_field( wp_unslash( $_REQUEST['status'] ?? '' ) );
106 110 $post_args = [ 'timeout' => 120 ];
107 111 $post_args['body'] = [
108 112 'status' => $status,
109 113 'layout_id' => $import_layout,
110 - 'has_pro' => $hasPro
114 + 'has_pro' => $hasPro,
111 115 ];
112 116 $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
113 117
114 118 $layoutJson = [];
@@ -147,25 +151,28 @@
147 151 }
148 152
149 153 $edit_by = '';
150 154 if ( $page_id ) {
155 + $edit_by = Fns::page_edit_with( $page_id );
156 + $template_for = sanitize_text_field( wp_unslash( $_POST['product_page_for'] ?? '' ) );
157 + $selected_category = array_unique( isset( $_POST['selected_category'] ) && is_array( $_POST['selected_category'] ) ? array_map( 'sanitize_text_field', $_POST['selected_category'] ) : [] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
151 158 if ( 'product' == $page_type ) {
152 159 update_post_meta( $page_id, BuilderFns::$product_template_meta, $product_id );
160 + update_post_meta( $page_id, '_is_product_page_template_for', $template_for );
153 161 }
154 - $edit_by = Fns::page_edit_with( $page_id );
155 - $category_archive = array_unique( isset( $_POST['category_archive'] ) && is_array( $_POST['category_archive'] ) ? array_map( 'sanitize_text_field', $_POST['category_archive'] ) : [] );
156 - $the_products = array_unique( isset( $_POST['the_products'] ) && is_array( $_POST['the_products'] ) ? array_map( 'absint', $_POST['the_products'] ) : [] );
157 - if ( ! count( $the_products ) && ! count( $category_archive ) ) {
162 +
163 + $has_default = TemplateSettings::instance()->get_option( $option_name );
164 + if ( ( 'product' === $page_type && 'all_products' !== $template_for ) || ( 'archive' === $page_type && count( $selected_category ) ) ) {
165 + if ( ! $has_default ) {
166 + TemplateSettings::instance()->set_option( $option_name, '' );
167 + }
168 + } else {
158 169 if ( 'default_template' === $default_template ) {
159 - // update_option( $option_name, $page_id );
160 170 TemplateSettings::instance()->set_option( $option_name, $page_id );
161 171 } else {
162 - // $has_default = get_option( $option_name );
163 - $has_default = TemplateSettings::instance()->get_option( $option_name );
164 - if ( ! $has_default ) {
165 - // update_option( $option_name, '' );
172 + //if ( ! $has_default ) {
166 173 TemplateSettings::instance()->set_option( $option_name, '' );
167 - }
174 + // }
168 175 }
169 176 }
170 177
171 178 $action = 'edit';
@@ -182,9 +189,9 @@
182 189
183 190 if ( ! empty( $layoutJson['data'] ) ) {
184 191 $data = json_decode( $layoutJson['data'], true );
185 192 $content = $this->process_export_import_content( $data, 'on_import' );
186 - $content = json_encode( $content );
193 + $content = wp_json_encode( $content );
187 194 update_post_meta( $page_id, '_elementor_data', $content );
188 195 update_post_meta( $page_id, '_rtsb_import_id', $import_layout );
189 196 }
190 197 }
@@ -198,9 +205,13 @@
198 205 'new_page' => $new_page,
199 206
200 207 ];
201 208 if ( $edit_by ) {
202 - $return['edit_btn_text'] = esc_html__( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' );
209 + $return['edit_btn_text'] = sprintf(
210 + /* translators: %s: Edit */
211 + esc_html__( 'Edit with %s', 'shopbuilder' ),
212 + esc_html( $edit_by )
213 + );
203 214 }
204 215 wp_send_json( $return );
205 216 wp_die();
206 217 }