| @@ -1,12 +1,12 @@ | ||
| 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 | 6 | use Elementor\TemplateLibrary\Source_Base; |
| 8 | 7 | use RadiusTheme\SB\Helpers\BuilderFns; |
| 8 | +use RadiusTheme\SB\Helpers\Cache; | |
| 9 | 9 | use RadiusTheme\SB\Helpers\Fns; |
| 10 | 10 | use RadiusTheme\SB\Models\TemplateSettings; |
| 11 | 11 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 12 | 12 | |
| @@ -67,9 +67,10 @@ | ||
| 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 | + 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 | |
| 72 | 73 | $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null; |
| 73 | 74 | $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null; |
| 74 | 75 | $hasPro = isset( $_POST['hasPro'] ) ? sanitize_text_field( wp_unslash( $_POST['hasPro'] ) ) : null; |
| 75 | 76 | $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null; |
| @@ -78,9 +79,9 @@ | ||
| 78 | 79 | $product_id = isset( $_POST['preview_product_id'] ) ? absint( $_POST['preview_product_id'] ) : null; |
| 79 | 80 | |
| 80 | 81 | $url = '#'; |
| 81 | 82 | |
| 82 | - if ( ! Fns::verify_nonce() || ! $page_type ) { | |
| 83 | + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! $page_type ) { | |
| 83 | 84 | $return = [ |
| 84 | 85 | 'success' => false, |
| 85 | 86 | 'post_id' => $page_id, |
| 86 | 87 | ]; |
| @@ -86,22 +87,33 @@ | ||
| 86 | 87 | ]; |
| 87 | 88 | wp_send_json( $return ); |
| 88 | 89 | |
| 89 | 90 | } |
| 91 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 92 | + $return = [ | |
| 93 | + 'success' => false, | |
| 94 | + 'post_id' => $page_id, | |
| 95 | + ]; | |
| 96 | + wp_send_json( $return ); | |
| 97 | + } | |
| 90 | 98 | |
| 91 | - add_filter( 'pre_option_elementor_unfiltered_files_upload', function () { | |
| 92 | - return '1'; | |
| 93 | - }, 99 ); | |
| 99 | + add_filter( | |
| 100 | + 'pre_option_elementor_unfiltered_files_upload', | |
| 101 | + function () { | |
| 102 | + return '1'; | |
| 103 | + }, | |
| 104 | + 99 | |
| 105 | + ); | |
| 94 | 106 | |
| 95 | 107 | Plugin::$instance->files_manager->clear_cache(); |
| 96 | 108 | add_filter( 'rtsb_import_status', '__return_true' ); |
| 97 | 109 | |
| 98 | - $status = $_REQUEST['status'] ?? ''; | |
| 110 | + $status = sanitize_text_field( wp_unslash( $_REQUEST['status'] ?? '' ) ); | |
| 99 | 111 | $post_args = [ 'timeout' => 120 ]; |
| 100 | 112 | $post_args['body'] = [ |
| 101 | 113 | 'status' => $status, |
| 102 | 114 | 'layout_id' => $import_layout, |
| 103 | - 'has_pro' => $hasPro | |
| 115 | + 'has_pro' => $hasPro, | |
| 104 | 116 | ]; |
| 105 | 117 | $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args ); |
| 106 | 118 | |
| 107 | 119 | $layoutJson = []; |
| @@ -140,23 +152,26 @@ | ||
| 140 | 152 | } |
| 141 | 153 | |
| 142 | 154 | $edit_by = ''; |
| 143 | 155 | 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'] ) : [] ); | |
| 144 | 159 | if ( 'product' == $page_type ) { |
| 145 | 160 | update_post_meta( $page_id, BuilderFns::$product_template_meta, $product_id ); |
| 161 | + update_post_meta( $page_id, '_is_product_page_template_for', $template_for ); | |
| 146 | 162 | } |
| 147 | - $edit_by = Fns::page_edit_with( $page_id ); | |
| 148 | - $category_archive = array_unique( isset( $_POST['category_archive'] ) && is_array( $_POST['category_archive'] ) ? array_map( 'sanitize_text_field', $_POST['category_archive'] ) : [] ); | |
| 149 | - $the_products = array_unique( isset( $_POST['the_products'] ) && is_array( $_POST['the_products'] ) ? array_map( 'absint', $_POST['the_products'] ) : [] ); | |
| 150 | - if ( ! count( $the_products ) && ! count( $category_archive ) ) { | |
| 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 { | |
| 151 | 170 | if ( 'default_template' === $default_template ) { |
| 152 | - // update_option( $option_name, $page_id ); | |
| 153 | 171 | TemplateSettings::instance()->set_option( $option_name, $page_id ); |
| 154 | 172 | } else { |
| 155 | - // $has_default = get_option( $option_name ); | |
| 156 | - $has_default = TemplateSettings::instance()->get_option( $option_name ); | |
| 157 | 173 | if ( ! $has_default ) { |
| 158 | - // update_option( $option_name, '' ); | |
| 159 | 174 | TemplateSettings::instance()->set_option( $option_name, '' ); |
| 160 | 175 | } |
| 161 | 176 | } |
| 162 | 177 | } |
| @@ -175,9 +190,9 @@ | ||
| 175 | 190 | |
| 176 | 191 | if ( ! empty( $layoutJson['data'] ) ) { |
| 177 | 192 | $data = json_decode( $layoutJson['data'], true ); |
| 178 | 193 | $content = $this->process_export_import_content( $data, 'on_import' ); |
| 179 | - $content = json_encode( $content ); | |
| 194 | + $content = wp_json_encode( $content ); | |
| 180 | 195 | update_post_meta( $page_id, '_elementor_data', $content ); |
| 181 | 196 | update_post_meta( $page_id, '_rtsb_import_id', $import_layout ); |
| 182 | 197 | } |
| 183 | 198 | } |
| @@ -191,9 +206,13 @@ | ||
| 191 | 206 | 'new_page' => $new_page, |
| 192 | 207 | |
| 193 | 208 | ]; |
| 194 | 209 | if ( $edit_by ) { |
| 195 | - $return['edit_btn_text'] = esc_html__( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' ); | |
| 210 | + $return['edit_btn_text'] = sprintf( | |
| 211 | + /* translators: %s: Edit */ | |
| 212 | + esc_html__( 'Edit with %s', 'shopbuilder' ), | |
| 213 | + esc_html( $edit_by ) | |
| 214 | + ); | |
| 196 | 215 | } |
| 197 | 216 | wp_send_json( $return ); |
| 198 | 217 | wp_die(); |
| 199 | 218 | } |