acf-extended / ACF-Extended

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

Default return value on Code Editor field throws fatal error in PHP 8.1 #113

Closed joedarsh closed 1 year ago

joedarsh commented 1 year ago

Describe the bug When creating a new Code Editor field, by default it has no return value selected. This causes an empty string to be passed as the second argument to the in_array call on line 218 of /includes/fields/field-code-editor.php (instead of an array) and throws a fatal error (php 8.1). This issue may exist in other fields, but have only tested on Code Editor field.

To Reproduce Create a new Code Editor field. Leave return value checkboxes unselected. Load field value on front end using get_field().

Expected behavior A sensible default should be applied when no return value is selected which allows it to render without breaking the page, or it shouldn't be possible to have no return value selected.

WordPress & ACF WordPress version: 6.1.1 ACF Pro version: 6.0.6 PHP version: 8.1

acf-extended commented 1 year ago

Hello,

Thanks for the feedback and the detailed report.

In fact, this issue appear on newly created/modified Code Editor field since the latest patch. This will be fixed in the upcoming update which should come out today.

In the meantime, you can fix it by yourself by adding this code in your theme’s functions.php file:

// acfe 0.8.9.1 fix return format in code editor
add_filter('acf/load_field/type=acfe_code_editor', 'my_code_editor_fix_return_format');
function my_code_editor_fix_return_format($field){

    // force array
    if(isset($field['return_format'])){
        $field['return_format'] = acf_get_array($field['return_format']);
    }

    // return field
    return $field;

}

Sorry for the inconvenience.

Have a nice day!

Regards.

acf-extended commented 1 year ago

Hello,

Just a heads up to let you know that this issue has been fixed in the latest 0.8.9.2 patch. Please ugrade your version.

Note that you can remove the hotfix I provided above.

Have a nice day!

Regards.