PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wp-media / mcp-oauth / inc / Auth / Rewrite.php

Rewrite.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/wp-media/mcp-oauth/inc/Auth/Rewrite.php

56 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OAuth 2.1 Rewrite Rules.
4 *
5 * Registers the WordPress rewrite rules and query var used to route the
6 * five OAuth endpoints (authorize, authorize-callback, token, consent,
7 * revoke).
8 */
9
10 declare( strict_types=1 );
11
12 namespace WPMedia\MCP\OAuth\Auth;
13
14 /**
15 * Registers OAuth endpoint rewrite rules and the query var used to route them.
16 */
17 class Rewrite {
18
19 /**
20 * WordPress query var used to route OAuth endpoint requests.
21 */
22 const OAUTH_QUERY_VAR = 'mcp_oauth_endpoint';
23
24 /**
25 * Canary rule key used to detect whether the OAuth rules are persisted.
26 */
27 const AUTHORIZE_RULE = '^oauth/authorize$';
28
29 /**
30 * Register WordPress rewrite rules for all five OAuth endpoints.
31 *
32 * Called on the 'init' action (normal page load).
33 *
34 * @return void
35 */
36 public function register_oauth_rewrite_rules(): void {
37 add_rewrite_rule( self::AUTHORIZE_RULE, 'index.php?' . self::OAUTH_QUERY_VAR . '=authorize', 'top' );
38 add_rewrite_rule( '^oauth/authorize-callback$', 'index.php?' . self::OAUTH_QUERY_VAR . '=authorize-callback', 'top' );
39 add_rewrite_rule( '^oauth/token$', 'index.php?' . self::OAUTH_QUERY_VAR . '=token', 'top' );
40 add_rewrite_rule( '^oauth/consent$', 'index.php?' . self::OAUTH_QUERY_VAR . '=consent', 'top' );
41 add_rewrite_rule( '^oauth/revoke$', 'index.php?' . self::OAUTH_QUERY_VAR . '=revoke', 'top' );
42 }
43
44 /**
45 * Add the OAuth query var to WordPress's list of recognised vars.
46 *
47 * @param string[] $vars Existing query vars.
48 * @return string[] Modified list.
49 */
50 public function add_oauth_query_vars( array $vars ): array {
51 $vars[] = self::OAUTH_QUERY_VAR;
52
53 return $vars;
54 }
55 }
56