PluginProbe ʕ •ᴥ•ʔ
Advanced Import / trunk
Advanced Import vtrunk
trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 2.0.0
advanced-import / admin / class-elementor-import.php
advanced-import / admin Last commit date
class-advanced-import-admin.php 3 weeks ago class-advanced-import-template.php 3 months ago class-advanced-import-tracking.php 3 weeks ago class-elementor-import.php 3 weeks ago class-reset.php 3 weeks ago index.php 5 years ago
class-elementor-import.php
237 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 /**
7 * The elementor import functionality of the plugin.
8 *
9 * @package Advanced_Import
10 * @subpackage Advanced_Import/admin/Advanced_Import_Elementor
11 * @author Addons Press <addonspress.com>
12 */
13 if ( ! class_exists( 'Advanced_Import_Elementor' ) ) {
14 /**
15 * Advanced_Import_Elementor
16 */
17 class Advanced_Import_Elementor {
18 /**
19 * Main Advanced_Import_Elementor Instance
20 * Initialize the class and set its properties.
21 *
22 * @since 1.0.0
23 * @return object $instance Advanced_Import_Elementor Instance
24 */
25 public static function instance() {
26
27 // Store the instance locally to avoid private static replication.
28 static $instance = null;
29
30 // Only run these methods if they haven't been ran previously.
31 if ( null === $instance ) {
32 $instance = new self();
33 }
34
35 // Always return the instance.
36 return $instance;
37 }
38
39 /**
40 * Change post id related to elementor to new id
41 *
42 * @param array $item current array of demo list.
43 * @param string $key
44 * @return void
45 */
46 public function elementor_id_import( &$item, $key ) {
47 if ( $key == 'id' && ! empty( $item ) && is_numeric( $item ) ) {
48 // check if this has been imported before
49 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
50 if ( $new_meta_val ) {
51 $item = $new_meta_val;
52 }
53 }
54 if ( $key == 'page' && ! empty( $item ) ) {
55
56 if ( false !== strpos( $item, 'p.' ) ) {
57 $new_id = str_replace( 'p.', '', $item );
58 // check if this has been imported before
59 $new_meta_val = advanced_import_admin()->imported_post_id( $new_id );
60 if ( $new_meta_val ) {
61 $item = 'p.' . $new_meta_val;
62 }
63 } elseif ( is_numeric( $item ) ) {
64 // check if this has been imported before
65 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
66 if ( $new_meta_val ) {
67 $item = $new_meta_val;
68 }
69 }
70 }
71 if ( $key == 'post_id' && ! empty( $item ) && is_numeric( $item ) ) {
72 // check if this has been imported before
73 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
74 if ( $new_meta_val ) {
75 $item = $new_meta_val;
76 }
77 }
78 if ( $key == 'url' && ! empty( $item ) && strstr( $item, 'ocalhost' ) ) {
79 // check if this has been imported before
80 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
81 if ( $new_meta_val ) {
82 $item = $new_meta_val;
83 }
84 }
85 if ( ( $key == 'shortcode' || $key == 'editor' ) && ! empty( $item ) ) {
86 // we have to fix the [contact-form-7 id=133] shortcode issue.
87 $item = advanced_import_admin()->parse_shortcode_meta_content( $item );
88
89 }
90 }
91
92 public function elementor_post( $post_id = false ) {
93
94 // regenerate the CSS for this Elementor post
95 if ( class_exists( 'Elementor\Core\Files\CSS\Post' ) ) {
96 $post_css = new Elementor\Core\Files\CSS\Post( $post_id );
97 $post_css->update();
98 }
99 }
100
101 /**
102 * Set and get transient adi_elementor_data_posts.
103 *
104 * @since 1.0.0
105 * @param int|string|false $el_post_id Elementor post ID.
106 * @param array|false $meta_val Meta value to store.
107 * @return array Transient data.
108 */
109 public function elementor_data_posts( $el_post_id = false, $meta_val = false ) {
110 $el_posts = get_transient( 'adi_elementor_data_posts' );
111 if ( ! is_array( $el_posts ) ) {
112 $el_posts = array();
113 }
114 if ( $el_post_id && $meta_val ) {
115 $el_posts[ $el_post_id ] = $meta_val;
116 set_transient( 'adi_elementor_data_posts', $el_posts, 60 * 60 * 24 );
117 }
118 return $el_posts;
119 }
120
121 /**
122 * Change post and term id related to elementor meta to new id
123 *
124 * @param array $item current array of demo list.
125 * @param string $key
126 * @return array
127 */
128 public function elementor_data( $elementor_data ) {
129
130 if ( advanced_import_admin()->isJson( $elementor_data ) && is_string( $elementor_data ) && ! is_null( $elementor_data ) ) {
131 $elementor_data = json_decode( stripslashes( $elementor_data ), true );
132 }
133
134 /*Terms IDS*/
135 $replace_post_ids = apply_filters(
136 'advanced_import_replace_post_ids',
137 array(
138 'image_id',
139 'thumbnail_id',
140 'page_id',
141 'post_id',
142 )
143 );
144
145 /*Terms IDS*/
146 $replace_term_ids = apply_filters(
147 'advanced_import_replace_term_ids',
148 array(
149 'acm_authors_list',
150 'categories_selected',
151 )
152 );
153
154 // Recursively update elementor data.
155 foreach ( $elementor_data as $element_id => $element_data ) {
156 if ( ! empty( $element_data['elements'] ) ) {
157 foreach ( $element_data['elements'] as $el_key => $el_data ) {
158 if ( ! empty( $el_data['elements'] ) ) {
159 foreach ( $el_data['elements'] as $el_child_key => $child_el_data ) {
160 if ( 'widget' === $child_el_data['elType'] ) {
161 $settings = isset( $child_el_data['settings'] ) ? $child_el_data['settings'] : array();
162
163 if ( ! empty( $settings ) ) {
164 foreach ( $settings as $el_set_key => $el_set_data ) {
165 if ( in_array( $el_set_key, $replace_post_ids ) ) {
166 if ( is_numeric( $el_set_data ) ) {
167 $el_set_data = advanced_import_admin()->imported_post_id( $el_set_data );
168 } elseif ( is_array( $el_set_data ) && ! empty( $el_set_data ) ) {
169 $new_set_data = array();
170 foreach ( $el_set_data as $el_set_single_data ) {
171 if ( is_numeric( $el_set_single_data ) ) {
172 $new_set_data[] = advanced_import_admin()->imported_post_id( $el_set_single_data );
173 }
174 }
175 $el_set_data = $new_set_data;
176 }
177 }
178 if ( in_array( $el_set_key, $replace_term_ids ) ) {
179 if ( is_numeric( $el_set_data ) ) {
180 $el_set_data = advanced_import_admin()->imported_term_id( $el_set_data );
181 } elseif ( is_array( $el_set_data ) && ! empty( $el_set_data ) ) {
182 $new_set_data = array();
183 foreach ( $el_set_data as $el_set_single_data ) {
184 if ( is_numeric( $el_set_single_data ) ) {
185 $new_set_data[] = advanced_import_admin()->imported_term_id( $el_set_single_data );
186 }
187 }
188 $el_set_data = $new_set_data;
189 }
190 }
191 $elementor_data[ $element_id ]['elements'][ $el_key ]['elements'][ $el_child_key ]['settings'][ $el_set_key ] = $el_set_data;
192
193 }
194 }
195 }
196 }
197 }
198 }
199 }
200 }
201
202 return $elementor_data;
203 }
204
205 /**
206 * Change post and term id related to elementor meta to new id
207 *
208 * @param array $item current array of demo list.
209 * @param string $key
210 * @return void
211 */
212 public function process_elementor_posts() {
213 $el_posts = $this->elementor_data_posts();
214 if ( is_array( $el_posts ) && ! empty( $el_posts ) ) {
215 foreach ( $el_posts as $el_post => $el_data ) {
216 $el_data = $this->elementor_data( $el_data );
217 update_post_meta( $el_post, '_elementor_data', $el_data );
218 }
219 }
220 }
221 }
222 }
223
224
225 /**
226 * Begins execution of the plugin.
227 *
228 * Since everything within the plugin is registered via hooks,
229 * then kicking off the plugin from this point in the file does
230 * not affect the page life cycle.
231 *
232 * @since 1.0.0
233 */
234 function advanced_import_elementor() {
235 return Advanced_Import_Elementor::instance();
236 }
237