-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclass-rewrite.php
More file actions
97 lines (85 loc) · 2.31 KB
/
class-rewrite.php
File metadata and controls
97 lines (85 loc) · 2.31 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Rewrite class.
*
* @package osi-features
*/
namespace Osi\Features\Inc;
use Osi\Features\Inc\Traits\Singleton;
use Osi\Features\Inc\Post_Types\Post_Type_Board_Member;
use Osi\Features\Inc\Taxonomies\Taxonomy_Status;
use Osi\Features\Inc\Post_Types\Post_Type_License;
use Osi\Features\Inc\Taxonomies\Taxonomy_License_Category;
use Osi\Features\Inc\Post_Types\Post_Type_Press_Mentions;
use Osi\Features\Inc\Taxonomies\Taxonomy_Publication;
use Osi\Features\Inc\Taxonomies\Taxonomy_Seat_Type;
use Osi\Features\Inc\Taxonomies\Taxonomy_Steward;
/**
* Class Rewrite
*/
class Rewrite {
use Singleton;
/**
* Construct method.
*/
protected function __construct() {
$this->setup_hooks();
}
/**
* To setup action/filter.
*
* @return void
*/
protected function setup_hooks() {
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10 );
add_action( 'init', array( $this, 'add_custom_rewrite_rules' ), 20 );
}
/**
* Add custom query vars.
*
* @param array $vars Public query vars.
*
* @return array
*/
public function add_query_vars( array $vars ) {
$vars[] = 'categories';
return $vars;
}
/**
* Add custom rewrite rules for custom post types and taxonomies.
*
* @return void
*/
public function add_custom_rewrite_rules() {
$base = Post_Type_License::get_instance()->get_slug();
add_rewrite_rule(
'^' . $base . '/steward/([^/]+)/?$',
'index.php?taxonomy=' . Taxonomy_Steward::SLUG . '&term=$matches[1]',
'top'
);
$base = Post_Type_Board_Member::get_instance()->get_slug();
add_rewrite_rule(
'^' . $base . '/status/([^/]+)/?$',
'index.php?taxonomy=' . Taxonomy_Status::SLUG . '&term=$matches[1]',
'top'
);
$base = Post_Type_Board_Member::get_instance()->get_slug();
add_rewrite_rule(
'^' . $base . '/seat-type/([^/]+)/?$',
'index.php?taxonomy=' . Taxonomy_Seat_Type::SLUG . '&term=$matches[1]',
'top'
);
$base = Post_Type_License::get_instance()->get_slug();
add_rewrite_rule(
'^' . $base . '/category/([^/]+)/?$',
'index.php?taxonomy=' . Taxonomy_License_Category::SLUG . '&term=$matches[1]',
'top'
);
$base = Post_Type_Press_Mentions::get_instance()->get_slug();
add_rewrite_rule(
'^' . $base . '/publication/([^/]+)/?$',
'index.php?taxonomy=' . Taxonomy_Publication::SLUG . '&term=$matches[1]',
'top'
);
}
}