Make WordPress Core

Opened 7 weeks ago

Last modified 7 weeks ago

#64131 new feature request

A new function to test if a thing is an instance of the WP_User class

Reported by: profiletoggler's profile profiletoggler Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.9
Component: Users Keywords:
Focuses: Cc:

Description

<?php
function is_wp_user( $thing ) {
 return ( $thing instanceof WP_User );
}

Change History (2)

#1 follow-up: @swissspidy
7 weeks ago

  • Keywords needs-design-feedback removed

Hi there and welcome to WordPress Trac!

What would be the benefit of adding a function simply wrapping an instanceof check? Why not just use instanceof directly?

#2 in reply to: ↑ 1 @profiletoggler
7 weeks ago

A current function,is_wp_error, does something similar regarding the WP_Error class: https://developer.wordpress.org/reference/functions/is_wp_error/ .When developing my plugin, Describr (https://wordpress.org/plugins/describr/), I used namespaces, and it became tedious doing $thing instanceof \WP_User often to break out of the namespaces. Replying to swissspidy:

Hi there and welcome to WordPress Trac!

What would be the benefit of adding a function simply wrapping an instanceof check? Why not just use instanceof directly?

Note: See TracTickets for help on using tickets.