Skip to content

Conversation

@scruffian
Copy link
Contributor

@scruffian scruffian commented Aug 3, 2023

This is an attempt to fix WordPress/gutenberg#53284.

The problem is that it's possible to call current_user_can before wp_get_current_user has been defined. We could guard against this by checking whether wp_get_current_user is defined before calling current_user_can each time, but adding the check here seems simpler.

I'm not sure if it makes sense to return false in this case, maybe we should return an error instead?

Fixes https://core.trac.wordpress.org/ticket/59000

*/
function current_user_can( $capability, ...$args ) {
if ( ! function_exists( 'wp_get_current_user' ) ) {
return false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not return false because it means user can't and maybe user can but we don't know yet if they can because we can't wp_get_current_user. 😆 It should return an error that can be used so that the extender or core calls current_user_can correctly.

@scruffian
Copy link
Contributor Author

@scruffian
Copy link
Contributor Author

Closing in favour of #5028

@scruffian scruffian closed this Aug 24, 2023
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.

Block Theme Previews does not work if we call the get_template or get_stylesheet functions early

2 participants