array_key_exists(): Argument #2 ($array) must be of type array, WP_Term given
-
PHP8 with installed plugin Fusion Page Builder and when trying to create new page (the URL is example.com/wp-admin/post-new.php) you are getting the following error:
TypeError thrown
array_key_exists(): Argument #2 ($array) must be of type array, WP_Term given
Issue lies with the php function array_key_exists which is deprecated from PHP version 8 if the second parameter is an object. It works only on arrays.
To get around this, edit the problem lies in the file wp-content/plugins/fusion-builder/inc/helpers.php.
The lines 239-243:
if ( array_key_exists( 'slug', $cat ) && array_key_exists( 'name', $cat ) ) { $label = $cat->name . ( ( array_key_exists( 'count', $cat ) ) ? ' (' . $cat->count . ')' : '' ); $post_categories[ urldecode( $cat->slug ) ] = $label; } }
Replace with:
/** @var WP_Term $cat */ foreach ( $get_categories as $cat ) { if ( property_exists( $cat, 'slug' ) && property_exists( $cat, 'name' ) ) { $label = $cat->name . ( ( property_exists( $cat, 'count') ) ? ' (' . $cat->count . ')' : '' ); $post_categories[ urldecode( $cat->slug ) ] = $label; } }
Also the line 278-283:
if ( $get_terms && is_array( $get_terms ) ) { foreach ( $get_terms as $term ) { $label = $term->name . ( ( array_key_exists( 'count', $term ) ) ? ' (' . $term->count . ')' : '' ); $post_tags[ urldecode( $term->slug ) ] = $label; } }
Replace with the:
if ( $get_terms && is_array( $get_terms ) ) { foreach ( $get_terms as $term ) { /** @var WP_Term $term */ $label = $term->name . ( ( property_exists( $term, 'count' ) ) ? ' (' . $term->count . ')' : '' ); $post_tags[ urldecode( $term->slug ) ] = $label; } }
Maybe the person that created this plugin can issue the new version because there are a lot of broken WordPress installations around the Internet.
Thanks, Petar.
- The topic ‘array_key_exists(): Argument #2 ($array) must be of type array, WP_Term given’ is closed to new replies.