Skip to content

Fix ACF site restoration after file fields - #110

Open
teolaz wants to merge 1 commit into
humanmade:masterfrom
teolaz:consecutive-acf-files-broken
Open

Fix ACF site restoration after file fields#110
teolaz wants to merge 1 commit into
humanmade:masterfrom
teolaz:consecutive-acf-files-broken

Conversation

@teolaz

@teolaz teolaz commented Aug 28, 2026

Copy link
Copy Markdown

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:

  1. A file field
  2. An image field

The image field was saved correctly in the subsite database, but after updating and reloading the page, it appeared empty in the admin interface.

Image field appearing empty after saving

Cause

While rendering an ACF file field, the plugin switches to the central media site at priority 0.

The original site is currently restored at the beginning of the next field's acf/render_field hook. However, ACF loads each field's value before firing that render hook.

The resulting flow is:

  1. ACF loads the first file field value from the subsite.
  2. Network Media Library switches to the central media site.
  3. ACF renders the file field.
  4. The central media site remains active.
  5. ACF loads the next field's value before its render hook runs.
  6. The value is therefore loaded using the central site's database instead of the original subsite's database.
  7. Network Media Library restores the original site, but at that point the next field has already received an empty or incorrect value.

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 file field.

ACF's built-in field renderer runs at priority 9, so the restoration is registered at priority 10. 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:

  • Before the fix, the second field rendered with an empty hidden input.
  • After the fix, the field retained the attachment ID stored in the subsite.
  • The updated PHP file passes syntax validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant