Skip to content

Commit ce53f67

Browse files
committed
Refactor grant type validation.
Inform user when they are doing it wrong. Since it is PHP 5.6, we cannot use array_filter() with the ARRAY_FILTER_USE_BOTH flag, can we? Thus, use a regular foreach loop.
1 parent 19d13a2 commit ce53f67

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

plugin.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ function get_grant_types() {
8080
* @param Type[] $grant_types Map of grant type to handler object.
8181
*/
8282
$grant_types = apply_filters( 'oauth2.grant_types', array() );
83-
84-
return array_filter( $grant_types, function ( $type ) {
85-
return $type instanceof Type;
86-
} );
83+
foreach ( $grant_types as $type => $handler ) {
84+
if ( ! $handler instanceof Type ) {
85+
/* translators: 1: Grant type name, 2: Grant type interface */
86+
$message = __( 'Skipping invalid grant type "%s". Required interface "%s" not implemented.', 'oauth2' );
87+
_doing_it_wrong( __FUNCTION__, sprintf( $message, $type, 'WP\\OAuth2\\Types\\Type' ), '0.1.0' );
88+
unset( $grant_types[ $type ] );
89+
}
90+
}
91+
92+
return $grant_types;
8793
}
8894

8995
/**

0 commit comments

Comments
 (0)