PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-dev3
Elementor Website Builder – more than just a page builder v4.1.0-dev3
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
← All changes | modules/global-classes/global-class-post.php +16 -72 4.2.14.1.0-dev3 View file →
@@ -3,10 +3,8 @@
3 3 namespace Elementor\Modules\GlobalClasses;
4 4
5 5 use Elementor\Modules\AtomicWidgets\PropTypeMigrations\Migrations_Orchestrator;
6 6 use Elementor\Modules\GlobalClasses\Concerns\Has_Preview_Context;
7 -use Elementor\Plugin;
8 -use Elementor\Core\Kits\Documents\Kit;
9 7 use Elementor\Modules\GlobalClasses\Utils\Global_Class_Data_Normalizer;
10 8 use WP_Post;
11 9
12 10 if ( ! defined( 'ABSPATH' ) ) {
@@ -48,22 +46,22 @@
48 46
49 47 return ( new static( $post ) )->set_preview( $is_preview );
50 48 }
51 49
52 - public static function find_by_class_id( string $class_id, bool $is_preview = false, ?Kit $kit = null ): ?self {
53 - $kit = $kit ?? Plugin::$instance->kits_manager->get_active_kit();
50 + public static function find_by_class_id( string $class_id, bool $is_preview = false ): ?self {
51 + $posts = get_posts( [
52 + 'post_type' => Global_Class_Post_Type::CPT,
53 + 'post_status' => 'publish',
54 + 'posts_per_page' => 1,
55 + 'meta_key' => self::META_KEY_ID,
56 + 'meta_value' => $class_id,
57 + ] );
54 58
55 - if ( ! $kit ) {
59 + if ( empty( $posts ) ) {
56 60 return null;
57 61 }
58 62
59 - $post_id = Global_Classes_Post_IDs::make( $kit )->get_post_id( $class_id );
60 -
61 - if ( ! $post_id ) {
62 - return null;
63 - }
64 -
65 - return self::from_post_id( $post_id, $is_preview );
63 + return ( new self( $posts[0] ) )->set_preview( $is_preview );
66 64 }
67 65
68 66 public function get_post_id(): int {
69 67 return $this->post->ID;
@@ -82,8 +80,12 @@
82 80 public function get_label(): string {
83 81 return $this->post->post_title;
84 82 }
85 83
84 + public function get_order(): int {
85 + return (int) $this->post->menu_order;
86 + }
87 +
86 88 public function get_data( bool $skip_migration = false ): array {
87 89 $data = $this->get_context_data();
88 90 $meta_key = $this->get_context_key( 'data' );
89 91
@@ -196,20 +198,8 @@
196 198
197 199 return is_array( $data ) ? $data : [];
198 200 }
199 201
200 - private function get_preview_data(): array {
201 - $data = get_post_meta( $this->post->ID, self::META_KEY_DATA_PREVIEW, true );
202 -
203 - return is_array( $data ) ? $data : [];
204 - }
205 -
206 - private function get_version(): string {
207 - $version = get_post_meta( $this->post->ID, self::META_KEY_VERSION, true );
208 -
209 - return is_string( $version ) ? $version : '';
210 - }
211 -
212 202 public function update_data(
213 203 array $data,
214 204 string $version = ELEMENTOR_VERSION
215 205 ): bool {
@@ -233,9 +223,9 @@
233 223 public static function create(
234 224 string $class_id,
235 225 string $label,
236 226 array $data,
237 - ?Kit $kit = null,
227 + int $order = 0,
238 228 string $version = ELEMENTOR_VERSION
239 229 ): ?self {
240 230 $post_id = wp_insert_post( [
241 231 'post_type' => Global_Class_Post_Type::CPT,
@@ -240,8 +230,9 @@
240 230 $post_id = wp_insert_post( [
241 231 'post_type' => Global_Class_Post_Type::CPT,
242 232 'post_title' => $label,
243 233 'post_status' => 'publish',
234 + 'menu_order' => $order,
244 235 ] );
245 236
246 237 if ( is_wp_error( $post_id ) || ! $post_id ) {
247 238 return null;
@@ -252,14 +243,8 @@
252 243 update_post_meta( $post_id, self::META_KEY_ID, $class_id );
253 244 update_post_meta( $post_id, self::META_KEY_DATA, $normalized_data );
254 245 update_post_meta( $post_id, self::META_KEY_VERSION, $version );
255 246
256 - $kit = $kit ?? Plugin::$instance->kits_manager->get_active_kit();
257 -
258 - if ( $kit ) {
259 - Global_Classes_Post_IDs::make( $kit )->set( $class_id, (int) $post_id );
260 - }
261 -
262 247 $instance = self::from_post_id( $post_id );
263 248
264 249 if ( $instance ) {
265 250 update_post_meta( $post_id, self::META_KEY_EDITED, $instance->get_creation_timestamp() );
@@ -271,47 +256,6 @@
271 256 public function delete(): bool {
272 257 $result = wp_delete_post( $this->post->ID, true );
273 258
274 259 return false !== $result;
275 - }
276 -
277 - public static function clone_to_other_kit( string $style_id, Kit $source_kit, Kit $target_kit ): ?Global_Class_Post {
278 - $source_post = self::find_by_class_id( $style_id, false, $source_kit );
279 -
280 - if ( ! $source_post ) {
281 - return null;
282 - }
283 -
284 - $new_post_id = wp_insert_post( [
285 - 'post_type' => Global_Class_Post_Type::CPT,
286 - 'post_title' => $source_post->get_label(),
287 - 'post_status' => 'publish',
288 - ] );
289 -
290 - if ( is_wp_error( $new_post_id ) || ! $new_post_id ) {
291 - return null;
292 - }
293 -
294 - update_post_meta( $new_post_id, self::META_KEY_ID, $style_id );
295 - update_post_meta( $new_post_id, self::META_KEY_VERSION, $source_post->get_version() );
296 -
297 - $frontend_data = $source_post->get_frontend_data();
298 - $preview_data = $source_post->get_preview_data();
299 - $last_edited_timestamp = get_post_meta( $source_post->get_post_id(), self::META_KEY_EDITED, true );
300 -
301 - if ( ! empty( $frontend_data ) ) {
302 - update_post_meta( $new_post_id, self::META_KEY_DATA, $frontend_data );
303 - }
304 -
305 - if ( ! empty( $preview_data ) ) {
306 - update_post_meta( $new_post_id, self::META_KEY_DATA_PREVIEW, $preview_data );
307 - }
308 -
309 - if ( $last_edited_timestamp ) {
310 - update_post_meta( $new_post_id, self::META_KEY_EDITED, $last_edited_timestamp );
311 - }
312 -
313 - Global_Classes_Post_IDs::make( $target_kit )->set( $style_id, (int) $new_post_id );
314 -
315 - return self::from_post_id( $new_post_id );
316 260 }
317 261 }