PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.13
ShopBuilder – WooCommerce Builder For Elementor v2.1.13
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / Admin / Ajax / DefaultTemplate.php

DefaultTemplate.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.13, at app/Controllers/Admin/Ajax/DefaultTemplate.php

72 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4
5 use RadiusTheme\SB\Helpers\BuilderFns;
6 use RadiusTheme\SB\Helpers\Fns;
7 use RadiusTheme\SB\Models\TemplateSettings;
8 use RadiusTheme\SB\Traits\SingletonTrait;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 /**
16 * Default Template Switch.
17 */
18 class DefaultTemplate {
19 /**
20 * Singleton Trait.
21 */
22 use SingletonTrait;
23
24 /**
25 * Construct function
26 */
27 private function __construct() {
28 add_action( 'wp_ajax_rtsb_default_template', [ $this, 'response' ] );
29 }
30
31 /**
32 * Set Default Template.
33 *
34 * @return void
35 */
36 public function response() {
37 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
38 wp_send_json_error();
39 }
40 if ( ! current_user_can( 'manage_options' ) ) {
41 wp_send_json_error();
42 }
43 $page_type = isset( $_POST['template_type'] ) ? sanitize_text_field( wp_unslash( $_POST['template_type'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
44 $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
45 $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
46
47 // For Specific Product
48 $the_option = BuilderFns::option_name_by_template_id( $page_id );
49 $the_cat_option = BuilderFns::archive_option_name_by_template_id( $page_id );
50
51 // $product_ids = get_option( $the_option );
52 // $the_cats = get_option( $the_cat_option );
53 $product_ids = TemplateSettings::instance()->get_option( $the_option );
54 $the_cats = TemplateSettings::instance()->get_option( $the_cat_option );
55 if ( empty( $product_ids ) && empty( $the_cats ) ) {
56 $option_name = BuilderFns::option_name( $page_type );
57 //update_option( $option_name, $default_page_id );
58 TemplateSettings::instance()->set_option( $option_name, $default_page_id );
59 }
60
61 do_action( 'rtsb/set/builder/default/template', $_POST, $page_id );
62
63 $return = [
64 'post_id' => $default_page_id,
65 'page_type' => $page_type,
66 ];
67 wp_send_json_success( $return );
68 wp_die();
69 }
70
71 }
72