Hi everyone,
If you’re using the image field in Block Lab, you should be aware of a minor backwards compatibility break in the latest plugin update.
The changes are related to when using the block_value()
function with the image field. This function now returns an integer attachment ID. Previously it returned the attachment URL.
This breaking change will only occur if:
- You are using the image field in a block, and
- The template retrieves the image fieldâs value using the block_value() function or block_field() with the second argument of
false
, and - The image field has been used in post content with an external URL (not a file hosted in your Media Library).
This change was made as it gives more versatility to what you can do when interacting with the field in your block templates.
The table below gives a good breakdown of how things work moving forward.
Function call | Expected result | Notes |
---|---|---|
block_value( 'foo-valid-url' ) | returns attachment ID | Different from before, used to return the URL |
block_value( 'foo-invalid-url' ) | returns 0 | Also different from before. Returns 0 if the URL isn’t on the same site, or if it doesn’t match an existing attachment (image). |
block_field( 'foo-valid-or-invalid-url' ) | echoes the string URL | Simply echoes the string (no change from previous behavior) |
When passing a second argument of false
to block_field(), like block_field( âfoo-fieldâ, false), please see the âFunction callâ documentation above for block_value().
block_field( 'foo-url' )
will have the same result as before, even if it used to have an external URL.
If the URL was previously for an external image, not an image hosted in the Media Library, block_value( 'foo-url' )
will now return 0
.
If you have any questions, please don’t hesitate to ask. Additionally, we encourage you to update the plugin on a testing environment or at least have a site backup ready to roll back to should you notice anything broken.
Hi!
I am using your plugin in my development. After you changed image type behaviour I get an issue. Where I using it, the image url always echoed. E.g. when I set a variable value with block_value I get an echoed url.
Please check it!
Kind regards,
Jozsef
Hi Jozsef â thanks for getting in touch. We try not to do tech support via the comments section on our blog posts, so I’ll reach out to you via email to try to help you resolve the issue.