PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.0
ShopBuilder – WooCommerce Builder For Elementor v1.1.0
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 / CreateTemplate.php

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

126 lines 4.0 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\Traits\SingletonTrait;
8
9 // Do not allow directly accessing this file.
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit( 'This script cannot be accessed directly.' );
12 }
13 /**
14 * Default Template Switch.
15 */
16 class CreateTemplate {
17 /**
18 * Singleton Trait.
19 */
20 use SingletonTrait;
21 /**
22 * Construct function
23 */
24 private function __construct() {
25 add_action( 'wp_ajax_rtsb_builder_create_template', [ $this, 'response' ] );
26 }
27 /**
28 * Create template
29 *
30 * @return void
31 */
32 public static function response() {
33 $page_type = isset( $_POST['page_type'] ) ? sanitize_text_field( wp_unslash( $_POST['page_type'] ) ) : null;
34 $page_id = isset( $_POST['page_id'] ) ? absint( wp_unslash( $_POST['page_id'] ) ) : null;
35 $page_name = isset( $_POST['page_name'] ) ? sanitize_text_field( wp_unslash( $_POST['page_name'] ) ) : null;
36 $edit_with = isset( $_POST['template_edit_with'] ) ? sanitize_text_field( wp_unslash( $_POST['template_edit_with'] ) ) : null;
37 $default_template = isset( $_POST['default_template'] ) ? sanitize_text_field( wp_unslash( $_POST['default_template'] ) ) : null;
38 $import_layout = isset( $_POST['import_default_layout'] ) ? sanitize_text_field( wp_unslash( $_POST['import_default_layout'] ) ) : null;
39 $product_id = isset( $_POST['display_product_id'] ) ? absint( $_POST['display_product_id'] ) : null;
40
41 $url = '#';
42
43 if ( ! Fns::verify_nonce() || ! $page_type ) {
44 $return = [
45 'success' => false,
46 'post_id' => $page_id,
47 ];
48 wp_send_json( $return );
49 }
50 $option_name = BuilderFns::option_name( $page_type );
51 $post_data = [
52 'ID' => $page_id,
53 'post_title' => $page_name,
54 'meta_input' => [
55 BuilderFns::template_type_meta_key() => $page_type,
56 ],
57 ];
58 if ( 'elementor' == $edit_with ) {
59 $post_data['meta_input']['_elementor_edit_mode'] = 'builder';
60 } elseif ( 'gutenberg' == $edit_with ) {
61 $post_data['meta_input']['_elementor_edit_mode'] = '';
62 }
63
64 if ( $page_id ) {
65 $page_id = wp_update_post( $post_data );
66 $new_page = false;
67 } else {
68 unset( $post_data['ID'] );
69 $post_data['post_type'] = BuilderFns::$post_type_tb;
70 $post_data['post_status'] = 'publish';
71 $page_id = wp_insert_post( $post_data );
72 $new_page = true;
73 if ( 'elementor' == $edit_with ) {
74 update_post_meta( $page_id, '_wp_page_template', 'elementor_header_footer' );
75 }
76 }
77
78 $edit_by = '';
79 if ( $page_id ) {
80 if( 'product' == $page_type ){
81 update_post_meta( $product_id, BuilderFns::$product_template_meta, $page_id );
82 update_post_meta( $page_id, BuilderFns::$product_template_meta, $product_id );
83 }
84 $edit_by = Fns::page_edit_with( $page_id );
85 if ( 'default_template' === $default_template ) {
86 update_option( $option_name, $page_id );
87 } else {
88 update_option( $option_name, '' );
89 }
90 $action = 'edit';
91 if ( 'elementor' === $edit_by ) {
92 $action = 'elementor';
93 }
94 $url = add_query_arg(
95 [
96 'post' => $page_id,
97 'action' => $action,
98 ],
99 admin_url( 'post.php' )
100 );
101 $filepath = rtsb()->plugin_path() . $import_layout;
102 // TODO:: Need use Elementor importer. In future Version.
103 if ( ! empty( $import_layout ) && file_exists( $filepath ) ) {
104 $json_value = wp_json_file_decode( $filepath, [ 'associative' => true ] );
105 if ( ! empty( $json_value['content'] ) ) {
106 $content = wp_slash( wp_json_encode( $json_value['content'] ) );
107 update_post_meta( $page_id, '_elementor_data', $content );
108 }
109 }
110 }
111
112 $return = [
113 'success' => true,
114 'post_id' => $page_id,
115 'post_edit_url' => $url,
116 'new_page' => $new_page,
117
118 ];
119 if ( $edit_by ) {
120 $return['edit_btn_text'] = esc_html__( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' );
121 }
122 wp_send_json( $return );
123 wp_die();
124 }
125 }
126