cedaro / satispress

Expose installed WordPress plugins and themes as Composer packages.
500 stars 48 forks source link

Uncaught TypeError: strpos() expects parameter 1 to be string, int given in src/Authentication/ApiKey/Repository.php:96 #133

Closed kupoback closed 3 years ago

kupoback commented 3 years ago

As the title states, there's an issue I'm coming across with a TypeError. If I set the $meta_key to a string then it works as intended, unless there's a possible alternative issue going on?

Error

[20-Jul-2020 21:46:13 UTC] PHP Fatal error:  Uncaught TypeError: strpos() expects parameter 1 to be string, int given in web/app/plugins/satispress/src/Authentication/ApiKey/Repository.php:96
Stack trace:
#0 web/app/plugins/satispress/src/Authentication/ApiKey/Repository.php(96): strpos(1, 'satispress_api_...')
#1 web/app/plugins/satispress/src/Screen/EditUser.php(87): SatisPress\Authentication\ApiKey\Repository->find_for_user(Object(WP_User))
#2 web/wp/wp-includes/class-wp-hook.php(287): SatisPress\Screen\EditUser->enqueue_assets('user-edit.php')
#3 web/wp/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
#4 web/wp/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#5 web/wp/wp-admin/admin-header.php(104): do_action('admin_enqueue_s...', 'user-edit.php')
#6 web/wp/wp-admin/user-edit.php(187): require_once('/Users/mak/Site...')
#7 .comp in web/app/plugins/satispress/src/Authentication/ApiKey/Repository.php on line 96

Reference

if ( 0 !== strpos( $meta_key, static::META_PREFIX ) ) {

Works

if ( 0 !== strpos( (string) $meta_key, static::META_PREFIX ) ) {
bradyvercher commented 3 years ago

I'm not sure why $meta_key would ever be anything other than I string, but I suppose it's possible someone is using a numeric key (or a bug caused a numeric key to be used), so it shouldn't hurt anything to go ahead and cast that to a string.