AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
823 stars 168 forks source link

Trying to access array offset on value of type null #847

Closed lpender closed 1 year ago

lpender commented 1 year ago

Hi!

I am on the latest: v6.1.7

I have many of these warnings each time I refresh the page:

[28-Jun-2023 21:55:41 UTC] PHP Warning:  Trying to access array offset on value of type null in XXXXX/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php on line 61
[28-Jun-2023 21:55:41 UTC] PHP Warning:  Trying to access array offset on value of type null in XXXXX/wp-content/plugins/advanced-custom-fields/includes/acf-field-functions.php on line 62

Inspection shows that the following line in acf-field-functions.php:58 is destroying the $field object.

    $field = apply_filters( 'acf/load_field', $field );

Object before:

array (
  'ID' => XXXXXX,
  'key' => 'field_XXXXXX',
  'label' => 'Open in a new tab',
  'name' => 'open_new_tab',
  'aria-label' => '',
  'prefix' => 'acf',
  'type' => 'select',
  'value' => NULL,
  'menu_order' => 1,
  'instructions' => '',
  'required' => 0,
  'id' => '',
  'class' => '',
  'conditional_logic' => 0,
  'parent' => XXXXXX,
  'wrapper' => 
  array (
    'width' => '',
    'class' => '',
    'id' => '',
  ),
  'choices' => 
  array (
    'auto' => 'auto',
    'manual' => 'manual',
  ),
  'default_value' => false,
  'allow_null' => 0,
  'multiple' => 0,
  'ui' => 0,
  'return_format' => 'value',
  'ajax' => 0,
  'placeholder' => '',
  '_name' => 'open_new_tab',
  '_valid' => 1,
)

Object after:

NULL

Some objects it does not destroy, i.e.

Object before:

array (
  'ID' =>  XXXXX,
  'key' => 'field_XXXXXXXX',
  'label' => 'Select the current environment',
  'name' => 'environment',
  'aria-label' => '',
  'prefix' => 'acf',
  'type' => 'radio',
  'value' => NULL,
  'menu_order' => 59,
  'instructions' => '',
  'required' => 0,
  'id' => '',
  'class' => '',
  'conditional_logic' => 0,
  'parent' => XXXXXX,
  'wrapper' => 
  array (
    'width' => '',
    'class' => '',
    'id' => '',
  ),
  'choices' => 
  array (
    'AB' => 'Example',
    'BA' => 'Example',
  ),
  'allow_null' => 0,
  'other_choice' => 0,
  'default_value' => '',
  'layout' => 'vertical',
  'return_format' => 'value',
  'save_other_choice' => 0,
  '_name' => 'environment',
  '_valid' => 1,
)

Object after:

array (
  'ID' => XXXXXX,
  'key' => 'field_XXXXXXXXXX',
  'label' => 'Select the current environment',
  'name' => 'environment',
  'aria-label' => '',
  'prefix' => 'acf',
  'type' => 'radio',
  'value' => NULL,
  'menu_order' => 59,
  'instructions' => '',
  'required' => 0,
  'id' => '',
  'class' => '',
  'conditional_logic' => 0,
  'parent' => 405098,
  'wrapper' => 
  array (
    'width' => '',
    'class' => '',
    'id' => '',
  ),
  'choices' => 
  array (
    'AB' => 'Example',
    'BA' => 'Example',
  ),
  'allow_null' => 0,
  'other_choice' => 0,
  'default_value' => '',
  'layout' => 'vertical',
  'return_format' => 'value',
  'save_other_choice' => 0,
  '_name' => 'environment',
  '_valid' => 1,
)

Can someone at least point me to the acf/load_field filter or tell me what it's doing ?

mattgrshaw commented 1 year ago

Hi @lpender,

The acf/load_field function is used to change the field settings after it has been loaded from the database. ACF does make use of this function internally, but it is also used by third party plugins and themes.

If you have a dev/test environment where you're able to replicate the issue, you may want to try temporarily deactivating any other plugins and switching to a default theme like 2020 to see if the issue persists.

If that doesn't help, feel free to reach out to support@advancedcustomfields.com so we can troubleshoot this further.

lpender commented 1 year ago

Hi @mattgrshaw can you point me to where in the code the acf/load_field function is declared? I couldn't seem to find it. I'd like to do some debugging myself before I take it to support.

Thanks!