Fix ACF site restoration after file fields - #110
Open
teolaz wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi!
I found an issue while using Network Media Library with ACF/SCF on a multisite subsite.
In my case, I had two consecutive media fields:
filefieldimagefieldThe image field was saved correctly in the subsite database, but after updating and reloading the page, it appeared empty in the admin interface.
Cause
While rendering an ACF
filefield, the plugin switches to the central media site at priority0.The original site is currently restored at the beginning of the next field's
acf/render_fieldhook. However, ACF loads each field's value before firing that render hook.The resulting flow is:
filefield value from the subsite.filefield.This is especially visible when an image field immediately follows a file field. The value remains stored in the subsite database, but ACF renders an empty hidden input. A later update can consequently remove the stored value.
Fix
This PR restores the originating site immediately after ACF finishes rendering the
filefield.ACF's built-in field renderer runs at priority
9, so the restoration is registered at priority10. The existing restoration at the beginning of the next field is preserved as a fallback.This ensures that ACF loads the following field from the correct site's database.
Verification
I reproduced the issue on a multisite subsite and confirmed that: