PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.1.4
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.1.4
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.1.4, at includes/admin/funnel/importer/page-builders/importer-base.php

131 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 new Elementor_Importer( $data, $new_step_id );
41
42 return false;
43 }
44
45 /**
46 * Imports the step
47 *
48 * @since 1.1.0
49 * @param string $step_id Step id.
50 */
51 public function import_from_api( $step_id ) {
52 if ( empty( $step_id ) ) {
53 return new \WP_Error( 'sellkit_step_importer_has_no_step_id', esc_html__( 'Does not have any step id for importing', 'sellkit' ) );
54 }
55
56 $response = wp_remote_get( "https://templates.getsellkit.com/wp-json/sellkit/v1/step/{$step_id}" );
57
58 if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) {
59 $step_data = json_decode( $response['body'] );
60
61 return $step_data;
62 }
63
64 new \WP_Error( 'sellkit_funnel_step_importing_data_error', esc_html__( 'Something went wrong in importing data from API.', 'sellkit' ) );
65 }
66
67 /**
68 * Imports data to funnel.
69 *
70 * @since 1.1.0
71 * @param object $data Data.
72 * @param int $funnel_id Funnel id.
73 */
74 public function import_to_funnel( $data, $funnel_id ) {
75 $meta_data = (array) $data->meta;
76 $step_data = unserialize( $meta_data['step_data'] ); //phpcs:ignore
77
78 unset( $step_data['funnel_id'] );
79 unset( $step_data['number'] );
80 unset( $step_data['data'] );
81
82 $funnel_step_data = get_post_meta( $funnel_id, 'sellkit_steps', true );
83 $funnel_step_data = ! empty( $funnel_step_data ) ? $funnel_step_data : [];
84 $new_step_data = $this->create_new_step_page( $step_data );
85 $new_funnel_step_data = array_merge( $funnel_step_data, [ $new_step_data ] );
86
87 update_post_meta( $funnel_id, 'sellkit_steps', $new_funnel_step_data );
88
89 $args = array(
90 'ID' => $new_step_data['page_id'],
91 'post_content' => $data->post_content,
92 );
93
94 wp_update_post( $args );
95
96 foreach ( $data->meta as $meta_key => $meta_value ) {
97 if ( '_elementor_data' === $meta_data ) {
98 continue;
99 }
100
101 if ( is_serialized( $meta_value, true ) ) {
102 $meta_value = maybe_unserialize( stripslashes( $meta_value ) );
103 }
104
105 update_post_meta( $new_step_data['page_id'], $meta_key, $meta_value );
106 }
107
108 return $new_step_data['page_id'];
109 }
110
111 /**
112 * Filter step data before saving.
113 *
114 * @since 1.1.0
115 * @param array $last_step Step data.
116 */
117 public function create_new_step_page( $last_step ) {
118 $new_step_id = wp_insert_post( [
119 'post_type' => \Sellkit_Admin_Steps::SELLKIT_STEP_POST_TYPE,
120 'post_title' => $last_step['title'],
121 'post_name' => sanitize_title( $last_step['title'] ),
122 'post_status' => 'publish',
123 ] );
124
125 $last_step['page_id'] = $new_step_id;
126 $last_step['slug'] = get_post_field( 'post_name', $new_step_id );
127
128 return $last_step;
129 }
130 }
131