File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,26 @@ public static function get_by_id( $id ) {
6060 return new static ( $ user , $ id , $ value [0 ] );
6161 }
6262
63+ /**
64+ * Get all tokens for the specified user.
65+ *
66+ * @return static[] List of tokens.
67+ */
68+ public static function get_for_user ( WP_User $ user ) {
69+ $ meta = get_user_meta ( $ user ->ID );
70+ $ tokens = [];
71+ foreach ( $ meta as $ key => $ values ) {
72+ if ( strpos ( $ key , static ::META_PREFIX ) !== 0 ) {
73+ continue ;
74+ }
75+
76+ $ real_key = substr ( $ key , strlen ( static ::META_PREFIX ) );
77+ $ value = maybe_unserialize ( $ values [0 ] );
78+ $ tokens [] = new static ( $ user , $ real_key , $ value );
79+ }
80+ return $ tokens ;
81+ }
82+
6383 /**
6484 * Creates a new token for the given client and user.
6585 *
You can’t perform that action at this time.
0 commit comments