| @@ -96,9 +96,9 @@ | ||
| 96 | 96 | |
| 97 | 97 | // Generate the code. |
| 98 | 98 | $code = self::generate_code(); |
| 99 | 99 | $code_hash = self::hash_code( $code ); |
| 100 | - $expires_at = time() + self::EXPIRATION; | |
| 100 | + $expires_at = \time() + self::EXPIRATION; | |
| 101 | 101 | |
| 102 | 102 | // Store code data in transient. |
| 103 | 103 | $code_data = array( |
| 104 | 104 | 'user_id' => $user_id, |
| @@ -107,9 +107,9 @@ | ||
| 107 | 107 | 'scopes' => $filtered_scopes, |
| 108 | 108 | 'code_challenge' => $code_challenge, |
| 109 | 109 | 'code_challenge_method' => $code_challenge_method, |
| 110 | 110 | 'expires_at' => $expires_at, |
| 111 | - 'created_at' => time(), | |
| 111 | + 'created_at' => \time(), | |
| 112 | 112 | ); |
| 113 | 113 | |
| 114 | 114 | $stored = \set_transient( |
| 115 | 115 | self::TRANSIENT_PREFIX . $code_hash, |
| @@ -154,9 +154,9 @@ | ||
| 154 | 154 | // Immediately delete the code (single use). |
| 155 | 155 | \delete_transient( $transient ); |
| 156 | 156 | |
| 157 | 157 | // Check expiration (belt and suspenders - transient should auto-expire). |
| 158 | - if ( isset( $code_data['expires_at'] ) && $code_data['expires_at'] < time() ) { | |
| 158 | + if ( isset( $code_data['expires_at'] ) && $code_data['expires_at'] < \time() ) { | |
| 159 | 159 | return new \WP_Error( |
| 160 | 160 | 'activitypub_code_expired', |
| 161 | 161 | \__( 'Authorization code has expired.', 'activitypub' ), |
| 162 | 162 | array( 'status' => 400 ) |
| @@ -227,9 +227,9 @@ | ||
| 227 | 227 | |
| 228 | 228 | // S256: BASE64URL(SHA256(code_verifier)) == code_challenge. |
| 229 | 229 | $computed = self::compute_code_challenge( $code_verifier ); |
| 230 | 230 | |
| 231 | - return hash_equals( $code_challenge, $computed ); | |
| 231 | + return \hash_equals( $code_challenge, $computed ); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | 235 | * Compute a PKCE code challenge from a code verifier. |
| @@ -237,11 +237,11 @@ | ||
| 237 | 237 | * @param string $code_verifier The code verifier. |
| 238 | 238 | * @return string The code challenge (BASE64URL encoded SHA256 hash). |
| 239 | 239 | */ |
| 240 | 240 | public static function compute_code_challenge( $code_verifier ) { |
| 241 | - $hash = hash( 'sha256', $code_verifier, true ); | |
| 241 | + $hash = \hash( 'sha256', $code_verifier, true ); | |
| 242 | 242 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Required for PKCE BASE64URL encoding per RFC 7636. |
| 243 | - return rtrim( strtr( base64_encode( $hash ), '+/', '-_' ), '=' ); | |
| 243 | + return \rtrim( \strtr( \base64_encode( $hash ), '+/', '-_' ), '=' ); | |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * Generate a random authorization code. |
| @@ -248,9 +248,9 @@ | ||
| 248 | 248 | * |
| 249 | 249 | * @return string The authorization code. |
| 250 | 250 | */ |
| 251 | 251 | public static function generate_code() { |
| 252 | - return bin2hex( random_bytes( 32 ) ); | |
| 252 | + return \bin2hex( \random_bytes( 32 ) ); | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | 256 | * Hash an authorization code for storage lookup. |
| @@ -258,9 +258,9 @@ | ||
| 258 | 258 | * @param string $code The authorization code. |
| 259 | 259 | * @return string The SHA-256 hash. |
| 260 | 260 | */ |
| 261 | 261 | public static function hash_code( $code ) { |
| 262 | - return hash( 'sha256', $code ); | |
| 262 | + return \hash( 'sha256', $code ); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Clean up expired authorization codes. |
| @@ -285,9 +285,9 @@ | ||
| 285 | 285 | return 0; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $timeout_prefix = '_transient_timeout_' . self::TRANSIENT_PREFIX; |
| 289 | - $now = time(); | |
| 289 | + $now = \time(); | |
| 290 | 290 | |
| 291 | 291 | // Find expired timeout rows for this prefix. |
| 292 | 292 | $timeout_option_names = $wpdb->get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| 293 | 293 | $wpdb->prepare( |
| @@ -306,12 +306,12 @@ | ||
| 306 | 306 | // Build list of timeout and corresponding value option names to delete. |
| 307 | 307 | $option_names_to_delete = array(); |
| 308 | 308 | foreach ( $timeout_option_names as $timeout_name ) { |
| 309 | 309 | $option_names_to_delete[] = $timeout_name; |
| 310 | - $option_names_to_delete[] = str_replace( '_transient_timeout_', '_transient_', $timeout_name ); | |
| 310 | + $option_names_to_delete[] = \str_replace( '_transient_timeout_', '_transient_', $timeout_name ); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $placeholders = implode( ', ', array_fill( 0, count( $option_names_to_delete ), '%s' ) ); | |
| 313 | + $placeholders = \implode( ', ', \array_fill( 0, \count( $option_names_to_delete ), '%s' ) ); | |
| 314 | 314 | |
| 315 | 315 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.DirectDatabaseQuery |
| 316 | 316 | $count = $wpdb->query( |
| 317 | 317 | $wpdb->prepare( |