acf-extended / ACF-Extended

🚀 All-in-one enhancement suite that improves WordPress & Advanced Custom Fields
https://www.acf-extended.com
239 stars 27 forks source link

PHP 8 E_WARNING: Trying to access array offset on value of type bool #89

Closed huubl closed 2 years ago

huubl commented 3 years ago

Hi,

I get a warning using PHP 8:

ErrorException (E_WARNING)
Trying to access array offset on value of type bool

https://github.com/acf-extended/ACF-Extended/blob/dc24837331734fd43da07d1d5a1fe1d9021c3586/includes/modules/dev.php#L735

Can be fixed by using:

if(isset($field_group['ID'])){

or something like $field_group_id = $field_group['ID'] ?? ''; using null coalescing operator:

if($field_group){

    $field_group_title = $field_group['title'] ?? '';
    $field_group_id = $field_group['ID'] ?? '';

    // no id setting, try to get raw field group from db
    if(!$field_group_id){
        $field_group = acf_get_raw_field_group($field_group['key']);
    }

    // found db field group
    if($field_group_id){

        $post_status = get_post_status($field_group['ID']);

        if($post_status === 'publish' || $post_status === 'acf-disabled'){

            $field_group_title = '<a href="' . admin_url('post.php?post=' . $field_group['ID'] . '&action=edit') . '">' . $field_group['title'] . '</a>';

        }

    }

}
acf-extended commented 2 years ago

Hello,

Thanks for the feedback!

Yes, this warning will be fixed in the next patch. In the meantime you can apply the fix by yourself following this instruction:

In the file: /acf-extended-pro/includes/modules/dev.php line:735

Change the line:

if($field_group['ID']){

To:

if($field_group && $field_group['ID']){

Sorry for the inconvenience.

Regards.