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
- 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|
|returns attachment ||Different from before, used to return the URL|
|returns ||Also different from before. Returns |
|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
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.