Skip to content

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

Description

@stefthoen

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions