PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-beta1
Elementor Website Builder – more than just a page builder v4.1.0-beta1
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 +13 -68 4.1.0-beta3 → 4.1.0-beta1 View file →
@@ -3,9 +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\Modules\GlobalClasses\Utils\Global_Class_Data_Normalizer;
8 7 use WP_Post;
9 8
10 9 if ( ! defined( 'ABSPATH' ) ) {
11 10 exit; // Exit if accessed directly.
@@ -17,9 +16,8 @@
17 16 const META_KEY_VERSION = '_elementor_version';
18 17 const META_KEY_ID = '_elementor_global_class_id';
19 18 const META_KEY_DATA = '_elementor_global_class_data';
20 19 const META_KEY_DATA_PREVIEW = '_elementor_global_class_data_preview';
21 - const META_KEY_EDITED = '_elementor_global_class_edited';
22 20
23 21 protected array $context_keys = [
24 22 'data' => [
25 23 'frontend' => self::META_KEY_DATA,
@@ -33,9 +31,9 @@
33 31 $this->post = $post;
34 32 }
35 33
36 34 public static function from_post( WP_Post $post, bool $is_preview = false ): self {
37 - return ( new static( $post ) )->set_preview( $is_preview );
35 + return ( new self( $post ) )->set_preview( $is_preview );
38 36 }
39 37
40 38 public static function from_post_id( int $post_id, bool $is_preview = false ): ?self {
41 39 $post = get_post( $post_id );
@@ -43,9 +41,9 @@
43 41 if ( ! $post || Global_Class_Post_Type::CPT !== $post->post_type ) {
44 42 return null;
45 43 }
46 44
47 - return ( new static( $post ) )->set_preview( $is_preview );
45 + return ( new self( $post ) )->set_preview( $is_preview );
48 46 }
49 47
50 48 public static function find_by_class_id( string $class_id, bool $is_preview = false ): ?self {
51 49 $posts = get_posts( [
@@ -122,59 +120,22 @@
122 120
123 121 public function to_array( bool $skip_migration = false ): array {
124 122 $data = $this->get_data( $skip_migration );
125 123
126 - $class_id = $this->get_class_id();
124 + $result = [
125 + 'id' => $this->get_class_id(),
126 + 'label' => $this->get_label(),
127 + 'type' => $data['type'] ?? 'class',
128 + 'variants' => $data['variants'] ?? [],
129 + ];
127 130
128 - return Global_Class_Data_Normalizer::normalize_style(
129 - $class_id,
130 - array_merge( $data, [ 'label' => $this->get_label() ] )
131 - );
132 - }
133 -
134 - public function was_edited(): bool {
135 - $last_edited = $this->get_last_edited_timestamp();
136 - $creation = $this->get_creation_timestamp();
137 -
138 - return $last_edited > $creation;
139 - }
140 -
141 - public function has_edit_timestamp(): bool {
142 - return $this->get_last_edited_timestamp() > 0;
143 - }
144 -
145 - private function get_creation_timestamp(): int {
146 - $dt = get_post_datetime( $this->post, 'date', 'gmt' );
147 -
148 - if ( $dt ) {
149 - return (int) $dt->format( 'U' );
131 + if ( array_key_exists( 'sync_to_v3', $data ) ) {
132 + $result['sync_to_v3'] = (bool) $data['sync_to_v3'];
150 133 }
151 134
152 - return (int) strtotime( (string) $this->post->post_date );
135 + return $result;
153 136 }
154 137
155 - private function get_last_edited_timestamp(): int {
156 - $raw = get_post_meta( $this->post->ID, self::META_KEY_EDITED, true );
157 -
158 - if ( self::is_timestamp( $raw ) ) {
159 - return (int) $raw;
160 - }
161 -
162 - return 0;
163 - }
164 -
165 - private static function is_timestamp( $value ): bool {
166 - if ( ! is_numeric( $value ) ) {
167 - return false;
168 - }
169 -
170 - return (int) $value > 0;
171 - }
172 -
173 - protected function get_current_timestamp(): int {
174 - return (int) time();
175 - }
176 -
177 138 public function update_label( string $label ): bool {
178 139 $result = wp_update_post( [
179 140 'ID' => $this->post->ID,
180 141 'post_title' => $label,
@@ -179,12 +140,8 @@
179 140 'ID' => $this->post->ID,
180 141 'post_title' => $label,
181 142 ] );
182 143
183 - if ( ! is_wp_error( $result ) && ! $this->is_preview() ) {
184 - update_post_meta( $this->post->ID, self::META_KEY_EDITED, $this->get_current_timestamp() );
185 - }
186 -
187 144 return ! is_wp_error( $result );
188 145 }
189 146
190 147 private function get_context_data(): array {
@@ -212,12 +169,8 @@
212 169 }
213 170
214 171 update_post_meta( $this->post->ID, self::META_KEY_VERSION, $version );
215 172
216 - if ( ! $this->is_preview() ) {
217 - update_post_meta( $this->post->ID, self::META_KEY_EDITED, $this->get_current_timestamp() );
218 - }
219 -
220 173 return false !== $result;
221 174 }
222 175
223 176 public static function create(
@@ -237,21 +190,13 @@
237 190 if ( is_wp_error( $post_id ) || ! $post_id ) {
238 191 return null;
239 192 }
240 193
241 - $normalized_data = Global_Class_Data_Normalizer::normalize_style_fields( $data );
242 -
243 194 update_post_meta( $post_id, self::META_KEY_ID, $class_id );
244 - update_post_meta( $post_id, self::META_KEY_DATA, $normalized_data );
195 + update_post_meta( $post_id, self::META_KEY_DATA, $data );
245 196 update_post_meta( $post_id, self::META_KEY_VERSION, $version );
246 197
247 - $instance = self::from_post_id( $post_id );
248 -
249 - if ( $instance ) {
250 - update_post_meta( $post_id, self::META_KEY_EDITED, $instance->get_creation_timestamp() );
251 - }
252 -
253 - return $instance;
198 + return self::from_post_id( $post_id );
254 199 }
255 200
256 201 public function delete(): bool {
257 202 $result = wp_delete_post( $this->post->ID, true );