— — — `, with the * client and the caller-supplied label both optional. Splitting on the * separator and comparing whole segments is what makes the match exact. * * @param string $name Credential display name. * @return string[] */ private static function segments( string $name ): array { return array_map( 'trim', explode( self::SEPARATOR, $name ) ); } /** * Count the current user's credentials issued for one server. * * @param int $user_id User whose credentials to count. * @param string $server_name Server display name. * @return int */ public static function count_for_server( int $user_id, string $server_name ): int { if ( ! class_exists( 'WP_Application_Passwords' ) || $user_id <= 0 ) { return 0; } // Core types this as a list of fully-populated credential arrays, so a // defensive is_array()/isset() pair here is provably dead code — // PHPStan says so at level 8 — and dead guards make a reader wonder // which case they were protecting against. $all = \WP_Application_Passwords::get_user_application_passwords( $user_id ); $count = 0; foreach ( $all as $password ) { if ( self::is_for_server( (string) $password['name'], $server_name ) ) { ++$count; } } return $count; } }