pixelbart/helpful

Crash in 4.5.10 in class-user.php

Closed this issue · 1 comments

Hello,

When editing certain posts with 4.5.10 installed, we are getting the following PHP error (PHP 8.1.4):

Error Details

An error of type E_ERROR was caused in line 58 of the file /home/hockintl/public_html/wp-content/plugins/helpful/core/helpers/class-user.php. Error message: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /home/hockintl/public_html/wp-content/plugins/helpful/core/helpers/class-user.php:58
Stack trace:
#0 /home/hockintl/public_html/wp-content/plugins/helpful/core/helpers/class-user.php(58): array_key_exists('helpful_user', NULL)
#1 /home/hockintl/public_html/wp-content/plugins/helpful/core/helpers/class-values.php(62): Helpful\Core\Helpers\User::get_user()
#2 /home/hockintl/public_html/wp-content/plugins/helpful/core/modules/class-frontend.php(203): Helpful\Core\Helpers\Values::get_defaults()
#3 /home/hockintl/public_html/wp-includes/class-wp-hook.php(307): Helpful\Core\Modules\Frontend->the_content('')
#4 /home/hockintl/public_html/wp-includes/plugin.php(189): WP_Hook->apply_filters('', Array)
#5 /home/hockintl/public_html/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php(103): apply_filters('the_content', '')
#6 /home/hockintl/public_html/wp-content/plugins/wordpress-seo/src/integrations/watchers/indexable-post-watcher.php(197): Yoast\WP\SEO\Builders\Indexable_Link_Builder->build(Object(Yoast\WP\SEO\Models\Indexable), '')
#7 /home/hockintl/public_html/wp-includes/class-wp-hook.php(309): Yoast\WP\SEO\Integrations\Watchers\Indexable_Post_Watcher->build_indexable(249548)
#8 /home/hockintl/public_html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
#9 /home/hockintl/public_html/wp-includes/plugin.php(474): WP_Hook->do_action(Array)
#10 /home/hockintl/public_html/wp-includes/post.php(4698): do_action('wp_insert_post', 249548, Object(WP_Post), true)
#11 /home/hockintl/public_html/wp-includes/post.php(4789): wp_insert_post(Array, false, true)
#12 /home/hockintl/public_html/wp-admin/includes/post.php(426): wp_update_post(Array)
#13 /home/hockintl/public_html/wp-admin/post.php(227): edit_post()
#14 {main}
thrown

It seems that $_SESSION is null, and therefore array_key_exists throws an exception. I fixed this with:

	if ( is_array($_SESSION) && array_key_exists( 'helpful_user', $_SESSION ) && '' !== trim( $_SESSION['helpful_user'] ) ) {

But maybe there's a better way or more WordPress-sanctioned way. Let me know if you need any other information.

Thanks,

Kevin Hock

Thank you as always for your detailed assistance! I have done exactly as you suggested. This is a good solution, WordPress itself can not do anything better.

Thank you very much!