Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capabilities: Allow string user_ids #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akirk
Copy link

@akirk akirk commented Nov 18, 2024

In the friends plugin I create virtual users that have a string as their user id, thus the type hint causes a fatal:

<b>Fatal error</b>:  Uncaught TypeError: Felix_Arntz\AI_Services_Dependencies\Felix_Arntz\WP_OOP_Plugin_Lib\Capabilities\Capability_Filters::filter_map_meta_cap(): Argument #3 ($user_id) must be of type int, string given, called in wp/wp-includes/class-wp-hook.php on line 324 and defined in wp/wp-content/plugins/ai-services/third-party/Capabilities/Capability_Filters.php:147
Stack trace:
#0 wp/wp-includes/class-wp-hook.php(324): Felix_Arntz\AI_Services_Dependencies\Felix_Arntz\WP_OOP_Plugin_Lib\Capabilities\Capability_Filters-&gt;filter_map_meta_cap(Array, 'friend', 'friends-virtual...', Array)
#1 wp/wp-includes/plugin.php(205): WP_Hook-&gt;apply_filters(Array, Array)
#2 wp/wp-includes/capabilities.php(876): apply_filters('map_meta_cap', Array, 'friend', 'friends-virtual...', Array)
#3 wp/wp-includes/class-wp-user.php(782): map_meta_cap('friend', 'friends-virtual...')
#4 wp/wp-content/plugins/friends/includes/class-user.php(1140): WP_User-&gt;has_cap('friend')

Can we allow strings here, too?

@LeTraceurSnork
Copy link

LeTraceurSnork commented Nov 27, 2024

Since WordPress itself implies that user ID is integer (PHPDoc says it's integer, default value is 0), I guess it's safe to say that while technically (since the property is not strictly typed) it is possible to set the ID as string, it shall not be done and therefore must trigger _doing_it_wrong() function

@felixarntz
Copy link
Owner

@akirk I agree with @LeTraceurSnork, user IDs in WordPress are expected to be integers, per the documentation, so it's against that documentation to use another type.

@akirk
Copy link
Author

akirk commented Nov 30, 2024

I guess it makes sense. Probably I need to resort to using fake numeric ids then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants