PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.9.2.7
Advanced Custom Fields: Extended v0.9.2.7
0.9.2.7 0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / revisions.php
acf-extended / includes Last commit date
admin 3 months ago field-groups 3 months ago fields 1 week ago fields-settings 3 months ago forms 3 months ago locations 3 months ago modules 1 week ago screens 3 months ago acfe-deprecated-functions.php 2 years ago acfe-field-functions.php 3 months ago acfe-field-group-functions.php 3 months ago acfe-file-functions.php 1 year ago acfe-form-functions.php 3 months ago acfe-helper-array-functions.php 3 months ago acfe-helper-functions.php 3 months ago acfe-helper-multi-functions.php 3 months ago acfe-helper-string-functions.php 3 months ago acfe-meta-functions.php 3 months ago acfe-post-functions.php 3 months ago acfe-screen-functions.php 3 months ago acfe-template-functions.php 3 months ago acfe-term-functions.php 3 months ago acfe-user-functions.php 3 months ago acfe-wp-functions.php 3 years ago assets.php 3 months ago compatibility-acf-5.8.php 4 months ago compatibility-acf-5.9.php 3 months ago compatibility-acf-6.5.php 3 months ago compatibility-acf-6.8.6.php 1 week ago compatibility.php 3 months ago field-extend.php 4 months ago field.php 4 months ago hooks.php 3 months ago init.php 3 months ago local-meta.php 3 years ago media.php 3 months ago module-acf.php 3 months ago module-db.php 3 months ago module-l10n.php 3 months ago module-legacy.php 3 years ago module-manager.php 4 months ago module-post.php 3 months ago module-posts.php 4 months ago module-upgrades.php 3 years ago module.php 3 months ago multilang.php 3 months ago revisions.php 4 months ago screen.php 3 months ago settings.php 3 months ago template-tags.php 3 months ago third-party.php 3 years ago upgrades.php 3 months ago
revisions.php
181 lines
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 if(!class_exists('acfe_compatibility_acf_64')):
8
9 class acfe_compatibility_acf_64{
10
11 /**
12 * construct
13 */
14 function __construct(){
15
16 // bail early pre-ACF 6.4
17 if(!acfe_is_acf('6.4')){
18 return;
19 }
20
21 // check ACF revisions instance
22 if(!property_exists(acf(), 'revisions') || !acf()->revisions instanceof acf_revisions){
23 return;
24 }
25
26 /**
27 * Replace ACF revisions hooks
28 *
29 * Since ACF 6.4+, ACF copy post meta to revisions using a new logic inside acf_copy_postmeta()
30 * That new logic uses the new acf_get_meta_instance('post')->update_meta()
31 * This bypass the historical acf_update_metadata() which called the hook: acf/pre_update_metadata
32 * This hook is important, as it's used by the Performance module to save compressed meta in the revisions
33 *
34 * The code below that replace ACF hooks is identical to the native ACF 6.4+ code found in:
35 * /advanced-custom-fields-pro/includes/revisions.php
36 *
37 * They have been simply rewritten to call our custom acfe_copy_postmeta() where needed
38 * acfe_copy_postmeta() then use the classic logic with acf_update_metadata() > acf/pre_update_metadata
39 */
40 acfe_replace_action(
41 'wp_restore_post_revision',
42 array(acf()->revisions, 'wp_restore_post_revision'),
43 array($this, 'wp_restore_post_revision'),
44 10, 2
45 );
46
47 /**
48 * WP 6.4+
49 */
50 if(version_compare(get_bloginfo( 'version' ), '6.4', '>=')){
51
52 acfe_replace_action(
53 '_wp_put_post_revision',
54 array(acf()->revisions, 'maybe_save_revision'),
55 array($this, 'maybe_save_revision'),
56 10, 2
57 );
58
59 acfe_replace_filter(
60 'wp_save_post_revision_post_has_changed',
61 array(acf()->revisions, 'check_acf_fields_have_changed'),
62 array($this, 'check_acf_fields_have_changed'),
63 9, 3
64 );
65
66 }
67
68 }
69
70
71 /**
72 * check_acf_fields_have_changed
73 *
74 * Helps WordPress determine if fields have changed, and if in a legacy
75 * metabox AJAX request, copies the metadata to the new revision.
76 *
77 * @param boolean $post_has_changed True if the post has changed, false if not.
78 * @param WP_Post $last_revision The WP_Post object for the latest revision.
79 * @param WP_Post $post The WP_Post object for the parent post.
80 *
81 * @return bool
82 */
83 function check_acf_fields_have_changed($post_has_changed, $last_revision, $post){
84
85 // no performance mode enabled on this post
86 // fallback to ACF native method
87 if(!acfe_is_object_performance_enabled($post->ID) && method_exists(acf()->revisions, 'check_acf_fields_have_changed')){
88 return acf()->revisions->check_acf_fields_have_changed($post_has_changed, $last_revision, $post);
89 }
90
91 if(acf_maybe_get_GET('meta-box-loader', false)){
92 // We're in a legacy AJAX request, so we copy fields over to the latest revision.
93 $this->maybe_save_revision($last_revision->ID, $post->ID);
94
95 }elseif(acf_maybe_get_POST('_acf_changed', false)){
96 // We're in a classic editor save request, so notify WP that fields have changed.
97 $post_has_changed = true;
98 }
99
100 // Let WordPress decide for REST/block editor requests.
101 return $post_has_changed;
102
103 }
104
105
106 /**
107 * maybe_save_revision
108 *
109 * Copies ACF field data to the latest revision.
110 *
111 * @param $revision_id (int) The ID of the revision that was just created.
112 * @param $post_id (int) The ID of the post being updated.
113 *
114 * @return void
115 */
116 function maybe_save_revision($revision_id, $post_id){
117
118 // no performance mode enabled on this post
119 // fallback to ACF native method
120 if(!acfe_is_object_performance_enabled($post_id) && method_exists(acf()->revisions, 'maybe_save_revision')){
121 acf()->revisions->maybe_save_revision($revision_id, $post_id);
122 return;
123 }
124
125 // We don't have anything to copy over yet.
126 if(!did_action('acf/save_post')){
127 delete_metadata('post', $post_id, '_acf_changed');
128 delete_metadata('post', $revision_id, '_acf_changed');
129 return;
130 }
131
132 // Bail if this is an autosave in Classic Editor, it already has the field values.
133 if(acf_maybe_get_POST('_acf_changed') && wp_is_post_autosave($revision_id)){
134 return;
135 }
136
137 // Copy the saved meta from the main post to the latest revision.
138 acfe_save_post_revision($post_id);
139
140 }
141
142
143 /**
144 * wp_restore_post_revision
145 *
146 * This action will copy and paste the metadata from a revision to the post
147 *
148 * @param $post_id (int) the destination post
149 * @param $revision_id (int) the source post
150 *
151 * @return void
152 */
153 function wp_restore_post_revision($post_id, $revision_id){
154
155 // no performance mode enabled on this post
156 // fallback to ACF native method
157 if(!acfe_is_object_performance_enabled($post_id) && method_exists(acf()->revisions, 'wp_restore_post_revision')){
158 acf()->revisions->wp_restore_post_revision($post_id, $revision_id);
159 return;
160 }
161
162 // copy postmeta from revision to post (restore from revision)
163 acfe_copy_postmeta($revision_id, $post_id);
164
165 // Make sure the latest revision is also updated to match the new $post data
166 // get latest revision
167 $revision = acf_get_post_latest_revision($post_id);
168
169 // save
170 if($revision){
171
172 // copy postmeta from revision to latest revision (potentialy may be the same, but most likely are different)
173 acfe_copy_postmeta($revision_id, $revision->ID);
174 }
175 }
176
177 }
178
179 acf_new_instance('acfe_compatibility_acf_64');
180
181 endif;