-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenericIndex.php
executable file
·63 lines (45 loc) · 1.52 KB
/
GenericIndex.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
abstract class GenericIndex {
protected $rewrite_rules = array();
protected $query_vars = array();
function __construct () {
add_filter ('rewrite_rules_array', array($this, 'rewrite_rules_array') );
add_filter ('query_vars', array($this, 'query_vars') );
add_action ('template_redirect', array($this, 'template_redirect') );
add_action ('wp_loaded', array($this, 'wp_loaded') );
foreach ($this->rewrite_rules as $key => $value) {
$this->rewrite_rules[$key] .= "&index=".get_class_name($this);
}
}
function wp_loaded(){
$rules = get_option( 'rewrite_rules' );
foreach ($this->rewrite_rules as $key => $value) {
if ( !isset($rules[$key]) || $rules[$key] != $value ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
}
function rewrite_rules_array ($rules) {
$ret = $this->rewrite_rules + $rules;
return $ret;
}
function query_vars ($vars) {
if ( !in_array("index", $vars) ) {
array_push($vars, "index");
}
$ret = $this->query_vars + $vars;
return $ret;
}
function template_redirect ($vars) {
global $wp;
global $wp_rewrite;
if ( !empty($wp->query_vars["index"]) && $wp->query_vars["index"] == get_class_name($this) ) {
$this->echo_index();
die();
}
}
function echo_index () {
}
}
?>