-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
plugin.php
executable file
·63 lines (54 loc) · 1.59 KB
/
plugin.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
<?php
/*
Plugin Name: /.well-known/
Plugin URI: http://wordpress.org/extend/plugins/well-known/
Description: This plugin enables "Well-Known URIs" support for WordPress (RFC 5785: http://tools.ietf.org/html/rfc5785).
Version: 1.0.1
Author: pfefferle
Author URI: http://notizblog.org/
*/
/**
* well-known class
*
* @author Matthias Pfefferle
*/
class WellKnownPlugin {
/**
* Add 'well-known' as a valid query variables.
*
* @param array $vars
* @return array
*/
public static function query_vars($vars) {
$vars[] = 'well-known';
return $vars;
}
/**
* Add rewrite rules for .well-known.
*
* @param WP_Rewrite $wp_rewrite
*/
public static function rewrite_rules($wp_rewrite) {
$well_known_rules = array(
'.well-known/(.+)' => 'index.php?well-known='.$wp_rewrite->preg_index(1),
);
$wp_rewrite->rules = $well_known_rules + $wp_rewrite->rules;
}
/**
* delegates the request to the matching (registered) class
*
* @param WP $wp
*/
public static function delegate_request($wp) {
if (array_key_exists('well-known', $wp->query_vars)) {
$id = $wp->query_vars['well-known'];
do_action("well-known", $wp->query_vars);
do_action("well_known_{$id}", $wp->query_vars);
}
}
}
add_filter('query_vars', array('WellKnownPlugin', 'query_vars'));
add_action('parse_request', array('WellKnownPlugin', 'delegate_request'), 99);
add_action('generate_rewrite_rules', array('WellKnownPlugin', 'rewrite_rules'), 99);
register_activation_hook(__FILE__, 'flush_rewrite_rules');
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');