-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,81 @@ | ||
<?php | ||
/* | ||
Plugin Name: /.well-known/ | ||
Plugin URI: http://notizblog.org/ | ||
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: 0.5.1 | ||
Version: 0.6.0 | ||
Author: Matthias Pfefferle | ||
Author URI: http://notizblog.org/ | ||
*/ | ||
|
||
// | ||
add_action('admin_init', 'flush_rewrite_rules'); | ||
add_filter('query_vars', array('WellKnownPlugin', 'queryVars')); | ||
add_action('parse_request', array('WellKnownPlugin', 'delegateRequest')); | ||
add_action('generate_rewrite_rules', array('WellKnownPlugin', 'rewriteRules')); | ||
|
||
/** | ||
* well-known class | ||
* | ||
* @author Matthias Pfefferle | ||
*/ | ||
class WellKnownPlugin { | ||
|
||
/** | ||
* constructor | ||
*/ | ||
public function __construct() { | ||
add_action('init', array($this, 'init')); | ||
|
||
register_activation_hook(__FILE__, 'flush_rewrite_rules'); | ||
register_deactivation_hook(__FILE__, 'flush_rewrite_rules'); | ||
} | ||
|
||
/** | ||
* Initialize the plugin, registering WordPess hooks. | ||
*/ | ||
public function init() { | ||
load_plugin_textdomain('wellknown', null, basename(dirname( __FILE__ ))); | ||
|
||
add_filter('query_vars', array($this, 'query_vars')); | ||
add_action('parse_request', array($this, 'delegate_request')); | ||
add_action('generate_rewrite_rules', array($this, 'rewrite_rules')); | ||
} | ||
|
||
/** | ||
* Add 'well-known' as a valid query variables. | ||
* | ||
* @param array $vars | ||
* @return array | ||
*/ | ||
function queryVars($vars) { | ||
public function query_vars($vars) { | ||
$vars[] = 'well-known'; | ||
|
||
return $vars; | ||
} | ||
|
||
/** | ||
* Add rewrite rules for .well-known. | ||
* | ||
* @param object $wp_rewrite WP_Rewrite object | ||
* @param WP_Rewrite $wp_rewrite | ||
*/ | ||
function rewriteRules($wp_rewrite) { | ||
$wellKnownRules = array( | ||
public function rewrite_rules($wp_rewrite) { | ||
$well_known_rules = array( | ||
'.well-known/(.+)' => 'index.php?well-known='.$wp_rewrite->preg_index(1), | ||
); | ||
|
||
$wp_rewrite->rules = $wellKnownRules + $wp_rewrite->rules; | ||
$wp_rewrite->rules = $well_known_rules + $wp_rewrite->rules; | ||
} | ||
|
||
/** | ||
* delegates the request to the matching (registered) class | ||
* | ||
* @param WP $wp | ||
*/ | ||
function delegateRequest() { | ||
global $wp; | ||
|
||
public 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); | ||
|
||
// @deprecated please du not use | ||
// still experimenting :) | ||
if( isset($wp->query_vars['well-known']) ) { | ||
do_action("well-known", $wp->query_vars); | ||
exit; | ||
} | ||
wp_die("pääm"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
new WellKnownPlugin(); |