| @@ -67,9 +67,9 @@ | ||
| 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 | + $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 | 72 | $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null; |
| 73 | 73 | $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null; |
| 74 | 74 | $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null; |
| 75 | 75 | $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null; |
| @@ -78,9 +78,9 @@ | ||
| 78 | 78 | $product_id = isset( $_POST['preview_product_id'] ) ? absint( $_POST['preview_product_id'] ) : null; |
| 79 | 79 | |
| 80 | 80 | $url = '#'; |
| 81 | 81 | |
| 82 | - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! $page_type ) { | |
| 82 | + if ( ! Fns::verify_nonce() || ! $page_type ) { | |
| 83 | 83 | $return = [ |
| 84 | 84 | 'success' => false, |
| 85 | 85 | 'post_id' => $page_id, |
| 86 | 86 | ]; |
| @@ -86,41 +86,29 @@ | ||
| 86 | 86 | ]; |
| 87 | 87 | wp_send_json( $return ); |
| 88 | 88 | |
| 89 | 89 | } |
| 90 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 91 | - $return = [ | |
| 92 | - 'success' => false, | |
| 93 | - 'post_id' => $page_id, | |
| 94 | - ]; | |
| 95 | - wp_send_json( $return ); | |
| 96 | - } | |
| 97 | 90 | |
| 98 | - add_filter( | |
| 99 | - 'pre_option_elementor_unfiltered_files_upload', | |
| 100 | - function () { | |
| 101 | - return '1'; | |
| 102 | - }, | |
| 103 | - 99 | |
| 104 | - ); | |
| 91 | + add_filter( 'pre_option_elementor_unfiltered_files_upload', function () { | |
| 92 | + return '1'; | |
| 93 | + }, 99 ); | |
| 105 | 94 | |
| 106 | 95 | Plugin::$instance->files_manager->clear_cache(); |
| 107 | 96 | add_filter( 'rtsb_import_status', '__return_true' ); |
| 108 | 97 | |
| 109 | - $status = sanitize_text_field( wp_unslash( $_REQUEST['status'] ?? '' ) ); | |
| 98 | + $status = $_REQUEST['status'] ?? ''; | |
| 110 | 99 | $post_args = [ 'timeout' => 120 ]; |
| 111 | 100 | $post_args['body'] = [ |
| 112 | 101 | 'status' => $status, |
| 113 | 102 | 'layout_id' => $import_layout, |
| 114 | - 'has_pro' => $hasPro, | |
| 103 | + 'has_pro' => $hasPro | |
| 115 | 104 | ]; |
| 116 | 105 | $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args ); |
| 117 | 106 | |
| 118 | - $layoutJson = []; | |
| 119 | - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) { | |
| 120 | - $layoutJson = json_decode( $layoutRequest['body'], true ); | |
| 107 | + if ( is_wp_error( $layoutRequest ) ) { | |
| 108 | + wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] ); | |
| 121 | 109 | } |
| 122 | - | |
| 110 | + $layoutJson = json_decode( $layoutRequest['body'], true ); | |
| 123 | 111 | $option_name = BuilderFns::option_name( $page_type ); |
| 124 | 112 | |
| 125 | 113 | $post_data = [ |
| 126 | 114 | 'ID' => $page_id, |
| @@ -159,12 +147,15 @@ | ||
| 159 | 147 | $category_archive = array_unique( isset( $_POST['category_archive'] ) && is_array( $_POST['category_archive'] ) ? array_map( 'sanitize_text_field', $_POST['category_archive'] ) : [] ); |
| 160 | 148 | $the_products = array_unique( isset( $_POST['the_products'] ) && is_array( $_POST['the_products'] ) ? array_map( 'absint', $_POST['the_products'] ) : [] ); |
| 161 | 149 | if ( ! count( $the_products ) && ! count( $category_archive ) ) { |
| 162 | 150 | if ( 'default_template' === $default_template ) { |
| 151 | + // update_option( $option_name, $page_id ); | |
| 163 | 152 | TemplateSettings::instance()->set_option( $option_name, $page_id ); |
| 164 | 153 | } else { |
| 154 | + // $has_default = get_option( $option_name ); | |
| 165 | 155 | $has_default = TemplateSettings::instance()->get_option( $option_name ); |
| 166 | 156 | if ( ! $has_default ) { |
| 157 | + // update_option( $option_name, '' ); | |
| 167 | 158 | TemplateSettings::instance()->set_option( $option_name, '' ); |
| 168 | 159 | } |
| 169 | 160 | } |
| 170 | 161 | } |
| @@ -183,9 +174,9 @@ | ||
| 183 | 174 | |
| 184 | 175 | if ( ! empty( $layoutJson['data'] ) ) { |
| 185 | 176 | $data = json_decode( $layoutJson['data'], true ); |
| 186 | 177 | $content = $this->process_export_import_content( $data, 'on_import' ); |
| 187 | - $content = wp_json_encode( $content ); | |
| 178 | + $content = json_encode( $content ); | |
| 188 | 179 | update_post_meta( $page_id, '_elementor_data', $content ); |
| 189 | 180 | update_post_meta( $page_id, '_rtsb_import_id', $import_layout ); |
| 190 | 181 | } |
| 191 | 182 | } |
| @@ -199,13 +190,9 @@ | ||
| 199 | 190 | 'new_page' => $new_page, |
| 200 | 191 | |
| 201 | 192 | ]; |
| 202 | 193 | if ( $edit_by ) { |
| 203 | - $return['edit_btn_text'] = sprintf( | |
| 204 | - /* translators: %s: Edit */ | |
| 205 | - esc_html__( 'Edit with %s', 'shopbuilder' ), | |
| 206 | - esc_html( $edit_by ) | |
| 207 | - ); | |
| 194 | + $return['edit_btn_text'] = esc_html__( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' ); | |
| 208 | 195 | } |
| 209 | 196 | wp_send_json( $return ); |
| 210 | 197 | wp_die(); |
| 211 | 198 | } |