PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / includes / Staging.php
kirki / includes Last commit date
API 5 days ago Admin 1 month ago Ajax 5 days ago ExportImport 2 weeks ago FormValidator 3 months ago Frontend 5 days ago Manager 3 weeks ago API.php 2 weeks ago Admin.php 3 months ago Ajax.php 5 days ago Apps.php 1 month ago ContentManager.php 3 months ago DbQueryUtils.php 2 months ago ElementVisibilityConditions.php 3 months ago Frontend.php 3 months ago HelperFunctions.php 5 days ago KirkiBase.php 1 month ago PostsQueryUtils.php 3 months ago Staging.php 5 days ago View.php 1 month ago
Staging.php
511 lines
1 <?php
2
3 /**
4 * This class act like controller for Editor, Iframe, Frontend
5 *
6 * @package kirki
7 */
8
9 namespace Kirki;
10
11 use Kirki\Ajax\Collaboration\Collaboration;
12 use Kirki\HelperFunctions;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Frontend handler class
20 */
21 class Staging {
22
23 /**
24 * @deprecated
25 * @see Kirki\App\Managers\PageManager::get_most_recent_stage_version()
26 */
27 public static function get_most_recent_stage_version( $post_id, $stage_must = true, $restoring = false, $old_version = false ) {
28 $staged_versions = self::get_all_staged_versions( $post_id, true );
29 $recent_stage_version = false;
30 $version_number = 0;
31 $being_restored = false;
32
33 foreach ( $staged_versions as $version ) {
34 if ( is_array( $version ) && intval( $version['version'] ) > $version_number ) {
35 $version_number = $version['version'];
36 $recent_stage_version = $version;
37 }
38
39 if ( $restoring && intval( $old_version ) === intval( $version['version'] ) ) {
40 $being_restored = $version;
41 }
42 }
43
44 if ( $version_number === 0 || ( $stage_must && isset( $recent_stage_version['publish'] ) && $recent_stage_version['publish'] ) || $restoring ) {
45 $version_number = self::add_stage_version( $post_id, $version_number + 1, $staged_versions, $being_restored );
46 }
47
48 return $version_number;
49 }
50
51 /**
52 * @deprecated
53 * @see Kirki\App\Managers\PageManager::get_all_staged_versions()
54 */
55 public static function get_all_staged_versions( $post_id, $internal = false, $withname = false ) {
56 // delete_post_meta($post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS);
57 $staged_versions = get_post_meta( $post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS, true );
58 if ( ! is_array( $staged_versions ) || count( $staged_versions ) < 1 ) {
59 $staged_versions = self::create_first_stage_version( $post_id );
60 }
61 if ( $withname ) {
62 $staged_versions = self::add_editor_names_into_stage_versions( $staged_versions );
63 }
64 if ( $internal ) {
65 return $staged_versions;
66 }
67 wp_send_json( $staged_versions );
68 }
69
70 /**
71 * @deprecated
72 * @see Kirki\App\Managers\PageManager::publish_stage_version()
73 */
74 public static function publish_stage_version( $internal = false, $post_id = false ) {
75 if ( ! $internal ) {
76 $post_id = HelperFunctions::sanitize_text( isset( $_POST['post_id'] ) ? $_POST['post_id'] : null );
77 }
78
79 if ( ! $post_id ) {
80 wp_send_json( false, 400 );
81 }
82
83 $version_id = self::get_most_recent_stage_version( $post_id, false );
84 $staged_versions = self::get_all_staged_versions( $post_id, true, true );
85 $staged_versions = array_map(
86 function ( $item ) use ( $version_id ) {
87 return ( is_array( $item ) && isset( $item['version'] ) && intval( $item['version'] ) === intval( $version_id ) )
88 ? array_merge( $item, array( 'publish' => true ) )
89 : array_merge( $item, array( 'publish' => false ) );
90 },
91 $staged_versions
92 );
93 update_post_meta( $post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS, $staged_versions );
94 if ( $internal ) {
95 return $staged_versions;
96 }
97 wp_send_json( $staged_versions );
98 }
99
100
101 /**
102 * @deprecated
103 * @see Kirki\App\Managers\PageManager::get_published_stage_version()
104 */
105 public static function get_published_stage_version( $post_id ) {
106 $staged_versions = self::get_all_staged_versions( $post_id, true, true );
107
108 // Find the first staged version that has 'publish' set to true
109 $published_version = null;
110 foreach ( $staged_versions as $item ) {
111 if ( ! empty( $item['publish'] ) ) {
112 $published_version = $item;
113 break;
114 }
115 }
116
117 return isset( $published_version['version'] ) ? $published_version['version'] : false;
118 }
119
120 /**
121 * @deprecated
122 * @see Kirki\App\Managers\PageManager::get_published_staged_version_info()
123 */
124 public static function get_published_stage_version_info( $post_id ) {
125 $staged_versions = self::get_all_staged_versions( $post_id, true, true );
126
127 // Find the first staged version that has 'publish' set to true
128 $published_version = null;
129 foreach ( $staged_versions as $item ) {
130 if ( ! empty( $item['publish'] ) ) {
131 $published_version = $item;
132 break;
133 }
134 }
135
136 return isset( $published_version['version'] ) ? $published_version : false;
137 }
138
139 public static function get_page_staging_data( $post_id, $version_id ) {
140 $kirki_data = array();
141 $kirki_data['blocks'] = null;
142
143 $meta_name = self::get_staged_meta_name( 'kirki', $post_id, $version_id );
144 $staging_post_meta = get_post_meta( $post_id, $meta_name, true );
145 if ( $staging_post_meta ) {
146 $kirki_data = $staging_post_meta;
147 }
148
149 $styles = HelperFunctions::get_page_styleblocks( $post_id, $version_id );
150 $kirki_data['styles'] = isset( $styles ) ? $styles : '';
151 return $kirki_data;
152 }
153
154 // This function receives the page data (blocks, styleblocks...) and saves in stage version whichever required in stage
155 // returns the data which needs to be saved in Publish version
156 /**
157 * @deprecated
158 * @see Kirki\App\Services\PageService::save_page_data()
159 */
160 public static function save_page_staging_data_to_db( $post_id, $page_data ) {
161 $staging_version = self::get_most_recent_stage_version( $post_id );
162 self::update_last_edited_datetime_of_stage_version( $post_id );
163 if ( isset( $page_data['styles'] ) ) {
164 $new_random_styles = $page_data['styles'];
165 $new_global_styles = array(); // global Styleblocks which won't be saved in publish but stage
166 $add_to_publish_global = array(); // global Styleblocks which won't be saved in stage but publish
167
168 foreach ( $new_random_styles as $key => $style ) {
169 if ( ( isset( $style['isDefault'] ) && $style['isDefault'] === true ) || ( isset( $style['isGlobal'] ) && $style['isGlobal'] === true ) ) {
170 if ( isset( $style['fromStage'] ) && $style['fromStage'] ) {
171 $new_global_styles[ $key ] = $style;
172 } else {
173 // Adding fromStage true because publish version saves only styleblocks having fromStage
174 $style['fromStage'] = true;
175 $add_to_publish_global[ $key ] = $style;
176 }
177 unset( $new_random_styles[ $key ] );
178 }
179 }
180
181 $meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY . '_random', $post_id, $staging_version );
182 update_post_meta( $post_id, $meta_key, $new_random_styles );
183
184 // $data = array(
185 // 'type' => 'COLLABORATION_UPDATE_GLOBAL_STYLE',
186 // 'payload' => array( 'styleBlock' => $new_random_styles ),
187 // );
188 // Collaboration::save_action_to_db( 'post', $post_id, $data, 1 );
189
190 $global_meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY, $post_id, $staging_version );
191 update_post_meta( $post_id, $global_meta_key, $new_global_styles );
192
193 // $data = array(
194 // 'type' => 'COLLABORATION_UPDATE_GLOBAL_STYLE',
195 // 'payload' => array( 'styleBlock' => $new_global_styles ),
196 // );
197 // Collaboration::save_action_to_db( 'global', 0, $data, 1 );
198
199 if ( count( $add_to_publish_global ) ) {
200 $page_data['styles'] = $add_to_publish_global;
201 } else {
202 unset( $page_data['styles'] ); // Unset if no global style blocks for publish version
203 }
204 }
205
206 if ( isset( $page_data['usedStyles'] ) ) {
207 $meta_key = KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS;
208 $meta_key = self::get_staged_meta_name( $meta_key, $post_id, $staging_version );
209 update_post_meta( $post_id, $meta_key, $page_data['usedStyles'] );
210 unset( $page_data['usedStyles'] );
211 }
212
213 if ( isset( $page_data['usedStyleIdsRandom'] ) ) {
214 $meta_key = KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS . '_random';
215 $meta_key = self::get_staged_meta_name( $meta_key, $post_id, $staging_version );
216 update_post_meta( $post_id, $meta_key, $page_data['usedStyleIdsRandom'] );
217 unset( $page_data['usedStyleIdsRandom'] );
218 }
219
220 if ( isset( $page_data['usedFonts'] ) ) {
221 $meta_key = KIRKI_META_NAME_FOR_USED_FONT_LIST;
222 $meta_key = self::get_staged_meta_name( $meta_key, $post_id, $staging_version );
223 update_post_meta( $post_id, $meta_key, $page_data['usedFonts'] );
224 unset( $page_data['usedFonts'] );
225 }
226
227 if ( isset( $page_data['blocks'] ) ) {
228 $meta_key = 'kirki';
229 $meta_key = self::get_staged_meta_name( $meta_key, $post_id, $staging_version );
230 update_post_meta( $post_id, $meta_key, array( 'blocks' => $page_data['blocks'] ) );
231 // $data = array(
232 // 'type' => 'COLLABORATION_PAGE_DATA',
233 // 'payload' => array('data' => $page_data['blocks']),
234 // );
235 unset( $page_data['blocks'] );
236 // Collaboration::save_action_to_db('post', $post_id, $data, 1);
237 }
238
239 return array(
240 'page_data' => $page_data,
241 'version' => $staging_version,
242 );
243 }
244
245 /**
246 * @deprecated
247 * @see Kirki\App\Managers\PageManager::restore_stage_version()
248 */
249 public static function restore_stage_version() {
250
251 $post_id = HelperFunctions::sanitize_text( isset( $_POST['post_id'] ) ? $_POST['post_id'] : null );
252 $old_version_id = HelperFunctions::sanitize_text( isset( $_POST['stage_version'] ) ? $_POST['stage_version'] : null );
253
254 $new_version = self::get_most_recent_stage_version( $post_id, true, true, $old_version_id );
255
256 $old_meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY . '_random', $post_id, $old_version_id );
257 $old_data = get_post_meta( $post_id, $old_meta_key, true );
258 $new_meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY . '_random', $post_id, $new_version );
259 update_post_meta( $post_id, $new_meta_key, $old_data );
260
261 $old_meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY, $post_id, $old_version_id );
262 $old_data = get_post_meta( $post_id, $old_meta_key, true );
263 $new_meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY, $post_id, $new_version );
264 update_post_meta( $post_id, $new_meta_key, $old_data );
265
266 $old_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS, $post_id, $old_version_id );
267 $old_data = get_post_meta( $post_id, $old_meta_key, true );
268 $new_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS, $post_id, $new_version );
269 update_post_meta( $post_id, $new_meta_key, $old_data );
270
271 $old_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS . '_random', $post_id, $old_version_id );
272 $old_data = get_post_meta( $post_id, $old_meta_key, true );
273 $new_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS . '_random', $post_id, $new_version );
274 update_post_meta( $post_id, $new_meta_key, $old_data );
275
276 $old_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_FONT_LIST, $post_id, $old_version_id );
277 $old_data = get_post_meta( $post_id, $old_meta_key, true );
278 $new_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_FONT_LIST, $post_id, $new_version );
279 update_post_meta( $post_id, $new_meta_key, $old_data );
280
281 $old_meta_key = self::get_staged_meta_name( 'kirki', $post_id, $old_version_id );
282 $old_data = get_post_meta( $post_id, $old_meta_key, true );
283 $new_meta_key = self::get_staged_meta_name( 'kirki', $post_id, $new_version );
284 update_post_meta( $post_id, $new_meta_key, $old_data );
285
286 wp_send_json( array_merge( array( 'versions' => self::get_all_staged_versions( $post_id, true, true ) ), array( 'new_version' => $new_version ) ) );
287 }
288
289 /**
290 * @deprecated
291 * @see Kirki\App\Managers\PageManager::rename_stage_version()
292 */
293 public static function rename_stage_version() {
294 $post_id = HelperFunctions::sanitize_text( isset( $_POST['post_id'] ) ? $_POST['post_id'] : null );
295 $version_id = HelperFunctions::sanitize_text( isset( $_POST['version_id'] ) ? $_POST['version_id'] : null );
296 $name = HelperFunctions::sanitize_text( isset( $_POST['name'] ) ? $_POST['name'] : null );
297
298 if ( ! $post_id || ! $version_id || ! $name ) {
299 wp_send_json( false, 400 );
300 }
301
302 $staged_versions = self::get_all_staged_versions( $post_id, true, true );
303 $staged_versions = array_map(
304 function ( $item ) use ( $version_id, $name ) {
305 return ( is_array( $item ) && isset( $item['version'] ) && intval( $item['version'] ) === intval( $version_id ) )
306 ? array_merge( $item, array( 'name' => $name ) )
307 : $item;
308 },
309 $staged_versions
310 );
311
312 update_post_meta( $post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS, $staged_versions );
313 wp_send_json( $staged_versions );
314 }
315
316 /**
317 * @deprecated
318 * @see Kirki\App\Managers\PageManager::remove_stage_version()
319 */
320 public static function delete_stage_version() {
321 $post_id = HelperFunctions::sanitize_text( isset( $_POST['post_id'] ) ? $_POST['post_id'] : null );
322 $version_id = HelperFunctions::sanitize_text( isset( $_POST['version_id'] ) ? $_POST['version_id'] : null );
323
324 if ( ! $post_id || ! $version_id ) {
325 wp_send_json( false, 400 );
326 }
327 // Delete stage meta data
328 $meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY . '_random', $post_id, $version_id, true );
329 delete_post_meta( $post_id, $meta_key );
330
331 $meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY, $post_id, $version_id, true );
332 delete_post_meta( $post_id, $meta_key );
333
334 $meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS, $post_id, $version_id, true );
335 delete_post_meta( $post_id, $meta_key );
336
337 $meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS . '_random', $post_id, $version_id, true );
338 delete_post_meta( $post_id, $meta_key );
339
340 $meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_FONT_LIST, $post_id, $version_id, true );
341 delete_post_meta( $post_id, $meta_key );
342
343 $meta_key = self::get_staged_meta_name( 'kirki', $post_id, $version_id, true );
344 delete_post_meta( $post_id, $meta_key );
345
346 // delete the version from stage version list
347 $staged_versions = self::get_all_staged_versions( $post_id, true, true );
348 $staged_versions = array_values(
349 array_filter(
350 $staged_versions,
351 function ( $item ) use ( $version_id ) {
352 return ! ( is_array( $item ) && ! $item['publish'] && intval( $item['version'] ) === intval( $version_id ) );
353 }
354 )
355 );
356 update_post_meta( $post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS, $staged_versions );
357
358 wp_send_json( $staged_versions );
359 }
360
361 /**
362 * @deprecated
363 * @see Kirki\App\Managers\PageManager::get_staged_meta_name()
364 */
365 public static function get_staged_meta_name( $meta_name, $post_id, $stage_version = false, $stage_only = false ) {
366 $version = $stage_version;
367 if ( ! $version ) {
368 $version = self::get_most_recent_stage_version( $post_id, false );
369 } elseif ( ! $stage_only ) {
370 $published_version = self::get_published_stage_version( $post_id );
371 if ( $published_version && $version == $published_version ) {
372 return $meta_name;
373 }
374 }
375 return 'staged_' . $version . '_' . $meta_name;
376 }
377
378 public static function get_all_stage_related_meta_names( $post_id ) {
379 $versions = get_post_meta( $post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS, true );
380 if ( ! $versions ) {
381 return array();
382 }
383 $meta_names = array( KIRKI_META_NAME_FOR_STAGED_VERSIONS );
384 foreach ( $versions as $version ) {
385 $version_id = $version['version'];
386 $meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY . '_random', $post_id, $version_id, true );
387 $meta_names[] = $meta_key;
388 $meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY, $post_id, $version_id, true );
389 $meta_names[] = $meta_key;
390 $meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS, $post_id, $version_id, true );
391 $meta_names[] = $meta_key;
392 $meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS . '_random', $post_id, $version_id, true );
393 $meta_names[] = $meta_key;
394 $meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_FONT_LIST, $post_id, $version_id, true );
395 $meta_names[] = $meta_key;
396 $meta_key = self::get_staged_meta_name( 'kirki', $post_id, $version_id, true );
397 $meta_names[] = $meta_key;
398 }
399 return $meta_names;
400 }
401
402 private static function add_editor_names_into_stage_versions( $versions ) {
403 $versions = array_map(
404 function ( $item ) {
405 $user = get_user_by( 'id', $item['edited_by'] );
406 if ( ! $user ) {
407 return $item;
408 }
409 return array_merge( $item, array( 'edited_by' => $user->data->display_name ) );
410 },
411 $versions
412 );
413 return $versions;
414 }
415
416 /**
417 * @deprecated
418 * @see Kirki\App\Managers\PageManager::create_first_stage_version_if_empty()
419 */
420 private static function create_first_stage_version( $post_id ) {
421 $new_version = self::add_stage_version( $post_id, 1 );
422
423 $old_meta_key = KIRKI_GLOBAL_STYLE_BLOCK_META_KEY . '_random';
424 $old_data = get_post_meta( $post_id, $old_meta_key, true );
425 $new_meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY . '_random', $post_id, $new_version );
426 update_post_meta( $post_id, $new_meta_key, $old_data );
427
428 $new_meta_key = self::get_staged_meta_name( KIRKI_GLOBAL_STYLE_BLOCK_META_KEY, $post_id, $new_version );
429 update_post_meta( $post_id, $new_meta_key, array() );
430
431 $old_meta_key = KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS;
432 $old_data = get_post_meta( $post_id, $old_meta_key, true );
433 $new_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS, $post_id, $new_version );
434 update_post_meta( $post_id, $new_meta_key, $old_data );
435
436 $old_meta_key = KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS . '_random';
437 $old_data = get_post_meta( $post_id, $old_meta_key, true );
438 $new_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_STYLE_BLOCK_IDS . '_random', $post_id, $new_version );
439 update_post_meta( $post_id, $new_meta_key, $old_data );
440
441 $old_meta_key = KIRKI_META_NAME_FOR_USED_FONT_LIST;
442 $old_data = get_post_meta( $post_id, $old_meta_key, true );
443 $new_meta_key = self::get_staged_meta_name( KIRKI_META_NAME_FOR_USED_FONT_LIST, $post_id, $new_version );
444 update_post_meta( $post_id, $new_meta_key, $old_data );
445
446 $old_meta_key = 'kirki';
447 $old_data = get_post_meta( $post_id, $old_meta_key, true );
448 $new_meta_key = self::get_staged_meta_name( 'kirki', $post_id, $new_version );
449 update_post_meta( $post_id, $new_meta_key, $old_data );
450
451 return self::publish_stage_version( true, $post_id );
452 }
453
454 /**
455 * @deprecated
456 * @see Kirki\App\Managers\PageManager::set_last_edited_datetime_of_stage_version()
457 */
458 private static function update_last_edited_datetime_of_stage_version( $post_id ) {
459 $staged_versions = self::get_all_staged_versions( $post_id, true, true );
460 if ( count( $staged_versions ) === 0 ) {
461 return;
462 }
463
464 $datetime = new \DateTime( 'now', wp_timezone() );
465 $datetime = $datetime->format( 'Y-m-d H:i:s' );
466 $staged_versions[ count( $staged_versions ) - 1 ] = array_merge( $staged_versions[ count( $staged_versions ) - 1 ], array( 'last_updated' => $datetime ) );
467 update_post_meta( $post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS, $staged_versions );
468 return $staged_versions;
469 }
470
471 /**
472 * @deprecated
473 * @see Kirki\App\Managers\PageManager::add_stage_version()
474 */
475 private static function add_stage_version( $post_id, $version_number, $prev_versions = array(), $being_restored = false ) {
476 $format = 'F j g:i A';
477 $datetime = new \DateTime( 'now', wp_timezone() );
478 $date = $datetime->format( $format );
479 $datetime = $datetime->format( 'Y-m-d H:i:s' );
480
481 $new_version = array(
482 'version' => $version_number,
483 'edited_by' => get_current_user_id(),
484 'created_on' => $datetime,
485 'last_updated' => $datetime,
486 'name' => $being_restored ? '[Restored] ' . $being_restored['name'] : $date,
487 'publish' => false,
488 );
489 $prev_versions[] = $new_version;
490 update_post_meta( $post_id, KIRKI_META_NAME_FOR_STAGED_VERSIONS, $prev_versions );
491 return $version_number;
492 }
493
494 /**
495 * @deprecated
496 * @see Kirki\App\Managers\PageManager::get_most_recent_unpublished_stage_version()
497 */
498 public static function get_most_recent_unpublished_stage_id( $post_id ) {
499 $staged_versions = get_post_meta( $post_id, 'kirki_stage_versions', true ) ?: array();
500 $most_recent_stage_id = false;
501
502 foreach ( $staged_versions as $version ) {
503 if ( ! empty( $version['publish'] ) ) {
504 continue; // skip published versions
505 }
506 $most_recent_stage_id = $version['version'];
507 }
508
509 return $most_recent_stage_id;
510 }
511 }