| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace RadiusTheme\SB\Controllers\Admin\Ajax; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Plugin; |
| 6 | -use Elementor\TemplateLibrary\Source_Base; | |
| 7 | 6 | use RadiusTheme\SB\Helpers\BuilderFns; |
| 8 | 7 | use RadiusTheme\SB\Helpers\Cache; |
| 9 | 8 | use RadiusTheme\SB\Helpers\Fns; |
| 10 | 9 | use RadiusTheme\SB\Models\TemplateSettings; |
| @@ -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 |
| @@ -68,19 +36,19 @@ | ||
| 68 | 36 | * @return void |
| 69 | 37 | */ |
| 70 | 38 | public function response() { |
| 71 | 39 | 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 | |
| 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. | |
| 73 | 41 | $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null; |
| 74 | 42 | $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null; |
| 75 | 43 | $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null; |
| 76 | 44 | $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null; |
| 77 | 45 | $default_template = isset( $_POST['default_template'] ) ? sanitize_text_field( wp_unslash( $_POST['default_template'] ) ) : null; |
| 78 | - $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 | |
| 79 | 48 | $product_id = isset( $_POST['preview_product_id'] ) ? absint( $_POST['preview_product_id'] ) : null; |
| 49 | + $url = '#'; | |
| 80 | 50 | |
| 81 | - $url = '#'; | |
| 82 | - | |
| 83 | 51 | if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! $page_type ) { |
| 84 | 52 | $return = [ |
| 85 | 53 | 'success' => false, |
| 86 | 54 | 'post_id' => $page_id, |
| @@ -106,22 +74,8 @@ | ||
| 106 | 74 | |
| 107 | 75 | Plugin::$instance->files_manager->clear_cache(); |
| 108 | 76 | add_filter( 'rtsb_import_status', '__return_true' ); |
| 109 | 77 | |
| 110 | - $status = sanitize_text_field( wp_unslash( $_REQUEST['status'] ?? '' ) ); | |
| 111 | - $post_args = [ 'timeout' => 120 ]; | |
| 112 | - $post_args['body'] = [ | |
| 113 | - 'status' => $status, | |
| 114 | - 'layout_id' => $import_layout, | |
| 115 | - 'has_pro' => $hasPro, | |
| 116 | - ]; | |
| 117 | - $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args ); | |
| 118 | - | |
| 119 | - $layoutJson = []; | |
| 120 | - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) { | |
| 121 | - $layoutJson = json_decode( $layoutRequest['body'], true ); | |
| 122 | - } | |
| 123 | - | |
| 124 | 78 | $option_name = BuilderFns::option_name( $page_type ); |
| 125 | 79 | |
| 126 | 80 | $post_data = [ |
| 127 | 81 | 'ID' => $page_id, |
| @@ -154,9 +108,9 @@ | ||
| 154 | 108 | $edit_by = ''; |
| 155 | 109 | if ( $page_id ) { |
| 156 | 110 | $edit_by = Fns::page_edit_with( $page_id ); |
| 157 | 111 | $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'] ) : [] ); | |
| 112 | + $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 | |
| 159 | 113 | if ( 'product' == $page_type ) { |
| 160 | 114 | update_post_meta( $page_id, BuilderFns::$product_template_meta, $product_id ); |
| 161 | 115 | update_post_meta( $page_id, '_is_product_page_template_for', $template_for ); |
| 162 | 116 | } |
| @@ -187,12 +141,10 @@ | ||
| 187 | 141 | ], |
| 188 | 142 | admin_url( 'post.php' ) |
| 189 | 143 | ); |
| 190 | 144 | |
| 191 | - if ( ! empty( $layoutJson['data'] ) ) { | |
| 192 | - $data = json_decode( $layoutJson['data'], true ); | |
| 193 | - $content = $this->process_export_import_content( $data, 'on_import' ); | |
| 194 | - $content = wp_json_encode( $content ); | |
| 145 | + if ( ! empty( $layoutJson ) && is_array( $layoutJson ) ) { | |
| 146 | + $content = wp_slash( wp_json_encode( $layoutJson ) ); | |
| 195 | 147 | update_post_meta( $page_id, '_elementor_data', $content ); |
| 196 | 148 | update_post_meta( $page_id, '_rtsb_import_id', $import_layout ); |
| 197 | 149 | } |
| 198 | 150 | } |