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/CreateTemplate.php +20 -44 2.2.1 → 2.0.2 View file →
@@ -1,14 +1,13 @@
1 1 <?php
2 2
3 3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4 4
5 +use Elementor\Core\Files\Uploads_Manager;
5 6 use Elementor\Plugin;
6 7 use Elementor\TemplateLibrary\Source_Base;
7 8 use RadiusTheme\SB\Helpers\BuilderFns;
8 -use RadiusTheme\SB\Helpers\Cache;
9 9 use RadiusTheme\SB\Helpers\Fns;
10 -use RadiusTheme\SB\Models\TemplateSettings;
11 10 use RadiusTheme\SB\Traits\SingletonTrait;
12 11
13 12 // Do not allow directly accessing this file.
14 13 if ( ! defined( 'ABSPATH' ) ) {
@@ -67,10 +66,9 @@
67 66 *
68 67 * @return void
69 68 */
70 69 public function response() {
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
70 + $page_type = isset( $_POST['page_type'] ) ? sanitize_text_field( wp_unslash( $_POST['page_type'] ) ) : null; //rtsb_tb_template_type - it represent to template type
73 71 $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null;
74 72 $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null;
75 73 $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null;
76 74 $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null;
@@ -79,9 +77,9 @@
79 77 $product_id = isset( $_POST['preview_product_id'] ) ? absint( $_POST['preview_product_id'] ) : null;
80 78
81 79 $url = '#';
82 80
83 - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! $page_type ) {
81 + if ( ! Fns::verify_nonce() || ! $page_type ) {
84 82 $return = [
85 83 'success' => false,
86 84 'post_id' => $page_id,
87 85 ];
@@ -87,41 +85,29 @@
87 85 ];
88 86 wp_send_json( $return );
89 87
90 88 }
91 - if ( ! current_user_can( 'manage_options' ) ) {
92 - $return = [
93 - 'success' => false,
94 - 'post_id' => $page_id,
95 - ];
96 - wp_send_json( $return );
97 - }
98 89
99 - add_filter(
100 - 'pre_option_elementor_unfiltered_files_upload',
101 - function () {
102 - return '1';
103 - },
104 - 99
105 - );
90 + add_filter( 'pre_option_elementor_unfiltered_files_upload', function () {
91 + return '1';
92 + }, 99 );
106 93
107 94 Plugin::$instance->files_manager->clear_cache();
108 95 add_filter( 'rtsb_import_status', '__return_true' );
109 96
110 - $status = sanitize_text_field( wp_unslash( $_REQUEST['status'] ?? '' ) );
97 + $status = $_REQUEST['status'] ?? '';
111 98 $post_args = [ 'timeout' => 120 ];
112 99 $post_args['body'] = [
113 100 'status' => $status,
114 101 'layout_id' => $import_layout,
115 - 'has_pro' => $hasPro,
102 + 'has_pro' => $hasPro
116 103 ];
117 104 $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
118 105
119 - $layoutJson = [];
120 - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) {
121 - $layoutJson = json_decode( $layoutRequest['body'], true );
106 + if ( is_wp_error( $layoutRequest ) ) {
107 + wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] );
122 108 }
123 -
109 + $layoutJson = json_decode( $layoutRequest['body'], true );
124 110 $option_name = BuilderFns::option_name( $page_type );
125 111
126 112 $post_data = [
127 113 'ID' => $page_id,
@@ -152,27 +138,21 @@
152 138 }
153 139
154 140 $edit_by = '';
155 141 if ( $page_id ) {
156 - $edit_by = Fns::page_edit_with( $page_id );
157 - $template_for = sanitize_text_field( wp_unslash( $_POST['product_page_for'] ?? '' ) );
158 - $selected_category = array_unique( isset( $_POST['selected_category'] ) && is_array( $_POST['selected_category'] ) ? array_map( 'sanitize_text_field', $_POST['selected_category'] ) : [] );
159 142 if ( 'product' == $page_type ) {
160 143 update_post_meta( $page_id, BuilderFns::$product_template_meta, $product_id );
161 - update_post_meta( $page_id, '_is_product_page_template_for', $template_for );
162 144 }
163 -
164 - $has_default = TemplateSettings::instance()->get_option( $option_name );
165 - if ( ( 'product' === $page_type && 'all_products' !== $template_for ) || ( 'archive' === $page_type && count( $selected_category ) ) ) {
166 - if ( ! $has_default ) {
167 - TemplateSettings::instance()->set_option( $option_name, '' );
168 - }
169 - } else {
145 + $edit_by = Fns::page_edit_with( $page_id );
146 + $category_archive = array_unique( isset( $_POST['category_archive'] ) && is_array( $_POST['category_archive'] ) ? array_map( 'sanitize_text_field', $_POST['category_archive'] ) : [] );
147 + $the_products = array_unique( isset( $_POST['the_products'] ) && is_array( $_POST['the_products'] ) ? array_map( 'absint', $_POST['the_products'] ) : [] );
148 + if ( ! count( $the_products ) && ! count( $category_archive ) ) {
170 149 if ( 'default_template' === $default_template ) {
171 - TemplateSettings::instance()->set_option( $option_name, $page_id );
150 + update_option( $option_name, $page_id );
172 151 } else {
152 + $has_default = get_option( $option_name );
173 153 if ( ! $has_default ) {
174 - TemplateSettings::instance()->set_option( $option_name, '' );
154 + update_option( $option_name, '' );
175 155 }
176 156 }
177 157 }
178 158
@@ -190,9 +170,9 @@
190 170
191 171 if ( ! empty( $layoutJson['data'] ) ) {
192 172 $data = json_decode( $layoutJson['data'], true );
193 173 $content = $this->process_export_import_content( $data, 'on_import' );
194 - $content = wp_json_encode( $content );
174 + $content = json_encode( $content );
195 175 update_post_meta( $page_id, '_elementor_data', $content );
196 176 update_post_meta( $page_id, '_rtsb_import_id', $import_layout );
197 177 }
198 178 }
@@ -206,13 +186,9 @@
206 186 'new_page' => $new_page,
207 187
208 188 ];
209 189 if ( $edit_by ) {
210 - $return['edit_btn_text'] = sprintf(
211 - /* translators: %s: Edit */
212 - esc_html__( 'Edit with %s', 'shopbuilder' ),
213 - esc_html( $edit_by )
214 - );
190 + $return['edit_btn_text'] = esc_html__( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' );
215 191 }
216 192 wp_send_json( $return );
217 193 wp_die();
218 194 }