PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.4.0
ShopBuilder – WooCommerce Builder For Elementor v3.4.0
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 +49 -64 2.1.123.4.0 View file →
@@ -1,12 +1,11 @@
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 -use Elementor\TemplateLibrary\Source_Base;
8 6 use RadiusTheme\SB\Helpers\BuilderFns;
7 +use RadiusTheme\SB\Helpers\Cache;
9 8 use RadiusTheme\SB\Helpers\Fns;
10 9 use RadiusTheme\SB\Models\TemplateSettings;
11 10 use RadiusTheme\SB\Traits\SingletonTrait;
12 11
@@ -17,9 +16,9 @@
17 16
18 17 /**
19 18 * Default Template Switch.
20 19 */
21 -class CreateTemplate extends Source_Base {
20 +class CreateTemplate {
22 21 /**
23 22 * Singleton Trait.
24 23 */
25 24 use SingletonTrait;
@@ -30,39 +29,8 @@
30 29 private function __construct() {
31 30 add_action( 'wp_ajax_rtsb_builder_create_template', [ $this, 'response' ] );
32 31 }
33 32
34 -
35 - public function get_id() {
36 - }
37 -
38 - public function get_title() {
39 - }
40 -
41 - public function register_data() {
42 - }
43 -
44 - public function get_items( $args = [] ) {
45 - }
46 -
47 - public function get_item( $template_id ) {
48 - }
49 -
50 - public function get_data( array $args ) {
51 - }
52 -
53 - public function delete_template( $template_id ) {
54 - }
55 -
56 - public function save_item( $template_data ) {
57 - }
58 -
59 - public function update_item( $new_data ) {
60 - }
61 -
62 - public function export_template( $template_id ) {
63 - }
64 -
65 33 /**
66 34 * Create template
67 35 *
68 36 * @return void
@@ -67,19 +35,20 @@
67 35 *
68 36 * @return void
69 37 */
70 38 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
39 + Cache::clear_transient_cache();
40 + $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 41 $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null;
73 42 $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null;
74 43 $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null;
75 44 $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null;
76 45 $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;
46 + $import_layout = isset( $_POST['import_default_layout'] ) ? sanitize_text_field( $_POST['import_default_layout'] ) : null; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
47 + $layoutJson = isset( $_POST['demoData'] ) ? $_POST['demoData'] : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
78 48 $product_id = isset( $_POST['preview_product_id'] ) ? absint( $_POST['preview_product_id'] ) : null;
49 + $url = '#';
79 50
80 - $url = '#';
81 -
82 51 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! $page_type ) {
83 52 $return = [
84 53 'success' => false,
85 54 'post_id' => $page_id,
@@ -94,8 +63,21 @@
94 63 ];
95 64 wp_send_json( $return );
96 65 }
97 66
67 + // Nonce verified above.
68 + $can_save = apply_filters( 'rtsb/builder/create_template/can_save', true, $page_type, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
69 +
70 + if ( true !== $can_save ) {
71 + wp_send_json(
72 + [
73 + 'success' => false,
74 + 'post_id' => $page_id,
75 + 'message' => is_string( $can_save ) ? $can_save : esc_html__( 'Template cannot be saved.', 'shopbuilder' ),
76 + ]
77 + );
78 + }
79 +
98 80 add_filter(
99 81 'pre_option_elementor_unfiltered_files_upload',
100 82 function () {
101 83 return '1';
@@ -105,22 +87,8 @@
105 87
106 88 Plugin::$instance->files_manager->clear_cache();
107 89 add_filter( 'rtsb_import_status', '__return_true' );
108 90
109 - $status = sanitize_text_field( wp_unslash( $_REQUEST['status'] ?? '' ) );
110 - $post_args = [ 'timeout' => 120 ];
111 - $post_args['body'] = [
112 - 'status' => $status,
113 - 'layout_id' => $import_layout,
114 - 'has_pro' => $hasPro,
115 - ];
116 - $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
117 -
118 - $layoutJson = [];
119 - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) {
120 - $layoutJson = json_decode( $layoutRequest['body'], true );
121 - }
122 -
123 91 $option_name = BuilderFns::option_name( $page_type );
124 92
125 93 $post_data = [
126 94 'ID' => $page_id,
@@ -151,21 +119,40 @@
151 119 }
152 120
153 121 $edit_by = '';
154 122 if ( $page_id ) {
123 + $edit_by = Fns::page_edit_with( $page_id );
124 + $template_for = sanitize_text_field( wp_unslash( $_POST['product_page_for'] ?? '' ) );
125 + $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
155 126 if ( 'product' == $page_type ) {
156 127 update_post_meta( $page_id, BuilderFns::$product_template_meta, $product_id );
128 + update_post_meta( $page_id, '_is_product_page_template_for', $template_for );
157 129 }
158 - $edit_by = Fns::page_edit_with( $page_id );
159 - $category_archive = array_unique( isset( $_POST['category_archive'] ) && is_array( $_POST['category_archive'] ) ? array_map( 'sanitize_text_field', $_POST['category_archive'] ) : [] );
160 - $the_products = array_unique( isset( $_POST['the_products'] ) && is_array( $_POST['the_products'] ) ? array_map( 'absint', $_POST['the_products'] ) : [] );
161 - if ( ! count( $the_products ) && ! count( $category_archive ) ) {
130 +
131 + $has_default = TemplateSettings::instance()->get_option( $option_name );
132 + $singleton_types = apply_filters(
133 + 'rtsb/builder/singleton_types',
134 + array_keys( BuilderFns::builder_page_types() )
135 + );
136 + $is_pool_type = ! in_array( $page_type, $singleton_types, true );
137 + if ( ( 'product' === $page_type && 'all_products' !== $template_for ) || ( 'archive' === $page_type && count( $selected_category ) ) ) {
138 + if ( ! $has_default ) {
139 + TemplateSettings::instance()->set_option( $option_name, '' );
140 + }
141 + } else {
162 142 if ( 'default_template' === $default_template ) {
163 - TemplateSettings::instance()->set_option( $option_name, $page_id );
143 + if ( $is_pool_type ) {
144 + update_post_meta( $page_id, '_rtsb_tb_enabled_in_pool', 'on' );
145 + } else {
146 + TemplateSettings::instance()->set_option( $option_name, $page_id );
147 + }
164 148 } else {
165 - $has_default = TemplateSettings::instance()->get_option( $option_name );
166 - if ( ! $has_default ) {
167 - TemplateSettings::instance()->set_option( $option_name, '' );
149 + if ( $is_pool_type ) {
150 + delete_post_meta( $page_id, '_rtsb_tb_enabled_in_pool' );
151 + } else {
152 + if ( ! $has_default ) {
153 + TemplateSettings::instance()->set_option( $option_name, '' );
154 + }
168 155 }
169 156 }
170 157 }
171 158
@@ -180,12 +167,10 @@
180 167 ],
181 168 admin_url( 'post.php' )
182 169 );
183 170
184 - if ( ! empty( $layoutJson['data'] ) ) {
185 - $data = json_decode( $layoutJson['data'], true );
186 - $content = $this->process_export_import_content( $data, 'on_import' );
187 - $content = wp_json_encode( $content );
171 + if ( ! empty( $layoutJson ) && is_array( $layoutJson ) ) {
172 + $content = wp_slash( wp_json_encode( $layoutJson ) );
188 173 update_post_meta( $page_id, '_elementor_data', $content );
189 174 update_post_meta( $page_id, '_rtsb_import_id', $import_layout );
190 175 }
191 176 }