StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
792 stars 61 forks source link

Issue with ACF 5.11 (new version) - Can't access get_field from wordpress admin #147

Closed voyou-sbeaulieu closed 2 years ago

voyou-sbeaulieu commented 2 years ago

Hi we are using ACF for managing admin setting from showing up so we are calling a lot's of get_field() inside wordpress admin console. Everything was working fine until the 5.11 version. If we call the get_field from the website (front) we do have the data but in the admin console it's simply empty.

We are hooking the 'init' action for all fields and as I already said, everything is working fine on the 5.10.2 version of ACF.

We really need this functionality as all our admin settings are made by ACF field.

Just so you understands, we have ACF admin page with setting, theses settings are use to setup ACF inside page admin. For exemple, in the setting page, we have checkbox to select which flexible content is available for the pages. Currently the get_field to fill the flexible data is empty and before 5.11 it's was filled by the settings page options.

ghost commented 2 years ago

See this comment by lgladdy. Apparently 5.11 introduced a breaking change with respect to how values are returned by get_field(). Updating to 5.11.2 is reported to fix this issue.

erralb commented 2 years ago

Hi, I'm having the same issue, and for me version 5.11.2, 5.11.3 and 5.11.4 of ACF Pro did not solve the issue.

As a result, fields declared with acf-builder are not detected by WPML and fail to be sent to translation management.

Has anyone had the same problem or found a fix ?

stevep commented 2 years ago

@erralb I don't have any experience with WPML but maybe it has to do with when acf_add_local_field_group is getting called?

The ACF docs say to do it in the root of your functions.php outside a filter/action or within the acf/init action

https://www.advancedcustomfields.com/resources/register-fields-via-php/

Add within an action

The functions above can be used in the root of the functions.php file or within the acf/init action. This action was added in ACF v5.2.7 and is recommended.

The benefit of using this action is that the function is guaranteed to exist, and won’t run unless ACF is active.

voyou-sbeaulieu commented 2 years ago

Hi, just to add to this that we got a lot of support from ACF team and we manage to make a fix from their side so what's reported here is now fixed from AFC 5.11.3 and 5.11.4

We add also to change some get_field called outside of add_action('acf/init') to wrap them inside an add_action. After those adjustments, plus the patch everything is working fine with ACF / acf-builder.

The problem was that if the get_field is called before the 'acf/init' ACF does a init from this point and then ignore the call inside the 'acf/init' action as it's already init.

I highly recommande you to contact ACF PRO support team if this doesn't fix the issue, they are very knowledgeable of acf-builder.

erralb commented 2 years ago

Hi @stevep and @voyou-sbeaulieu and thank you very much for your answers.

I am already calling acf-builder functions within an acf/init action :

add_action('acf/init', 'my_acf_init');

The fields are working within the pages I can fill them, they just do not appear on the Field Groups on the ACF admin page.

I will contact the ACF Pro support about this thanks

stevep commented 2 years ago

@erralb unfortunately fields added via acf_add_local_field_group don't get added to the ACF Field Groups admin page.

From the function's documentation:

👨‍💻 Note: Field Groups and Fields registered via code will not be visible/editable via the “Edit Field Groups” admin page.

Since the fields are defined in PHP, you wouldn't be able to change them via the admin.

erralb commented 2 years ago

Yes thanks I saw that today... It makes sense, but it would be a nice feature.

I'm not sure it's working well with WPML / ACFML...