| @@ -3,9 +3,11 @@ | ||
| 3 | 3 | namespace RadiusTheme\SB\Controllers\Admin\Ajax; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Plugin; |
| 6 | 6 | use RadiusTheme\SB\Helpers\BuilderFns; |
| 7 | +use RadiusTheme\SB\Helpers\Cache; | |
| 7 | 8 | use RadiusTheme\SB\Helpers\Fns; |
| 9 | +use RadiusTheme\SB\Models\TemplateSettings; | |
| 8 | 10 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 9 | 11 | use Elementor\Core\Files\Uploads_Manager; |
| 10 | 12 | |
| 11 | 13 | // Do not allow directly accessing this file. |
| @@ -27,9 +29,9 @@ | ||
| 27 | 29 | */ |
| 28 | 30 | private function __construct() { |
| 29 | 31 | add_action( 'wp_ajax_rtsb_builder_modal_template', [ $this, 'response' ] ); |
| 30 | 32 | add_action( 'wp_ajax_rtsb_modal_product_search', [ $this, 'product_search' ] ); |
| 31 | - add_action( 'wp_ajax_rtsb_modal_category_search', [ $this, 'category_search' ] ); | |
| 33 | + add_action( 'wp_ajax_rtsb_modal_term_search', [ $this, 'term_search' ] ); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | /** |
| 35 | 37 | * Popups For Create Template |
| @@ -37,9 +39,9 @@ | ||
| 37 | 39 | * @return void |
| 38 | 40 | */ |
| 39 | 41 | public function response() { |
| 40 | 42 | $title = '<h2>' . esc_html__( 'Template Settings', 'shopbuilder' ) . '</h2>'; |
| 41 | - if ( ! Fns::verify_nonce() ) { | |
| 43 | + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) { | |
| 42 | 44 | $return = [ |
| 43 | 45 | 'success' => false, |
| 44 | 46 | 'title' => $title, |
| 45 | 47 | 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ), |
| @@ -46,8 +48,26 @@ | ||
| 46 | 48 | ]; |
| 47 | 49 | wp_send_json( $return ); |
| 48 | 50 | } |
| 49 | 51 | |
| 52 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 53 | + $return = [ | |
| 54 | + 'success' => false, | |
| 55 | + 'title' => $title, | |
| 56 | + 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ), | |
| 57 | + ]; | |
| 58 | + wp_send_json( $return ); | |
| 59 | + } | |
| 60 | + if ( ! defined( 'ELEMENTOR_VERSION' ) ) { | |
| 61 | + $return = [ | |
| 62 | + 'success' => true, | |
| 63 | + 'title' => $title, | |
| 64 | + 'content' => '<h2 style="text-align: center;">' . esc_html__( 'Permission Denied. Please Install elementor', 'shopbuilder' ) . '</h2>', | |
| 65 | + ]; | |
| 66 | + | |
| 67 | + wp_send_json( $return ); | |
| 68 | + } | |
| 69 | + | |
| 50 | 70 | add_filter( 'option_' . Uploads_Manager::UNFILTERED_FILE_UPLOADS_KEY, '__return_true' ); |
| 51 | 71 | Plugin::$instance->files_manager->clear_cache(); |
| 52 | 72 | |
| 53 | 73 | // user capability check. |
| @@ -53,15 +73,16 @@ | ||
| 53 | 73 | // user capability check. |
| 54 | 74 | $user = wp_get_current_user(); |
| 55 | 75 | $allowed_roles = [ 'editor', 'administrator', 'author' ]; |
| 56 | 76 | |
| 57 | - if ( ! array_intersect( $allowed_roles, $user->roles ) ) { | |
| 58 | - wp_die( __( 'You don\'t have permission to perform this action', 'shopbuilder' ) ); | |
| 77 | + if ( ! array_intersect( $allowed_roles, Fns::get_current_user_roles() ) ) { | |
| 78 | + wp_die( esc_html__( 'You don\'t have permission to perform this action', 'shopbuilder' ) ); | |
| 59 | 79 | } |
| 60 | 80 | |
| 61 | 81 | // Check if the user is not logged in and the provided 'user_id' in the request does not match the currently logged-in user's ID. |
| 82 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 62 | 83 | if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) { |
| 63 | - wp_die( __( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) ); | |
| 84 | + wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) ); | |
| 64 | 85 | } |
| 65 | 86 | |
| 66 | 87 | $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null; |
| 67 | 88 | $layout_id = isset( $_POST['layout_id'] ) ? absint( $_POST['layout_id'] ) : null; |
| @@ -66,8 +87,9 @@ | ||
| 66 | 87 | $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null; |
| 67 | 88 | $layout_id = isset( $_POST['layout_id'] ) ? absint( $_POST['layout_id'] ) : null; |
| 68 | 89 | |
| 69 | 90 | $template_type = null; |
| 91 | + $product_page_for = 'all_products'; | |
| 70 | 92 | $template_default = null; |
| 71 | 93 | $url = ''; |
| 72 | 94 | $tmp_title = ''; |
| 73 | 95 | $_rtsb_import_id = ''; |
| @@ -73,13 +95,16 @@ | ||
| 73 | 95 | $_rtsb_import_id = ''; |
| 74 | 96 | $edit_by = did_action( 'elementor/loaded' ) ? 'elementor' : 'elementor'; |
| 75 | 97 | if ( $post_id ) { |
| 76 | 98 | $tmp_title = get_the_title( $post_id ); |
| 77 | - $type = get_post_meta( $post_id, BuilderFns::template_type_meta_key() ); | |
| 78 | - $template_type = isset( $type[0] ) ? $type[0] : ''; | |
| 79 | - $template_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) ); | |
| 99 | + $template_type = get_post_meta( $post_id, BuilderFns::template_type_meta_key(), true ); | |
| 100 | + $options = BuilderFns::option_name( $template_type ); | |
| 101 | + $template_default = TemplateSettings::instance()->get_option( $options ); | |
| 80 | 102 | $edit_by = Fns::page_edit_with( $post_id ); |
| 81 | 103 | $action = 'edit'; |
| 104 | + if ( rtsb()->has_pro() ) { | |
| 105 | + $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true ); | |
| 106 | + } | |
| 82 | 107 | |
| 83 | 108 | // TODO:: This Condition Will remove after release Gutenberg Addons. |
| 84 | 109 | if ( 'gutenberg' == $edit_by ) { |
| 85 | 110 | $action = 'elementor'; |
| @@ -100,8 +125,9 @@ | ||
| 100 | 125 | |
| 101 | 126 | $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true ); |
| 102 | 127 | } |
| 103 | 128 | |
| 129 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 104 | 130 | $status = $_REQUEST['status'] ?? ''; |
| 105 | 131 | $post_args = [ 'timeout' => 120 ]; |
| 106 | 132 | $post_args['body'] = [ |
| 107 | 133 | 'status' => $status, |
| @@ -106,13 +132,12 @@ | ||
| 106 | 132 | $post_args['body'] = [ |
| 107 | 133 | 'status' => $status, |
| 108 | 134 | ]; |
| 109 | 135 | $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args ); |
| 110 | - | |
| 111 | - if ( is_wp_error( $layoutRequest ) ) { | |
| 112 | - wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] ); | |
| 136 | + $layoutData = []; | |
| 137 | + if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) { | |
| 138 | + $layoutData = json_decode( $layoutRequest['body'], true ); | |
| 113 | 139 | } |
| 114 | - $layoutData = json_decode( $layoutRequest['body'], true ); | |
| 115 | 140 | |
| 116 | 141 | ob_start(); |
| 117 | 142 | |
| 118 | 143 | ?> |
| @@ -129,10 +154,9 @@ | ||
| 129 | 154 | placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>" |
| 130 | 155 | value="<?php echo esc_attr( $tmp_title ); ?>" |
| 131 | 156 | autocomplete="off" |
| 132 | 157 | > |
| 133 | - <span class="message" | |
| 134 | - style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span> | |
| 158 | + <span class="message" style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span> | |
| 135 | 159 | </div> |
| 136 | 160 | <div class="rtsb-template-type rtsb-tb-field-wraper"> |
| 137 | 161 | <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label> |
| 138 | 162 | <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type"> |
| @@ -144,37 +168,111 @@ | ||
| 144 | 168 | <?php } ?> |
| 145 | 169 | </select> |
| 146 | 170 | </div> |
| 147 | 171 | |
| 148 | - <div class="rtsb-product-page-field rtsb-tb-field-wraper" style="display:none;"> | |
| 172 | + <div class="rtsb-product-page-for rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;" > | |
| 173 | + <label for="product_page_for"> | |
| 174 | + <?php esc_html_e( 'Product Template For', 'shopbuilder' ); ?> | |
| 175 | + <?php if ( ! rtsb()->has_pro() ) { ?> | |
| 176 | + <div class="card-label"> | |
| 177 | + <span class="rtsb-btn-import pro-btn"> | |
| 178 | + <?php echo esc_html( 'PRO' ); ?> | |
| 179 | + </span> | |
| 180 | + </div> | |
| 181 | + <?php } ?> | |
| 182 | + </label> | |
| 183 | + | |
| 184 | + <select class="rtsb-field" id="product_page_for" name="product_page_for"> | |
| 185 | + <?php | |
| 186 | + $builder_page_types = [ | |
| 187 | + 'all_products' => esc_html__( 'All Products', 'shopbuilder' ), | |
| 188 | + 'product_cats' => esc_html__( 'Product Categories', 'shopbuilder' ), | |
| 189 | + 'product_tags' => esc_html__( 'Product Tags', 'shopbuilder' ), | |
| 190 | + 'specific_products' => esc_html__( 'Selected Products', 'shopbuilder' ), | |
| 191 | + ]; | |
| 192 | + foreach ( $builder_page_types as $key => $value ) { | |
| 193 | + ?> | |
| 194 | + <option <?php echo esc_attr( $key === $product_page_for ? 'selected="selected"' : '' ); ?> value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $value ); ?> </option> | |
| 195 | + <?php } ?> | |
| 196 | + </select> | |
| 197 | + </div> | |
| 198 | + | |
| 199 | + <?php if ( ! rtsb()->has_pro() ) { ?> | |
| 200 | + <div class="rtsb-product-page-for rtsb-tb-field-wraper" style="display:none;" > | |
| 201 | + <label for="product_page_for"> </label> | |
| 202 | + <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Product Categories, Product Tags, Selected Products</span> | |
| 203 | + </div> | |
| 204 | + <?php } ?> | |
| 205 | + | |
| 206 | + <!-- Product Page For Categories --> | |
| 207 | + <div class="rtsb-categories-page-field rtsb-product-page-for-the-categories rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;"> | |
| 149 | 208 | <?php |
| 150 | - $default_items = ''; | |
| 151 | - $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true ); | |
| 152 | - if ( $product_id ) { | |
| 153 | - $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>'; | |
| 209 | + $default_items_link = ''; | |
| 210 | + $default_items = ''; | |
| 211 | + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type ); | |
| 212 | + if ( ! empty( $categories_name ) && is_array( $categories_name ) ) { | |
| 213 | + foreach ( $categories_name as $c_name ) { | |
| 214 | + $cat = get_term_by( 'slug', $c_name, 'product_cat' ); | |
| 215 | + $title_cat = $cat->name; | |
| 216 | + $link = get_term_link( $cat ); | |
| 217 | + if ( ! is_wp_error( $link ) ) { | |
| 218 | + $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title_cat . '</a>'; | |
| 219 | + } | |
| 220 | + $default_items .= '<option selected="selected" value="' . $c_name . '">' . $title_cat . '</option>'; | |
| 221 | + } | |
| 154 | 222 | } |
| 155 | 223 | ?> |
| 156 | - <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Product For Preview', 'shopbuilder' ); ?></label> | |
| 157 | - <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview"> | |
| 158 | - <?php echo Fns::print_html( $default_items, true ); ?> | |
| 224 | + <label for="rtsb_page_for_the_products"> | |
| 225 | + <?php esc_html_e( 'Select Product Categories', 'shopbuilder' ); ?> | |
| 226 | + <?php if ( ! rtsb()->has_pro() ) { ?> | |
| 227 | + <div class="card-label"> | |
| 228 | + <span class="rtsb-btn-import pro-btn"> | |
| 229 | + <?php echo esc_html( 'PRO' ); ?> | |
| 230 | + </span> | |
| 231 | + </div> | |
| 232 | + <?php } ?> | |
| 233 | + </label> | |
| 234 | + <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple"> | |
| 235 | + <?php Fns::print_html( $default_items, true ); ?> | |
| 159 | 236 | </select> |
| 160 | - <p style="margin:0;"> This Product is only used for preview And Elementor edit page. </p> | |
| 237 | + <p style="margin:0;">Select a Product Category to apply this template. You can select multiple Categories. Keep it blank to apply to all Categories. | |
| 238 | + <?php | |
| 239 | + if ( ! empty( $default_items_link ) ) { | |
| 240 | + ?> | |
| 241 | + <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Category Archive Pages: ' . $default_items_link ); ?> </span> | |
| 242 | + <?php | |
| 243 | + } | |
| 244 | + ?> | |
| 245 | + </p> | |
| 161 | 246 | </div> |
| 162 | 247 | |
| 163 | - <div class="rtsb-product-page-field rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;"> | |
| 248 | + <?php if ( ! rtsb()->has_pro() ) { ?> | |
| 249 | + <div class="rtsb-categories-page-field rtsb-product-page-for-the-categories rtsb-tb-field-wraper" style="display:none;"> | |
| 250 | + <label for="product_page_for"> </label> | |
| 251 | + <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Categories Base Prodcut Page.</span> | |
| 252 | + </div> | |
| 253 | + <?php } ?> | |
| 254 | + | |
| 255 | + <!-- Product Page for Selected Product Tags--> | |
| 256 | + <div class="rtsb-product-tags-page-field rtsb-product-page-for-the-tags rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;"> | |
| 164 | 257 | <?php |
| 165 | 258 | $default_items_link = ''; |
| 166 | 259 | $default_items = ''; |
| 167 | - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id ); | |
| 168 | - if ( ! empty( $product_ids ) && is_array( $product_ids ) ) { | |
| 169 | - foreach ( $product_ids as $p_id ) { | |
| 170 | - $title = get_the_title( $p_id ); | |
| 171 | - $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $title . '</a>'; | |
| 172 | - $default_items .= '<option selected="selected" value="' . $p_id . '">' . $title . ' - ( ID ' . $p_id . ' )</option>'; | |
| 260 | + $tags_name = apply_filters( 'rtsb/template/builder/selected/tags', [], $post_id, $template_type ); | |
| 261 | + if ( ! empty( $tags_name ) && is_array( $tags_name ) ) { | |
| 262 | + foreach ( $tags_name as $tg_name ) { | |
| 263 | + $tag = get_term_by( 'slug', $tg_name, 'product_tag' ); | |
| 264 | + $title_tag = $tag->name; | |
| 265 | + $link = get_term_link( $tag ); | |
| 266 | + if ( ! is_wp_error( $link ) ) { | |
| 267 | + $default_items_link .= '<a target="_blank" href="' . get_term_link( $tag ) . '">' . $title_tag . '</a>'; | |
| 268 | + } | |
| 269 | + $default_items .= '<option selected="selected" value="' . $tg_name . '">' . $title_tag . '</option>'; | |
| 173 | 270 | } |
| 174 | 271 | } |
| 175 | 272 | ?> |
| 176 | - <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Layout For the Products ', 'shopbuilder' ); ?> | |
| 273 | + <label for="rtsb_page_for_the_products_tags"> | |
| 274 | + <?php esc_html_e( 'Select Product Tags', 'shopbuilder' ); ?> | |
| 177 | 275 | <?php if ( ! rtsb()->has_pro() ) { ?> |
| 178 | 276 | <div class="card-label"> |
| 179 | 277 | <span class="rtsb-btn-import pro-btn"> |
| 180 | 278 | <?php echo esc_html( 'PRO' ); ?> |
| @@ -181,34 +279,38 @@ | ||
| 181 | 279 | </span> |
| 182 | 280 | </div> |
| 183 | 281 | <?php } ?> |
| 184 | 282 | </label> |
| 185 | - <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple"> | |
| 283 | + <select class="rtsb-field" id="rtsb_page_for_the_products_tags" name="rtsb_page_for_the_products_tags" multiple="multiple"> | |
| 186 | 284 | <?php Fns::print_html( $default_items, true ); ?> |
| 187 | 285 | </select> |
| 188 | - <p style="margin:0;"> The Products Display in this layout. <span style="display:inline-flex; gap :10px"> <?php echo ! empty( $default_items_link ) ? 'Visit: ' . $default_items_link : ''; ?> </span> | |
| 286 | + <p style="margin:0;">Select a Product Tags to apply this template. You can select multiple Tags. Keep it blank to apply to All. | |
| 287 | + <?php | |
| 288 | + if ( ! empty( $default_items_link ) ) { | |
| 289 | + ?> | |
| 290 | + <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Tags Archive Pages: ' . $default_items_link ); ?> </span> | |
| 291 | + <?php | |
| 292 | + } | |
| 293 | + ?> | |
| 189 | 294 | </p> |
| 190 | 295 | </div> |
| 191 | 296 | |
| 192 | - <div class="rtsb-categories-page-field rtsb-page-for-the-categories rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;"> | |
| 297 | + | |
| 298 | + <!-- Product Page for Selected Product --> | |
| 299 | + <div class="rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;"> | |
| 193 | 300 | <?php |
| 194 | 301 | $default_items_link = ''; |
| 195 | 302 | $default_items = ''; |
| 196 | - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id ); | |
| 197 | - if ( ! empty( $categories_name ) && is_array( $categories_name ) ) { | |
| 198 | - foreach ( $categories_name as $c_name ) { | |
| 199 | - $cat = get_term_by( 'slug', $c_name, 'product_cat' ); | |
| 200 | - $title = $cat->name; | |
| 201 | - $link = get_term_link( $cat ); | |
| 202 | - if ( ! is_wp_error( $link ) ) { | |
| 203 | - $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title . '</a>'; | |
| 204 | - } | |
| 205 | - $default_items .= '<option selected="selected" value="' . $c_name . '">' . $title . '</option>'; | |
| 303 | + $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id ); | |
| 304 | + if ( ! empty( $product_ids ) && is_array( $product_ids ) ) { | |
| 305 | + foreach ( $product_ids as $p_id ) { | |
| 306 | + $p_title = get_the_title( $p_id ); | |
| 307 | + $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $p_title . '</a>'; | |
| 308 | + $default_items .= '<option selected="selected" value="' . $p_id . '">' . $p_title . ' - ( ID ' . $p_id . ' )</option>'; | |
| 206 | 309 | } |
| 207 | 310 | } |
| 208 | 311 | ?> |
| 209 | - <label for="rtsb_page_for_the_products"> | |
| 210 | - <?php esc_html_e( 'Layout For the Products categories', 'shopbuilder' ); ?> | |
| 312 | + <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Select Products ', 'shopbuilder' ); ?> | |
| 211 | 313 | <?php if ( ! rtsb()->has_pro() ) { ?> |
| 212 | 314 | <div class="card-label"> |
| 213 | 315 | <span class="rtsb-btn-import pro-btn"> |
| 214 | 316 | <?php echo esc_html( 'PRO' ); ?> |
| @@ -215,15 +317,41 @@ | ||
| 215 | 317 | </span> |
| 216 | 318 | </div> |
| 217 | 319 | <?php } ?> |
| 218 | 320 | </label> |
| 219 | - <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple"> | |
| 321 | + <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple"> | |
| 220 | 322 | <?php Fns::print_html( $default_items, true ); ?> |
| 221 | 323 | </select> |
| 222 | - <p style="margin:0;"> The Product Categories Display in this layout. <span style="display:inline-flex; gap :10px"> <?php echo ! empty( $default_items_link ) ? 'Visit: ' . $default_items_link : ''; ?> </span> | |
| 324 | + <p style="margin:0;">Select a Product to apply this template. You can select multiple Products. Keep it blank to apply to all Products. | |
| 325 | + <?php | |
| 326 | + if ( ! empty( $default_items_link ) ) { | |
| 327 | + ?> | |
| 328 | + <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Product Pages: ' . $default_items_link ); ?> </span> | |
| 329 | + <?php | |
| 330 | + } | |
| 331 | + ?> | |
| 223 | 332 | </p> |
| 224 | 333 | </div> |
| 225 | 334 | |
| 335 | + <div class="rtsb-product-page-preview-field rtsb-tb-field-wraper" style="display:none;"> | |
| 336 | + <?php | |
| 337 | + $default_items = ''; | |
| 338 | + $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true ); | |
| 339 | + if ( $product_id && get_post_status( $product_id ) ) { | |
| 340 | + $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>'; | |
| 341 | + } | |
| 342 | + if ( $product_id && ! get_post_status( $product_id ) ) { | |
| 343 | + delete_post_meta( $post_id, BuilderFns::$product_template_meta ); | |
| 344 | + } | |
| 345 | + ?> | |
| 346 | + <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Preview Product', 'shopbuilder' ); ?></label> | |
| 347 | + <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview"> | |
| 348 | + <?php Fns::print_html( $default_items, true ); ?> | |
| 349 | + </select> | |
| 350 | + <p style="margin:0;">Select a Product for preview and Elementor editing purposes only.</p> | |
| 351 | + </div> | |
| 352 | + | |
| 353 | + | |
| 226 | 354 | <div class="rtsb-template-edit-with rtsb-tb-field-wraper"> |
| 227 | 355 | <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label> |
| 228 | 356 | <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with" |
| 229 | 357 | required> |
| @@ -235,15 +363,27 @@ | ||
| 235 | 363 | <div class="rtsb-template-setdefaults rtsb-tb-field-wraper"> |
| 236 | 364 | <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label> |
| 237 | 365 | <?php |
| 238 | 366 | if ( $post_id && 'product' === $template_type ) { |
| 239 | - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id ); | |
| 240 | - $set_default = BuilderFns::get_specific_product_as_default( $post_id ); | |
| 241 | - if ( ! empty( $product_ids ) && $set_default ) { | |
| 242 | - $template_default = $post_id; | |
| 367 | + if ( 'specific_products' === $product_page_for ) { | |
| 368 | + $set_default = BuilderFns::get_specific_product_as_default( $post_id ); | |
| 369 | + if ( $set_default ) { | |
| 370 | + $template_default = $post_id; | |
| 371 | + } | |
| 372 | + } else { | |
| 373 | + $set_default_option_name = ''; | |
| 374 | + if ( 'product_cats' === $product_page_for ) { | |
| 375 | + $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id ); | |
| 376 | + } elseif ( 'product_tags' === $product_page_for ) { | |
| 377 | + $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id ); | |
| 378 | + } | |
| 379 | + $default_id = ! empty( $set_default_option_name ) && TemplateSettings::instance()->get_option( $set_default_option_name ); | |
| 380 | + if ( $default_id ) { | |
| 381 | + $template_default = $post_id; | |
| 382 | + } | |
| 243 | 383 | } |
| 244 | 384 | } elseif ( $post_id && 'archive' === $template_type ) { |
| 245 | - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id ); | |
| 385 | + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type ); | |
| 246 | 386 | $set_default = BuilderFns::get_specific_category_as_default( $post_id ); |
| 247 | 387 | if ( ! empty( $categories_name ) && $set_default ) { |
| 248 | 388 | $template_default = $post_id; |
| 249 | 389 | } |
| @@ -250,17 +390,16 @@ | ||
| 250 | 390 | } |
| 251 | 391 | |
| 252 | 392 | ?> |
| 253 | 393 | <span class="rtsb-switch-wrapper" |
| 254 | - title="<?php esc_html_e( 'Only publish post can set default ', 'shopbuilder' ); ?>"> | |
| 394 | + title="<?php esc_html_e( 'Switch on to set as active template', 'shopbuilder' ); ?>"> | |
| 255 | 395 | <label class="rtsb-switch"> |
| 256 | 396 | <input class="rtsb_set_default rtsb-field" |
| 257 | 397 | type="checkbox" |
| 258 | 398 | id="default_template" |
| 259 | - class="rtsb-field" | |
| 260 | 399 | name="default_template" |
| 261 | 400 | value="default_template" |
| 262 | - <?php echo esc_attr( ( $post_id && absint( $post_id ) === absint( $template_default ) ) ? 'checked' : '' ); ?> | |
| 401 | + <?php echo esc_attr( ( $post_id && ( absint( $post_id ) === absint( $template_default ) ) ) ? 'checked' : '' ); ?> | |
| 263 | 402 | > |
| 264 | 403 | <span class="rtsb-slider rtsb-round "> |
| 265 | 404 | <span class="rtsb-loader"></span> |
| 266 | 405 | </span> |
| @@ -307,9 +446,17 @@ | ||
| 307 | 446 | <?php esc_html_e( 'Save', 'shopbuilder' ); ?> |
| 308 | 447 | </button> |
| 309 | 448 | </div> |
| 310 | 449 | <div class="rtsb-tb-button-wrapper rtsb-tb-edit-button-wrapper"> |
| 311 | - <a href="<?php echo esc_url( $url ); ?>" class="btn"> <?php esc_html_e( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' ); ?> </a> | |
| 450 | + <a href="<?php echo esc_url( $url ); ?>" class="btn"> | |
| 451 | + <?php | |
| 452 | + printf( | |
| 453 | + /* translators: %s: Edit */ | |
| 454 | + esc_html__( 'Edit with %s', 'shopbuilder' ), | |
| 455 | + esc_html( $edit_by ) | |
| 456 | + ); | |
| 457 | + ?> | |
| 458 | + </a> | |
| 312 | 459 | </div> |
| 313 | 460 | </div> |
| 314 | 461 | <?php |
| 315 | 462 | $footer = ob_get_clean(); |
| @@ -449,9 +596,9 @@ | ||
| 449 | 596 | * |
| 450 | 597 | * @return void |
| 451 | 598 | */ |
| 452 | 599 | public function product_search() { |
| 453 | - if ( ! Fns::verify_nonce() ) { | |
| 600 | + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) { | |
| 454 | 601 | $return = [ |
| 455 | 602 | 'success' => false, |
| 456 | 603 | 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ), |
| 457 | 604 | ]; |
| @@ -456,8 +603,15 @@ | ||
| 456 | 603 | 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ), |
| 457 | 604 | ]; |
| 458 | 605 | wp_send_json( $return ); |
| 459 | 606 | } |
| 607 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 608 | + $return = [ | |
| 609 | + 'success' => false, | |
| 610 | + 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ), | |
| 611 | + ]; | |
| 612 | + wp_send_json( $return ); | |
| 613 | + } | |
| 460 | 614 | global $wpdb; |
| 461 | 615 | $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 462 | 616 | if ( empty( $search ) ) { |
| 463 | 617 | $return = [ |
| @@ -465,9 +619,9 @@ | ||
| 465 | 619 | 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ), |
| 466 | 620 | ]; |
| 467 | 621 | wp_send_json( $return ); |
| 468 | 622 | } |
| 469 | - $query = $wpdb->prepare( | |
| 623 | + $query = $wpdb->prepare( | |
| 470 | 624 | "SELECT ID, post_title |
| 471 | 625 | FROM $wpdb->posts |
| 472 | 626 | WHERE post_type = 'product' |
| 473 | 627 | AND post_status = 'publish' |
| @@ -475,20 +629,20 @@ | ||
| 475 | 629 | LIMIT %d", |
| 476 | 630 | '%' . $search . '%', |
| 477 | 631 | 10 |
| 478 | 632 | ); |
| 479 | - | |
| 480 | - $_product = wp_cache_get( md5( $query ), 'rtsb-product-query' ); | |
| 633 | + $cache_key = md5( $query ); | |
| 634 | + $_product = wp_cache_get( $cache_key, 'shopbuilder' ); | |
| 481 | 635 | if ( false === $_product ) { |
| 482 | - $_product = $wpdb->get_results( $query ); | |
| 483 | - wp_cache_set( md5( $query ), $_product, 'rtsb-product-query' ); | |
| 636 | + $_product = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared | |
| 637 | + wp_cache_set( $cache_key, $_product, 'shopbuilder' ); | |
| 638 | + Cache::set_data_cache_key( $cache_key ); | |
| 484 | 639 | } |
| 485 | - | |
| 486 | 640 | $product_list = []; |
| 487 | 641 | foreach ( $_product as $product ) { |
| 488 | 642 | $product_list['items'][] = [ |
| 489 | 643 | 'id' => $product->ID, |
| 490 | - 'text' => $product->post_title . ' - ( ID ' . $product->ID . ' )', | |
| 644 | + 'text' => html_entity_decode( $product->post_title, ENT_QUOTES | ENT_HTML5 ) . ' - (ID#' . $product->ID . ')', | |
| 491 | 645 | ]; |
| 492 | 646 | } |
| 493 | 647 | |
| 494 | 648 | wp_send_json_success( $product_list ); |
| @@ -499,11 +653,11 @@ | ||
| 499 | 653 | * Popups For Create Template |
| 500 | 654 | * |
| 501 | 655 | * @return void |
| 502 | 656 | */ |
| 503 | - public function category_search() { | |
| 657 | + public function term_search() { | |
| 504 | 658 | |
| 505 | - if ( ! Fns::verify_nonce() ) { | |
| 659 | + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) { | |
| 506 | 660 | $return = [ |
| 507 | 661 | 'success' => false, |
| 508 | 662 | 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ), |
| 509 | 663 | ]; |
| @@ -508,17 +662,33 @@ | ||
| 508 | 662 | 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ), |
| 509 | 663 | ]; |
| 510 | 664 | wp_send_json( $return ); |
| 511 | 665 | } |
| 512 | - $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 513 | - $args = [ | |
| 514 | - 'taxonomy' => [ 'product_cat' ], // taxonomy name | |
| 666 | + | |
| 667 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 668 | + $return = [ | |
| 669 | + 'success' => false, | |
| 670 | + 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ), | |
| 671 | + ]; | |
| 672 | + wp_send_json( $return ); | |
| 673 | + } | |
| 674 | + | |
| 675 | + $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 676 | + $taxonomy = isset( $_REQUEST['taxonomy'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 677 | + if ( ! $taxonomy ) { | |
| 678 | + $return = [ | |
| 679 | + 'success' => false, | |
| 680 | + 'content' => esc_html__( 'Invalid taxonomy', 'shopbuilder' ), | |
| 681 | + ]; | |
| 682 | + wp_send_json( $return ); | |
| 683 | + } | |
| 684 | + $args = [ | |
| 685 | + 'taxonomy' => [ $taxonomy ], // taxonomy name. | |
| 515 | 686 | 'orderby' => 'name', |
| 516 | 687 | 'order' => 'ASC', |
| 517 | 688 | 'hide_empty' => false, |
| 518 | 689 | 'name__like' => $search, |
| 519 | 690 | ]; |
| 520 | - | |
| 521 | 691 | $terms = get_terms( $args ); |
| 522 | 692 | $count = count( $terms ); |
| 523 | 693 | $term_list = []; |
| 524 | 694 | if ( $count > 0 ) { |
| @@ -524,9 +694,9 @@ | ||
| 524 | 694 | if ( $count > 0 ) { |
| 525 | 695 | foreach ( $terms as $term ) { |
| 526 | 696 | $term_list['items'][] = [ |
| 527 | 697 | 'id' => $term->slug, |
| 528 | - 'text' => $term->name, | |
| 698 | + 'text' => html_entity_decode( $term->name, ENT_QUOTES | ENT_HTML5 ), | |
| 529 | 699 | ]; |
| 530 | 700 | } |
| 531 | 701 | } |
| 532 | 702 | wp_send_json_success( $term_list ); |