Closed SergiArias closed 2 years ago
Probably related: https://github.com/AdvancedCustomFields/acf/issues/570
I don't have any sites updated to ACF 5.11 yet so I'm not entirely sure what's causing this.
The first thing I'd try changing around is https://github.com/Log1x/acf-composer/blob/master/src/Composer.php#L80-L88 to see if it's a priority issue. I know I originally went to use acf/init
and something didn't work as intended.
I don't have any sites updated to ACF 5.11 yet so I'm not entirely sure what's causing this.
The first thing I'd try changing around is https://github.com/Log1x/acf-composer/blob/master/src/Composer.php#L80-L88 to see if it's a priority issue. I know I originally went to use
acf/init
and something didn't work as intended.
I did change the priority as ACF team suggests, but still, getfield('field', 'user' . $user_id) doesn't work anymore and it has to be retrieved with get_user_meta. Probably is a collateral bug from the safety measures they added in 5.11.
Hey everyone!
We made some changes in today's ACF 5.11.2 release which should mitigate this issue, although we would still advise that acf-composer is updated to make sure fields are correctly initialised and registered before get_field is used.
Whilst you'll be returned data in ACF 5.11.2, things like return formats have always been broken if ACF isn't able to understand what field is being requested by get_field.
Can anyone on the latest ACF confirm that this stuff is no longer an issue?
@Log1x for me it doesnt work. I have a problem with fields from Option Page.
It's weird. I only have a problem on the online production server (litespeed). The local server is functioning properly (apache). I work with Sage 10 and PHP 7.4.
I have a many notices: Advanced Custom Fields PRO - We've detected one or more calls to retrieve ACF field values before ACF has been initialized, resulting in missing data.
I have a medium size project with ACF 5.9. After update to 5.11.4 i couldn't find all the reasons for these notifications., but i have one example in app/setup.php (Sage 10):
This doesnt work
$compare_car_page = get_field('compare-car-page','option');
$compare_car_page_url = (is_array($compare_car_page)) ? $compare_car_page['url'] : false;
define('COMPARE_CAR', $compare_car_page_url);
This works fine
add_action('acf/init', function() {
$compare_car_page = get_field('compare-car-page','option');
$compare_car_page_url = (is_array($compare_car_page)) ? $compare_car_page['url'] : false;
define('COMPARE_CAR', $compare_car_page_url);
});
And if i have DEBUG = true i can't open wordpress admin panel.
Cannot modify header information - headers already sent by (output started at /home/klient.dhosting.pl/imaggo/skoda2.imaggo-work.pl/public_html/wp-includes/functions.php:5663)
I tried to change this code from acf-composer:
add_filter('init', function () use ($callback) {
if ($callback) {
$callback();
}
acf_add_local_field_group(
$this->build($this->fields)
);
}, 20);
to this
add_filter('acf/init', function () use ($callback) {
if ($callback) {
$callback();
}
acf_add_local_field_group(
$this->build($this->fields)
);
}, 20);
or this
add_filter('acf/init', function () use ($callback) {
if ($callback) {
$callback();
}
acf_add_local_field_group(
$this->build($this->fields)
);
}, 10);
and its doesnt work with sage 10-dev. Maybe Litespeed is problem for me? Localhost based on Apache works fine.
I am working with php 8.0 and so far everything is working flawlessly in my local server. If I find bugs in production like @grzesiek1owline I will file them.
@Log1x @SergiArias I tested this also on apache server and i have the same problems. Only local server works fine.
I also have issues most likely related to this topic. I'm at:
First time I noticed a problem was when admin menu items for acf options pages suddenly started directing to 404 pages (.../wp/wp-admin/option-page-slug
instead of .../wp/wp-admin/admin.php?page=option-page-slug
). Strangely, development and staging worked fine, production had this issue. All env's have PHP v7.4.27 and plugin versions from composer.json.
At some point I started noticing the following logs (same additional log entry every ~ 15 sec) in development env storage/logs (this is when I troubleshooted my way here):
[2022-01-06 14:12:47] development.WARNING: Skipping provider [Log1x\AcfComposer\Providers\AcfComposerServiceProvider] because it encountered an error. {"package":"log1x/acf-composer","provider":"Log1x\\AcfComposer\\Providers\\AcfComposerServiceProvider","error":"acf_get_value encountered an <strong>error</strong>. <strong>Advanced Custom Fields PRO</strong> - We've detected one or more calls to retrieve ACF field values before ACF has been initialized. This is not supported and can result in malformed or missing data. <a href=\"https://www.advancedcustomfields.com/resources/acf-field-functions/\" target=\"_blank\">Learn how to fix this</a>. Lisainfo: <a href=\"https://wordpress.org/support/article/debugging-in-wordpress/\">WordPressi silumine</a>. (See teade lisati versioonis 5.11.1.)","help":"https://roots.io/docs/acorn/troubleshooting"}
I looked up that at this point I had ACF Pro v5.11.4.
Another thing I noticed with ACF Pro v5.11.4 was that I wasn't able to use wp acorn acf:options MyOption
since I got this error:
There are no commands defined in the "acf" namespace.
For testing purposes I reverted back to ACF Pro v5.11 and issues were gone.
I'll update if anything else pops up.
Will try to work on this next week.
Another thing I noticed with ACF Pro v5.11.4 was that I wasn't able to use
wp acorn acf:options MyOption
since I got this error:
This should be fixed in the latest Acorn. It is more or less a caching issue.
Advanced Custom Fields PRO - We've detected one or more calls to retrieve ACF field values before ACF has been initialized, resulting in missing data.
Having a hard time reproducing this locally. Will keep trying.
Is this reproducible for any of you by setting your local environment to production
?
@Log1x yes, i can. I added true/false field in option page. In setup.php (sage 10 beta) i check is this field is true and xdebug console show error.
We've detected one or more calls to retrieve ACF field values before ACF has been initialized, resulting in missing data. Learn how to fix this.)
can you give me an example of how you're using this in setup.php? is it inside of a hook?
I use get_field('xyz', 'option') in class. I dont use any hooks.
<?php
namespace App\Fields\Partials;
use Log1x\AcfComposer\Partial;
use StoutLogic\AcfBuilder\FieldsBuilder;
class SMTP extends Partial
{
public function fields()
{
$sMTP = new FieldsBuilder('smtp', ['title' => __('Poczta SMTP', THEME_SLUG)]);
$sMTP
->addTrueFalse('smtp-run-smtp', ['label' => __('Uruchom SMTP', THEME_SLUG), 'ui' => 1]);
return $sMTP;
}
}
setup.php
include 'setup/Mailing.php';
$mailBySMTP = new Mailing();
$mailBySMTP->init();
Mailing.php
class Mailing
{
public function __construct()
{
$this->smtp_status = false;
}
public function init()
{
if (!class_exists('acf')) {
return false;
}
$this->smtp_status = get_field('smtp-run-smtp', 'option');
/* ....*/
}
}
I think per ACF's changes you now need to put things like that into a hook. I'm not sure this is ACF Composer-related. Your code in setup.php
from what I can tell is being called before ACF is loaded.
try:
add_filter('init', function () {
include 'setup/Mailing.php';
$mailBySMTP = new Mailing();
$mailBySMTP->init();
});
it should still work as intended and no longer give you an error.
I am encoutering the same problem , I have this code in app\setup.php before :
if( class_exists('acf') ){
if(is_admin()){
add_action('init', function () {
collect(glob(config('theme.dir').'/app/fields/*.php'))->map(function ($field) {
return require_once($field);
})->map(function ($field) {
if ($field instanceof FieldsBuilder) {
acf_add_local_field_group($field->build());
}
});
});
}else{
add_action('wp', function () {
collect(glob(config('theme.dir').'/app/fields/*.php'))->map(function ($field) {
return require_once($field);
})->map(function ($field) {
if ($field instanceof FieldsBuilder) {
acf_add_local_field_group($field->build());
}
});
});
}
}
Then I have changed it to :
if( class_exists('acf') ){
if(is_admin()){
add_action('init', function () {
collect(glob(config('theme.dir').'/app/fields/*.php'))->map(function ($field) {
return require_once($field);
})->map(function ($field) {
if ($field instanceof FieldsBuilder) {
add_action('acf/init', function() use ($field) {
acf_add_local_field_group($field->build());
});
}
});
});
}else{
add_action('wp', function () {
collect(glob(config('theme.dir').'/app/fields/*.php'))->map(function ($field) {
return require_once($field);
})->map(function ($field) {
if ($field instanceof FieldsBuilder) {
add_action('acf/init', function() use ($field) {
acf_add_local_field_group($field->build());
});
}
});
});
}
}
The problem showing is :
acf_get_value was called incorrectly. Advanced Custom Fields PRO - We've detected one or more calls to retrieve ACF field values before ACF has been initialized. This is not supported and can result in malformed or missing
I have upgraded to ACF 6.0 Do anyone has an idea about this ? Thanks in advance
What is with the is_admin()
conditional? It's unnecessary. Also, I think the wp
filter is too early for ACF.
I am starting to have a lot of problems with ACF 5.11.
Although a fresh install of wp and acf composer works as expected, one with a lot of fields don't, and the errors point directly to acf composer (development.WARNING: Skipping provider [Log1x\AcfComposer\Providers\AcfComposerServiceProvider] because it encountered an error. {"package":"log1x/acf-composer","provider":"Log1x\AcfComposer\Providers\AcfComposerServiceProvider","error":"acf_get_value s'ha cridat de manera incorrecta. Advanced Custom Fields PRO - We've detected one or more calls to retrieve ACF field values before ACF has been initialized, resulting in missing data. <a href=\"https://www.advancedcustomfields.com/resources/acf-field-functions/\" target=\"_blank\">Learn how to fix this.).
I am still trying to understand where is everything coming from, but for example, using get_field from a user page no longer works (we have to use get_user_meta instead), and is not a documented breaking change in the acf page, so I am suspecting that more bugs are there to come.
Probably everything is 100% delicious brains fault, but just in case I post it as a bug until everything gets cleared. I will update any other findings.