Skip to content

Commit

Permalink
ACF connector post_updated callback updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Jul 2, 2020
1 parent 6be4f3f commit ef3cb53
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"wordpress/wordpress": "^5.2",
"wp-cli/wp-cli-bundle": "^2.2",
"wp-coding-standards/wpcs": "^2.2",
"wpackagist-plugin/advanced-custom-fields": "*",
"wpackagist-plugin/advanced-custom-fields": "5.8.10",
"wpsh/local": "^0.2.3",
"xwp/wp-dev-lib": "^1.5"
},
Expand Down
23 changes: 11 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 15 additions & 24 deletions connectors/class-connector-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,38 +196,29 @@ public function callback_post_updated( $post_id, $posts_after, $posts_before ) {
return;
}

$_new = maybe_unserialize( $posts_after->post_content );
$_old = maybe_unserialize( $posts_before->post_content );
$_new = maybe_unserialize( $posts_after->post_content ) ?? array();
$_old = maybe_unserialize( $posts_before->post_content ) ?? array();

// Get updated settings.
// Extract "location" property it will be compare separately.
$_new_location = acf_extract_var( $_new, 'location' );
$_old_location = acf_extract_var( $_old, 'location' );

$updated = array_diff_assoc( $_new, $_old );

// Check if "location" changed.
if ( $_new_location !== $_old_location ) {
$updated['location'] = $_new_location;
$_old['location'] = $_old_location;
}
$updated_keys = $this->get_changed_keys( $_new, $_old );
$updated_keys = empty( $updated_keys ) ? array_keys( $_new ) : $updated_keys;

// Process updated properties.
if ( ! empty( $updated ) ) {
foreach ( $updated as $prop => $value ) {
$old_value = null;
if ( empty( $value ) && is_array( $_old ) && ! empty( $_old[ $prop ] ) ) {
$action = 'deleted';
$old_value = $_old[ $prop ];
} else {
$action = 'updated';
}

$this->log_prop( $action, $post_id, $posts_after, $prop, $value, $old_value );
foreach ( $updated_keys as $prop ) {
$old_value = null;
$value = $_new[ $prop ];
if ( empty( $value ) && is_array( $_old ) && ! empty( $_old[ $prop ] ) ) {
$action = 'deleted';
$old_value = $_old[ $prop ];
} else {
$action = 'updated';
}

$this->log_prop( $action, $post_id, $posts_after, $prop, $value, $old_value );
}
}


/**
* Logs field/field group property changes (ACF v5 only).
*
Expand Down

0 comments on commit ef3cb53

Please sign in to comment.