Make WordPress Core

Opened 13 months ago

Last modified 13 months ago

#64131 new feature request

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

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

Description

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

Change History (2)

#1 follow-up: @swissspidy
13 months 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
13 months 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.