PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.6.8
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.6.8
2.7.0 2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 All 43 releases
sellkit / includes / admin / funnel / importer / page-builders / importer-base.php

importer-base.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.6.8, at includes/admin/funnel/importer/page-builders/importer-base.php

133 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Admin\Funnel\Importer\Page_Builder;
4
5 use Elementor\Plugin;
6
7 defined( 'ABSPATH' ) || die();
8
9 /**
10 * Class Funnel Importer.
11 *
12 * @since 1.1.0
13 */
14 class Importer_Base extends \WP_Background_Process {
15
16 /**
17 * Importing Process
18 *
19 * @var string
20 */
21 protected $action = 'sellkit_import_template_process';
22
23 /**
24 * Task
25 *
26 * Override this method to perform any actions required on each
27 * queue item. Return the modified item for further processing
28 * in the next pass through. Or, return false to remove the
29 * item from the queue.
30 *
31 * @since 1.0.0
32 *
33 * @param array $args Ids data.
34 * @return mixed
35 */
36 public function task( $args ) {
37 $data = $args['data'];
38 $new_step_id = $args['new_step_id'];
39
40 if ( class_exists( 'Elementor\Plugin' ) ) {
41 new Elementor_Importer( $data, $new_step_id );
42 }
43
44 return false;
45 }
46
47 /**
48 * Imports the step
49 *
50 * @since 1.1.0
51 * @param string $step_id Step id.
52 */
53 public function import_from_api( $step_id ) {
54 if ( empty( $step_id ) ) {
55 return new \WP_Error( 'sellkit_step_importer_has_no_step_id', esc_html__( 'Does not have any step id for importing', 'sellkit' ) );
56 }
57
58 $response = wp_remote_get( "https://templates.getsellkit.com/wp-json/sellkit/v1/step/{$step_id}" );
59
60 if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) {
61 $step_data = json_decode( $response['body'] );
62
63 return $step_data;
64 }
65
66 new \WP_Error( 'sellkit_funnel_step_importing_data_error', esc_html__( 'Something went wrong in importing data from API.', 'sellkit' ) );
67 }
68
69 /**
70 * Imports data to funnel.
71 *
72 * @since 1.1.0
73 * @param object $data Data.
74 * @param int $funnel_id Funnel id.
75 */
76 public function import_to_funnel( $data, $funnel_id ) {
77 $meta_data = (array) $data->meta;
78 $step_data = unserialize( $meta_data['step_data'] ); //phpcs:ignore
79
80 unset( $step_data['funnel_id'] );
81 unset( $step_data['number'] );
82 unset( $step_data['data'] );
83
84 $funnel_step_data = get_post_meta( $funnel_id, 'sellkit_steps', true );
85 $funnel_step_data = ! empty( $funnel_step_data ) ? $funnel_step_data : [];
86 $new_step_data = $this->create_new_step_page( $step_data );
87 $new_funnel_step_data = array_merge( $funnel_step_data, [ $new_step_data ] );
88
89 update_post_meta( $funnel_id, 'sellkit_steps', $new_funnel_step_data );
90
91 $args = array(
92 'ID' => $new_step_data['page_id'],
93 'post_content' => $data->post_content,
94 );
95
96 wp_update_post( $args );
97
98 foreach ( $data->meta as $meta_key => $meta_value ) {
99 if ( '_elementor_data' === $meta_data ) {
100 continue;
101 }
102
103 if ( is_serialized( $meta_value, true ) ) {
104 $meta_value = maybe_unserialize( stripslashes( $meta_value ) );
105 }
106
107 update_post_meta( $new_step_data['page_id'], $meta_key, $meta_value );
108 }
109
110 return $new_step_data['page_id'];
111 }
112
113 /**
114 * Filter step data before saving.
115 *
116 * @since 1.1.0
117 * @param array $last_step Step data.
118 */
119 public function create_new_step_page( $last_step ) {
120 $new_step_id = wp_insert_post( [
121 'post_type' => \Sellkit_Admin_Steps::SELLKIT_STEP_POST_TYPE,
122 'post_title' => $last_step['title'],
123 'post_name' => sanitize_title( $last_step['title'] ),
124 'post_status' => 'publish',
125 ] );
126
127 $last_step['page_id'] = $new_step_id;
128 $last_step['slug'] = get_post_field( 'post_name', $new_step_id );
129
130 return $last_step;
131 }
132 }
133