Skip Navigation

[Resolved] Undefined constant IS_PROFILE_PAGE in PHP 8

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by nicholasG-2 2 years, 1 month ago.

Author
Posts
#2517091

Hi there,

I have a custom JS file that handles some user actions -- namely, changing a user's role. This has worked well for a couple of years, but with our necessary update to PHP 8, we now get this error when running either `update_user_meta()` or `wp_delete user()`, we're not sure which. It seems that the Access `save_user_options` hook gets run on one of these operations, and my guess is since we're not actually on a profile page, IS_PROFILE_PAGE is not defined, and in PHP 8, that now throws a fatal error.

The same issue is also mentioned in this thread, but is not resolved: https://toolset.com/forums/topic/undefined-constant/

Stack trace:

PHP Fatal error: Uncaught Error: Undefined constant "OTGS\Toolset\Access\Controllers\Filters\IS_PROFILE_PAGE" in /var/www/html/wp-content/plugins/types-access/application/controllers/filters/backend_filters.php:271
Stack trace:
#0 /var/www/html/wp-includes/class-wp-hook.php(310): OTGS\Toolset\Access\Controllers\Filters\BackendFilters->save_user_options(2628)
#1 /var/www/html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#2 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /var/www/html/wp-includes/user.php(2446): do_action('profile_update', 2628, Object(WP_User), Array)
#4 /var/www/html/wp-includes/user.php(2567): wp_insert_user(Array)
#5 /var/www/html/wp-content/mu-plugins/rhdwp-toolset-functions-shortcodes.php(164): wp_update_user(Array)
#6 /var/www/html/wp-includes/class-wp-hook.php(308): rhdwp_muse_approve_pending_user('')
#7 /var/www/html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#8 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#9 /var/www/html/wp-admin/admin-ajax.php(188): do_action('wp_ajax_rhdwp_m...')
#10 {main}
thrown in /var/www/html/wp-content/plugins/types-access/application/controllers/filters/backend_filters.php on line 271

A simple `is_defined()` check will likely fix this, but for now we've had to downgrade back to PHP 7.4.

Thanks for your assistance.

#2518711

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Nick

Thanks for the report.

I'm not going to dwell on the exact steps to reproduce this, as it's a clear weakness in the code that makes it vulnerable to triggering such an error (in the context of more recent PHP versions which are much less forgiving).

So I've escalated this directly to the developers, it's a very simple fix to check if the constant is defined first.

Although simple, we just released an Access update, and I'm not sure when the next one will be, so you might want to make such an edit in the plugin code yourself.

#2519093

Hi Nigel,

Thanks so much for the reply, and thanks for the heads up about the unknown date of the next release. I'll add a patch to check for the constant on our end for now, and will look forward to the next release!

Cheers,
Nick

#2519095

Looking forward to the next release with this patch. Happy to put a temporary patch in on our side in the meanwhile. Thanks.