PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-beta3
Elementor Website Builder – more than just a page builder v4.1.0-beta3
4.3.3 4.3.2 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 All 456 releases
← All changes | modules/global-classes/global-class-post.php +16 -19 4.1.2 → 4.1.0-beta3 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
@@ -221,9 +223,9 @@
221 223 public static function create(
222 224 string $class_id,
223 225 string $label,
224 226 array $data,
225 - ?Kit $kit = null,
227 + int $order = 0,
226 228 string $version = ELEMENTOR_VERSION
227 229 ): ?self {
228 230 $post_id = wp_insert_post( [
229 231 'post_type' => Global_Class_Post_Type::CPT,
@@ -228,8 +230,9 @@
228 230 $post_id = wp_insert_post( [
229 231 'post_type' => Global_Class_Post_Type::CPT,
230 232 'post_title' => $label,
231 233 'post_status' => 'publish',
234 + 'menu_order' => $order,
232 235 ] );
233 236
234 237 if ( is_wp_error( $post_id ) || ! $post_id ) {
235 238 return null;
@@ -239,14 +242,8 @@
239 242
240 243 update_post_meta( $post_id, self::META_KEY_ID, $class_id );
241 244 update_post_meta( $post_id, self::META_KEY_DATA, $normalized_data );
242 245 update_post_meta( $post_id, self::META_KEY_VERSION, $version );
243 -
244 - $kit = $kit ?? Plugin::$instance->kits_manager->get_active_kit();
245 -
246 - if ( $kit ) {
247 - Global_Classes_Post_IDs::make( $kit )->set( $class_id, (int) $post_id );
248 - }
249 246
250 247 $instance = self::from_post_id( $post_id );
251 248
252 249 if ( $instance ) {