AdvancedCustomFields / AdvancedCustomFields/acf

Would it be possible to update acf_setup_meta to allow an empty parameter?

Open
#733 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

I have been using the following code in a parse_blocks callback in a large number of themes I've created - primarily to take some image fields and generate optimized image sizes at the point the post is saved.

acf_setup_meta( $block['attrs']['data'], $block['attrs']['id'], true );
// some get_field code
acf_reset_meta($block['attrs']['id']);

This type of code has been regularly referenced in tutorials etc online (and even by Elliot on his own Twitter account).

With ACF 6, due to the missing id parameter, this now fails, as get_field calls won't return any data.

I've discovered that there was no specific need to use the block id; when you're temporarily setting and unsetting the meta, you can in fact using any id at all, eg:

acf_setup_meta( $block['attrs']['data'], 'tempdata', true );
// some get_field code
acf_reset_meta('tempdata');

Now, I could go back through 100+ custom themes we've developed with Gutenberg, and fix this after the breaking ACF 6 change, but it's a bit frustrating.

But is it possible that you could adjust the plugin so that it works if the id parameter passed to these functions is empty? That way, the original code will continue to work exactly as it used to.

This would be an easy change on your end - at the start of both function calls, if the parameter is empty, set it to something like 'tempdata' yourself.

This would only cause problems if you intentionally call the functions with a blank parameter somewhere else, and intentionally don't want the fields set up in these cases. But this seems highly unlikely.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the definitions of acf_setup_meta and acf_reset_meta, then review how their id parameters are handled when called from a parse_blocks callback. Verify the behavior with an empty id and confirm that temporary get_field lookups still work and can be reset without an explicit block id.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.