Skip to content

Fixed issue where the hidden input field would result in double saving of the user profile #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions fields/class-npx-acf-field-image-aspect-ratio-crop-v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,32 @@ function __construct($settings)
// Also options pages, taxonomies etc have ACF generated special post id that we don't know before save hook
$this->temp_post_id = wp_generate_uuid4();

// Store temporary post id in a hidden field
// Store temporary post id in a hidden field, only add the hidden field if we are using a field of type 'image_aspect_ratio_crop', this to prevent double saving of user profile
add_action(
'acf/input/form_data',
function () {
echo "<input type='hidden' name='aiarc_temp_post_id' value='$this->temp_post_id'>";
},
10,
1
);
'acf/input/form_data',
function () {
// Get all ACF fields on the current form
$fields = acf_get_fields(acf_get_form_data('screen'));

// Flag to check if the specific field type is found
$has_special_field = false;

// Check if any field is of the type 'image_aspect_ratio_crop'
foreach ($fields as $field) {
if (isset($field['type']) && $field['type'] === 'image_aspect_ratio_crop') {
$has_special_field = true;
break;
}
}

// Only add the hidden input if the specific field type is present
if ($has_special_field) {
echo "<input type='hidden' name='aiarc_temp_post_id' value='$this->$temp_post_id'>";
}
},
10,
1
);

// filters
add_filter('get_media_item_args', [$this, 'get_media_item_args']);
Expand Down