-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-apple-pay-domain-association.php
84 lines (60 loc) · 1.65 KB
/
class-apple-pay-domain-association.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Domain Association for Apple Pay
*
* @package Apple_Pay_Domain_Association
*/
namespace Thoughtis;
use WP;
/**
* Apple Pay Domain Association
*/
class Apple_Pay_Domain_Association {
/**
* Construct
*/
public function __construct() {
add_action( 'init', array( __CLASS__, 'add_rewrite_rule' ), 10 );
add_action( 'parse_request', array( __CLASS__, 'handle_request' ), 10, 1 );
add_filter( 'query_vars', array( __CLASS__, 'add_query_var' ), 10, 1 );
}
/**
* Add Rewrite Rule
*/
public static function add_rewrite_rule() : void {
$rewrite_test = '^\.well-known\/apple-developer-merchantid-domain-association$';
$rewrite_dest = 'index.php?apple_pay_domain_association=true';
add_rewrite_rule( $rewrite_test, $rewrite_dest, 'top' );
}
/**
* Add Query Var
*
* @param array $public_query_vars - provided public query vars.
* @return array $public_query_vars - updated public query vars.
*/
public static function add_query_var( array $public_query_vars ) : array {
array_push( $public_query_vars, 'apple_pay_domain_association' );
return $public_query_vars;
}
/**
* Handle Request
*
* @param WP $wp Current WordPress environment instance.
*/
public static function handle_request( WP $wp ) : void {
if ( ! isset( $wp->query_vars['apple_pay_domain_association'] ) ) {
return;
}
if ( 'true' !== $wp->query_vars['apple_pay_domain_association'] ) {
return;
}
header( 'Content-Type: application/octet-stream' );
echo esc_html(
file_get_contents(
plugin_dir_path( __FILE__ ) . 'apple-developer-merchantid-domain-association'
)
);
exit;
}
}
new Apple_Pay_Domain_Association();