Support

Account

Home Forums Bug Reports Calling get_field() within acf/init causes PHP notice

Solved

Calling get_field() within acf/init causes PHP notice

  • Calling get_field() within the acf/init action causes the PHP notice (in German):

    Notice: acf_get_value wurde fehlerhaft aufgerufen. 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 data. Learn how to fix this. Weitere Informationen: Debugging in WordPress (engl.) (Diese Meldung wurde in Version 5.11.1 hinzugefĆ¼gt.) in /var/www/clients/client1/web4/web/wp-includes/functions.php on line 5663

    But the documentation under
    https://www.advancedcustomfields.com/resources/acf-init/
    states “Fires after ACF is fully initialized.”.

  • Are you sure that the call to get_field() in that acf/init action function is what is causing the error? Does the error stop when you remove the action?

  • Yes I’m sure.
    I inserted
    debug_print_backtrace(); die();
    in acf-value-functions.php on line 351 and the stacktrace showed me exactly the call in the acf/init action.

    #0  acf_log_invalid_field_notice(Array ([ID] => 0,[key] => ,[label] => ,[name] => theme_mapbox_access_token,[prefix] => ,[type] => ,[value] => ,[menu_order] => 0,[instructions] => ,[required] => ,[id] => ,[class] => ,[conditional_logic] => ,[parent] => 0,[wrapper] => Array ([width] => ,[class] => ,[id] => ),[_name] => theme_mapbox_access_token,[_valid] => 1), acf_get_value) called at [/var/www/clients/client1/web4/web/wp-includes/class-wp-hook.php:303]
    #1  WP_Hook->apply_filters(, Array ([0] => Array ([ID] => 0,[key] => ,[label] => ,[name] => theme_mapbox_access_token,[prefix] => ,[type] => ,[value] => ,[menu_order] => 0,[instructions] => ,[required] => ,[id] => ,[class] => ,[conditional_logic] => ,[parent] => 0,[wrapper] => Array ([width] => ,[class] => ,[id] => ),[_name] => theme_mapbox_access_token,[_valid] => 1),[1] => acf_get_value)) called at [/var/www/clients/client1/web4/web/wp-includes/class-wp-hook.php:327]
    #2  WP_Hook->do_action(Array ([0] => Array ([ID] => 0,[key] => ,[label] => ,[name] => theme_mapbox_access_token,[prefix] => ,[type] => ,[value] => ,[menu_order] => 0,[instructions] => ,[required] => ,[id] => ,[class] => ,[conditional_logic] => ,[parent] => 0,[wrapper] => Array ([width] => ,[class] => ,[id] => ),[_name] => theme_mapbox_access_token,[_valid] => 1),[1] => acf_get_value)) called at [/var/www/clients/client1/web4/web/wp-includes/plugin.php:470]
    #3  do_action(acf/get_invalid_field_value, Array ([ID] => 0,[key] => ,[label] => ,[name] => theme_mapbox_access_token,[prefix] => ,[type] => ,[value] => ,[menu_order] => 0,[instructions] => ,[required] => ,[id] => ,[class] => ,[conditional_logic] => ,[parent] => 0,[wrapper] => Array ([width] => ,[class] => ,[id] => ),[_name] => theme_mapbox_access_token,[_valid] => 1), acf_get_value) called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/lib/advanced-custom-fields-pro/includes/acf-value-functions.php:72]
    #4  acf_get_value(options, Array ([ID] => 0,[key] => ,[label] => ,[name] => theme_mapbox_access_token,[prefix] => ,[type] => ,[value] => ,[menu_order] => 0,[instructions] => ,[required] => ,[id] => ,[class] => ,[conditional_logic] => ,[parent] => 0,[wrapper] => Array ([width] => ,[class] => ,[id] => ),[_name] => theme_mapbox_access_token,[_valid] => 1)) called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/lib/advanced-custom-fields-pro/includes/api/api-template.php:45]
    #5  get_field(theme_mapbox_access_token, options) called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/functions/mapbox/class-customtheme-mapbox.php:17]
    #6  Customtheme_Mapbox::{closure}(5) called at [/var/www/clients/client1/web4/web/wp-includes/class-wp-hook.php:303]
    #7  WP_Hook->apply_filters(, Array ([0] => 5)) called at [/var/www/clients/client1/web4/web/wp-includes/class-wp-hook.php:327]
    #8  WP_Hook->do_action(Array ([0] => 5)) called at [/var/www/clients/client1/web4/web/wp-includes/plugin.php:470]
    #9  do_action(acf/init, 5) called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/lib/advanced-custom-fields-pro/acf.php:332]
    #10 ACF->init() called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/lib/advanced-custom-fields-pro/includes/api/api-helpers.php:226]
    #11 acf_init() called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/lib/advanced-custom-fields-pro/includes/api/api-template.php:144]
    #12 acf_maybe_get_field(theme_header_nav_type, options) called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/lib/advanced-custom-fields-pro/includes/api/api-template.php:26]
    #13 get_field(theme_header_nav_type, options) called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/class-customtheme.php:127]
    #14 Customtheme::load_header_nav() called at [/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/functions.php:65]
    #15 include(/var/www/clients/client1/web4/web/wp-content/themes/pixelcube/functions.php) called at [/var/www/clients/client1/web4/web/wp-settings.php:546]
    #16 require_once(/var/www/clients/client1/web4/web/wp-settings.php) called at [/var/www/clients/client1/web4/web/wp-config.php:131]
    #17 require_once(/var/www/clients/client1/web4/web/wp-config.php) called at [/var/www/clients/client1/web4/web/wp-load.php:50]
    #18 require_once(/var/www/clients/client1/web4/web/wp-load.php) called at [/var/www/clients/client1/web4/web/wp-blog-header.php:13]
    #19 require(/var/www/clients/client1/web4/web/wp-blog-header.php) called at [/var/www/clients/client1/web4/web/index.php:17]
    
  • is the field (theme_mapbox_access_token) a field that is created by ACF?

  • This reply has been marked as private.
  • STOP!

    It seems, that this notice was caused by another statement in a totally different module.
    I’m still investigating.

  • Issue resolved.
    Sorry for the false alarm.

    Stacktrace #14 Customtheme::load_header_nav() had the get_field() before acf/init.
    After that ACF->init() is called (#10) and that fires all acf/init actions and after all the actions it shows the notice.
    This is somehow missleading. I guess it should already have stopped at #14.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.