multisite-global-media icon indicating copy to clipboard operation
multisite-global-media copied to clipboard

[Bug]: ACF image doesn't get properly stored or retrieved when using in ACF and wp_get_attachment_image()

Open stefthoen opened this issue 1 year ago • 0 comments

Description of the bug

I'm using this plugin together with ACF. If I use a normal ACF Image field on a page and try to retrieve a globally shared image with wp_get_attachment_image(), I get an empty string as a return value.

I did some exploring and acfLoadValue() gets triggered and the image gets stored in ACF's cache, but it's either unsuccessful in storing or retrieving the image from said cache, and I think the issue is storing the image, because just the image id is getting stored. If I var_dump the $formatted value in ACF/Image.php I get only the image id.

If I 'manually' run switch_to_blog(1) before wp_get_attachment_image() and restore_blog() after, I'm successful in retrieving the image, but that seems rather cumbersome and invasive.

What would be the best way to debug this issue? How should the image be stored in the ACF_Data store?

Reproduction instructions

  1. Add a globally shared image with ACF
  2. Use wp_get_attachment_image() to load the image.

Expected behavior

I'm successful loading a globally shared image in a ACF with wp_get_attachment_image().

Environment info

  • The latest release of this plug-in
  • Any browser
  • Roots Sage theme

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

stefthoen avatar May 02 '23 12:05 stefthoen