Skip to content

Commit 75f7bc0

Browse files
committed
Update custom tax permalinks
1 parent 3cd59cf commit 75f7bc0

File tree

6 files changed

+84
-36
lines changed

6 files changed

+84
-36
lines changed

plugins/osi-features/inc/classes/class-rewrite.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
namespace Osi\Features\Inc;
99

1010
use Osi\Features\Inc\Traits\Singleton;
11+
use Osi\Features\Inc\Post_Types\Post_Type_Board_Member;
12+
use Osi\Features\Inc\Taxonomies\Taxonomy_Status;
13+
use Osi\Features\Inc\Post_Types\Post_Type_License;
14+
use Osi\Features\Inc\Taxonomies\Taxonomy_License_Category;
15+
use Osi\Features\Inc\Post_Types\Post_Type_Press_Mentions;
16+
use Osi\Features\Inc\Taxonomies\Taxonomy_Publication;
17+
use Osi\Features\Inc\Taxonomies\Taxonomy_Seat_Type;
18+
use Osi\Features\Inc\Taxonomies\Taxonomy_Steward;
1119

1220
/**
1321
* Class Rewrite
@@ -32,6 +40,7 @@ protected function __construct() {
3240
*/
3341
protected function setup_hooks() {
3442
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10 );
43+
add_action( 'init', [ $this, 'add_custom_rewrite_rules' ], 20 );
3544
}
3645

3746
public function add_query_vars( $vars ) {
@@ -40,4 +49,48 @@ public function add_query_vars( $vars ) {
4049
return $vars;
4150
}
4251

52+
/**
53+
* Add custom rewrite rules for custom post types and taxonomies.
54+
*
55+
* @return void
56+
*/
57+
public function add_custom_rewrite_rules() {
58+
$base = Post_Type_License::get_instance()->get_slug();
59+
add_rewrite_rule(
60+
'^' . $base . '/steward/([^/]+)/?$',
61+
'index.php?taxonomy=' . Taxonomy_Steward::SLUG . '&term=$matches[1]',
62+
'top'
63+
);
64+
65+
$base = Post_Type_Board_Member::get_instance()->get_slug();
66+
add_rewrite_rule(
67+
'^' . $base . '/status/([^/]+)/?$',
68+
'index.php?taxonomy=' . Taxonomy_Status::SLUG . '&term=$matches[1]',
69+
'top'
70+
);
71+
72+
$base = Post_Type_Board_Member::get_instance()->get_slug();
73+
add_rewrite_rule(
74+
'^' . $base . '/seat-type/([^/]+)/?$',
75+
'index.php?taxonomy=' . Taxonomy_Seat_Type::SLUG . '&term=$matches[1]',
76+
'top'
77+
);
78+
79+
$base = Post_Type_License::get_instance()->get_slug();
80+
add_rewrite_rule(
81+
'^' . $base . '/category/([^/]+)/?$',
82+
'index.php?taxonomy=' . Taxonomy_License_Category::SLUG . '&term=$matches[1]',
83+
'top'
84+
);
85+
86+
$base = Post_Type_Press_Mentions::get_instance()->get_slug();
87+
add_rewrite_rule(
88+
'^' . $base . '/publication/([^/]+)/?$',
89+
'index.php?taxonomy=' . Taxonomy_Publication::SLUG . '&term=$matches[1]',
90+
'top'
91+
);
92+
93+
94+
}
95+
4396
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-license-category.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
74-
'rewrite' => array(
75-
'slug' => 'license-category',
74+
'rewrite' => [
75+
'slug' => Post_Type_License::get_instance()->get_slug() . '/category',
7676
'with_front' => false,
77-
),
78-
],
77+
],
78+
],
7979
parent::get_args()
8080
);
8181
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-publication.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ public function get_post_types() {
6868
public function get_args() {
6969

7070
return wp_parse_args(
71-
array(
71+
[
7272
'hierarchical' => true,
73-
'show_in_rest' => true,
74-
'rewrite' => array(
75-
'slug' => 'publication',
73+
'rewrite' => [
74+
'slug' => Post_Type_Press_Mentions::get_instance()->get_slug() . '/publication',
7675
'with_front' => false,
77-
),
78-
),
76+
],
77+
],
7978
parent::get_args()
8079
);
8180
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-seat-type.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
7474
'hierarchical' => false,
75-
'rewrite' => array(
76-
'slug' => 'seat-type',
75+
'rewrite' => [
76+
'slug' => Post_Type_Board_Member::get_instance()->get_slug() . '/seat-type',
7777
'with_front' => false,
78-
),
79-
],
78+
],
79+
],
8080
parent::get_args()
8181
);
8282
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-status.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,15 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71+
7172
return wp_parse_args(
72-
array(
73-
'hierarchical' => false,
74-
'rewrite' => false,
75-
'public' => false,
76-
'publicly_queryable' => true,
77-
'show_ui' => true,
78-
'show_in_menu' => true,
79-
'show_in_nav_menus' => false,
80-
'show_in_rest' => true,
81-
'show_admin_column' => true,
82-
'query_var' => true,
83-
),
73+
[
74+
'hierarchical' => false,
75+
'rewrite' => [
76+
'slug' => Post_Type_Board_Member::get_instance()->get_slug() . '/status',
77+
'with_front' => false,
78+
],
79+
],
8480
parent::get_args()
8581
);
8682
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-steward.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
7474
'hierarchical' => false,
75-
'rewrite' => array(
76-
'slug' => 'steward',
75+
'rewrite' => [
76+
'slug' => Post_Type_License::get_instance()->get_slug() . '/steward',
7777
'with_front' => false,
78-
),
79-
],
78+
],
79+
],
8080
parent::get_args()
8181
);
8282
}

0 commit comments

Comments
 (0)