Backwards Compatability Break for the Image Field

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:

  1. You are using the image field in a block, and
  2. The template retrieves the image field’s value using the block_value() function or block_field() with the second argument of false, and
  3. 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 callExpected resultNotes
block_value( 'foo-valid-url' )returns attachment IDDifferent from before, used to return the URL
block_value( 'foo-invalid-url' )returns 0Also 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 URLSimply 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.

2 Replies to “Backwards Compatability Break for the Image Field”

  1. 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

    Reply

    1. 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.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *