Skip to content

Commit 37810e9

Browse files
committed
ACF connector post_updated callback updated
1 parent 4807d30 commit 37810e9

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"wordpress/wordpress": "^5.2",
2424
"wp-cli/wp-cli-bundle": "^2.2",
2525
"wp-coding-standards/wpcs": "^2.2",
26-
"wpackagist-plugin/advanced-custom-fields": "*",
26+
"wpackagist-plugin/advanced-custom-fields": "5.8.10",
2727
"wpsh/local": "^0.2.3",
2828
"xwp/wp-dev-lib": "^1.5"
2929
},

composer.lock

Lines changed: 11 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connectors/class-connector-acf.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,38 +196,29 @@ public function callback_post_updated( $post_id, $posts_after, $posts_before ) {
196196
return;
197197
}
198198

199-
$_new = maybe_unserialize( $posts_after->post_content );
200-
$_old = maybe_unserialize( $posts_before->post_content );
199+
$_new = maybe_unserialize( $posts_after->post_content ) ?? array();
200+
$_old = maybe_unserialize( $posts_before->post_content ) ?? array();
201201

202202
// Get updated settings.
203-
// Extract "location" property it will be compare separately.
204-
$_new_location = acf_extract_var( $_new, 'location' );
205-
$_old_location = acf_extract_var( $_old, 'location' );
206-
207-
$updated = array_diff_assoc( $_new, $_old );
208-
209-
// Check if "location" changed.
210-
if ( $_new_location !== $_old_location ) {
211-
$updated['location'] = $_new_location;
212-
$_old['location'] = $_old_location;
213-
}
203+
$updated_keys = $this->get_changed_keys( $_new, $_old );
204+
$updated_keys = empty( $updated_keys ) ? array_keys( $_new ) : $updated_keys;
214205

215206
// Process updated properties.
216-
if ( ! empty( $updated ) ) {
217-
foreach ( $updated as $prop => $value ) {
218-
$old_value = null;
219-
if ( empty( $value ) && is_array( $_old ) && ! empty( $_old[ $prop ] ) ) {
220-
$action = 'deleted';
221-
$old_value = $_old[ $prop ];
222-
} else {
223-
$action = 'updated';
224-
}
225-
226-
$this->log_prop( $action, $post_id, $posts_after, $prop, $value, $old_value );
207+
foreach ( $updated_keys as $prop ) {
208+
$old_value = null;
209+
$value = $_new[ $prop ];
210+
if ( empty( $value ) && is_array( $_old ) && ! empty( $_old[ $prop ] ) ) {
211+
$action = 'deleted';
212+
$old_value = $_old[ $prop ];
213+
} else {
214+
$action = 'updated';
227215
}
216+
217+
$this->log_prop( $action, $post_id, $posts_after, $prop, $value, $old_value );
228218
}
229219
}
230220

221+
231222
/**
232223
* Logs field/field group property changes (ACF v5 only).
233224
*

0 commit comments

Comments
 (0)