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 +58 -37 3.4.02.6.2 View file →
@@ -2,8 +2,9 @@
2 2
3 3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4 4
5 5 use Elementor\Plugin;
6 +use Elementor\TemplateLibrary\Source_Base;
6 7 use RadiusTheme\SB\Helpers\BuilderFns;
7 8 use RadiusTheme\SB\Helpers\Cache;
8 9 use RadiusTheme\SB\Helpers\Fns;
9 10 use RadiusTheme\SB\Models\TemplateSettings;
@@ -16,9 +17,9 @@
16 17
17 18 /**
18 19 * Default Template Switch.
19 20 */
20 -class CreateTemplate {
21 +class CreateTemplate extends Source_Base {
21 22 /**
22 23 * Singleton Trait.
23 24 */
24 25 use SingletonTrait;
@@ -29,8 +30,39 @@
29 30 private function __construct() {
30 31 add_action( 'wp_ajax_rtsb_builder_create_template', [ $this, 'response' ] );
31 32 }
32 33
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 +
33 65 /**
34 66 * Create template
35 67 *
36 68 * @return void
@@ -36,9 +68,9 @@
36 68 * @return void
37 69 */
38 70 public function response() {
39 71 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 + $page_type = isset( $_POST['page_type'] ) ? sanitize_text_field( wp_unslash( $_POST['page_type'] ) ) : null; // rtsb_tb_template_type - it represent to template type
41 73 $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null;
42 74 $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null;
43 75 $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null;
44 76 $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null;
@@ -43,11 +75,10 @@
43 75 $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null;
44 76 $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null;
45 77 $default_template = isset( $_POST['default_template'] ) ? sanitize_text_field( wp_unslash( $_POST['default_template'] ) ) : null;
46 78 $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
48 79 $product_id = isset( $_POST['preview_product_id'] ) ? absint( $_POST['preview_product_id'] ) : null;
49 - $url = '#';
80 + $url = '#';
50 81
51 82 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! $page_type ) {
52 83 $return = [
53 84 'success' => false,
@@ -63,21 +94,8 @@
63 94 ];
64 95 wp_send_json( $return );
65 96 }
66 97
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 -
80 98 add_filter(
81 99 'pre_option_elementor_unfiltered_files_upload',
82 100 function () {
83 101 return '1';
@@ -87,8 +105,22 @@
87 105
88 106 Plugin::$instance->files_manager->clear_cache();
89 107 add_filter( 'rtsb_import_status', '__return_true' );
90 108
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 +
91 123 $option_name = BuilderFns::option_name( $page_type );
92 124
93 125 $post_data = [
94 126 'ID' => $page_id,
@@ -127,14 +159,9 @@
127 159 update_post_meta( $page_id, BuilderFns::$product_template_meta, $product_id );
128 160 update_post_meta( $page_id, '_is_product_page_template_for', $template_for );
129 161 }
130 162
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 );
163 + $has_default = TemplateSettings::instance()->get_option( $option_name );
137 164 if ( ( 'product' === $page_type && 'all_products' !== $template_for ) || ( 'archive' === $page_type && count( $selected_category ) ) ) {
138 165 if ( ! $has_default ) {
139 166 TemplateSettings::instance()->set_option( $option_name, '' );
140 167 }
@@ -139,21 +166,13 @@
139 166 TemplateSettings::instance()->set_option( $option_name, '' );
140 167 }
141 168 } else {
142 169 if ( 'default_template' === $default_template ) {
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 - }
170 + TemplateSettings::instance()->set_option( $option_name, $page_id );
148 171 } else {
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 - }
155 - }
172 + //if ( ! $has_default ) {
173 + TemplateSettings::instance()->set_option( $option_name, '' );
174 + // }
156 175 }
157 176 }
158 177
159 178 $action = 'edit';
@@ -167,10 +186,12 @@
167 186 ],
168 187 admin_url( 'post.php' )
169 188 );
170 189
171 - if ( ! empty( $layoutJson ) && is_array( $layoutJson ) ) {
172 - $content = wp_slash( wp_json_encode( $layoutJson ) );
190 + if ( ! empty( $layoutJson['data'] ) ) {
191 + $data = json_decode( $layoutJson['data'], true );
192 + $content = $this->process_export_import_content( $data, 'on_import' );
193 + $content = wp_json_encode( $content );
173 194 update_post_meta( $page_id, '_elementor_data', $content );
174 195 update_post_meta( $page_id, '_rtsb_import_id', $import_layout );
175 196 }
176 197 }