soflyy / oxygen-bugs-and-features

Bug Reports & Feature Requests for Oxygen
https://oxygenbuilder.com/
315 stars 29 forks source link

Dynamically inserting an image (Media Library > data) results in an error (Beta 2) #2804

Open andreslotta opened 2 years ago

andreslotta commented 2 years ago

Hey guys,

I was really happy reading the following line in the Beta 2 changelog: Tweak: Added dynamic data button to image ID field for Images using Media Library - (#4250)

Unfortunately this does not (yet) work as expected. See details below.

Describe the bug Trying to insert an image dynamically with the new "Media Library > data" option does not work and results in an error which makes the builder unusable. I tried it with a page's featured image as well as a custom image field (ACF) added to the page – same error for both variants.

Steps required to reproduce the bug

  1. Create a page
  2. Set a featured image for the page
  3. Open the page in Oxygen
  4. Add an image element
  5. On the image element choose "Media Library" as the source
  6. Click on "data"
  7. Choose "Featured Image"

Expected behaviour The image gets inserted dynamically.

Actual behaviour There is an error ("Error occured while loading attachment sizes"), the builder is grayed out and the loading gear spins indefinitely.

I attached a screenshot showing the issue. You can also see an error in the console. Hope this helps identifying the issue.

oxygen_beta_2-media_library-data-issue

Possible cause Since I am always interested in how things work behind the scenes I tried to find out what the problem could be. And I think I found the cause. So hopefully this information helps you to fix this bug more quickly:

In the file image.class.php – line 129 as of Beta 2 – you are doing a shortcode ([oxygen data='featured_image_id']) to dynamically get the image ID. In this shortcode's function (file oxygen-dynamic-shortcodes.php – line 278 as of Beta 2) you call the WordPress function get_post_thumbnail_id(). Without an argument this function relies on the global $post object. And here is the problem: There is no global $post object at the time of calling this function.

udoro commented 2 years ago

Having same issue

Spellhammer commented 2 years ago

There's something else at play here. I'm unable to reproduce on a Sandbox or on a local environment.

Do you have any other details you can provide? Can you provide us with a backup of the site where the problem is occurring?

Spellhammer commented 2 years ago

With @andreslotta 's help, narrowed this down to occurring only on pages set as the static home page. Reproduced and reported internally.

daniel-wimble commented 2 years ago

The same issue, happening across all pages.

sunnyt7 commented 2 years ago

I was able to easily reproduce this in the Oxygen sandbox.

  1. Create new sandbox install on the Oxygen site
  2. Choose the default installation
  3. Go to the About Me page (any page will cause the error)
  4. Click on the hero placeholder image, set to Media Library > Data, choose Post Featured Image

The gear will spin forever and you'll see a "error ocurred while loading attachment sizes" notice in the background.

Brandinwebdesign commented 2 years ago

I was able to easily reproduce this in the Oxygen sandbox.

1. Create new sandbox install on the Oxygen site

2. Choose the default installation

3. Go to the About Me page (any page will cause the error)

4. Click on the hero placeholder image, set to Media Library > Data, choose Post Featured Image

The gear will spin forever and you'll see a "error ocurred while loading attachment sizes" notice in the background.

Thit the same. Same Problom. Also by a test site of my self. Normal images wil load if you browse. If you use Data you got a error.