| @@ -41,19 +41,19 @@ | ||
| 41 | 41 | if ( ! current_user_can( 'manage_options' ) ) { |
| 42 | 42 | wp_send_json_error(); |
| 43 | 43 | } |
| 44 | 44 | $page_type = isset( $_POST['template_type'] ) ? sanitize_text_field( wp_unslash( $_POST['template_type'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 45 | - $default_page_id = isset( $_POST['set_default_page_id'] ) && 'publish' === get_post_status( $_POST['set_default_page_id'] ) ? absint( wp_unslash( $_POST['set_default_page_id'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 46 | - $page_id = isset( $_POST['page_id'] ) && 'publish' === get_post_status( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 45 | + $default_page_id = isset( $_POST['set_default_page_id'] ) && 'publish' === get_post_status( $_POST['set_default_page_id'] ) ? absint( wp_unslash( $_POST['set_default_page_id'] ) ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 46 | + $page_id = isset( $_POST['page_id'] ) && 'publish' === get_post_status( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 47 | 47 | Cache::clear_transient_cache(); |
| 48 | - $the_cat_option = BuilderFns::archive_option_name_by_template_id( $page_id ); | |
| 49 | - $the_cats = TemplateSettings::instance()->get_option( $the_cat_option ); | |
| 50 | - $option_name = BuilderFns::option_name( $page_type ); | |
| 51 | - $product_page_for = get_post_meta( $page_id, '_is_product_page_template_for', true ); | |
| 52 | - | |
| 48 | + $the_cat_option = BuilderFns::archive_option_name_by_template_id( $page_id ); | |
| 49 | + $the_cats = TemplateSettings::instance()->get_option( $the_cat_option ); | |
| 50 | + $option_name = BuilderFns::option_name( $page_type ); | |
| 51 | + $product_page_for = get_post_meta( $page_id, '_is_product_page_template_for', true ); | |
| 53 | 52 | $is_can_set_default = true; |
| 54 | 53 | switch ( $page_type ) { |
| 55 | 54 | case 'product': |
| 55 | + $product_page_for = empty( $product_page_for ) ? 'all_products' : $product_page_for; | |
| 56 | 56 | if ( 'all_products' !== $product_page_for ) { |
| 57 | 57 | $is_can_set_default = null; |
| 58 | 58 | } |
| 59 | 59 | break; |
| @@ -63,8 +63,9 @@ | ||
| 63 | 63 | } |
| 64 | 64 | break; |
| 65 | 65 | default: |
| 66 | 66 | } |
| 67 | + | |
| 67 | 68 | if ( $is_can_set_default ) { |
| 68 | 69 | TemplateSettings::instance()->set_option( $option_name, $default_page_id ); |
| 69 | 70 | } |
| 70 | 71 | |