Skip to content

Commit 928895c

Browse files
authored
Merge pull request #214 from OpenSourceOrg/fix/195-tax-permalinks
Fix/195 tax permalinks
2 parents 0a755c3 + 5934627 commit 928895c

File tree

8 files changed

+123
-98
lines changed

8 files changed

+123
-98
lines changed

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

Lines changed: 58 additions & 4 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
@@ -20,9 +28,7 @@ class Rewrite {
2028
* Construct method.
2129
*/
2230
protected function __construct() {
23-
2431
$this->setup_hooks();
25-
2632
}
2733

2834
/**
@@ -32,12 +38,60 @@ protected function __construct() {
3238
*/
3339
protected function setup_hooks() {
3440
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10 );
41+
add_action( 'init', array( $this, 'add_custom_rewrite_rules' ), 20 );
3542
}
3643

37-
public function add_query_vars( $vars ) {
44+
/**
45+
* Add custom query vars.
46+
*
47+
* @param array $vars Public query vars.
48+
*
49+
* @return array
50+
*/
51+
public function add_query_vars( array $vars ) {
3852
$vars[] = 'categories';
39-
4053
return $vars;
4154
}
4255

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

plugins/osi-features/inc/classes/taxonomies/class-base.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Osi\Features\Inc\Taxonomies;
99

10-
use \Osi\Features\Inc\Traits\Singleton;
10+
use Osi\Features\Inc\Traits\Singleton;
1111

1212
/**
1313
* Class Base
@@ -20,9 +20,7 @@ abstract class Base {
2020
* Base constructor.
2121
*/
2222
protected function __construct() {
23-
2423
$this->setup_hooks();
25-
2624
}
2725

2826
/**
@@ -31,9 +29,7 @@ protected function __construct() {
3129
* @return void
3230
*/
3331
protected function setup_hooks() {
34-
35-
add_action( 'init', [ $this, 'register_taxonomy' ] );
36-
32+
add_action( 'init', array( $this, 'register_taxonomy' ) );
3733
}
3834

3935
/**
@@ -42,7 +38,6 @@ protected function setup_hooks() {
4238
* @return void
4339
*/
4440
public function register_taxonomy() {
45-
4641
if ( empty( static::SLUG ) ) {
4742
return;
4843
}
@@ -54,17 +49,16 @@ public function register_taxonomy() {
5449
}
5550

5651
$args = $this->get_args();
57-
$args = ( ! empty( $args ) && is_array( $args ) ) ? $args : [];
52+
$args = ( ! empty( $args ) && is_array( $args ) ) ? $args : array();
5853

5954
$labels = $this->get_labels();
60-
$labels = ( ! empty( $labels ) && is_array( $labels ) ) ? $labels : [];
55+
$labels = ( ! empty( $labels ) && is_array( $labels ) ) ? $labels : array();
6156

6257
if ( ! empty( $labels ) && is_array( $labels ) ) {
6358
$args['labels'] = $labels;
6459
}
6560

6661
register_taxonomy( static::SLUG, $post_types, $args );
67-
6862
}
6963

7064
/**
@@ -73,15 +67,13 @@ public function register_taxonomy() {
7367
* @return array
7468
*/
7569
public function get_args() {
76-
77-
return [
70+
return array(
7871
'hierarchical' => true,
7972
'show_ui' => true,
8073
'show_admin_column' => true,
8174
'query_var' => true,
8275
'show_in_rest' => true,
83-
];
84-
76+
);
8577
}
8678

8779
/**
@@ -97,5 +89,4 @@ abstract public function get_labels();
9789
* @return array
9890
*/
9991
abstract public function get_post_types();
100-
10192
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class Taxonomy_Example extends Base {
2525
* @return array
2626
*/
2727
public function get_labels() {
28-
29-
return [
28+
return array(
3029
'name' => _x( 'Taxonomy_Example', 'taxonomy general name', 'osi-features' ),
3130
'singular_name' => _x( 'Taxonomy_Example', 'taxonomy singular name', 'osi-features' ),
3231
'search_items' => __( 'Search Taxonomy_Example', 'osi-features' ),
@@ -43,8 +42,7 @@ public function get_labels() {
4342
'choose_from_most_used' => __( 'Choose from the most used Taxonomy_Example', 'osi-features' ),
4443
'not_found' => __( 'No Taxonomy_Example found.', 'osi-features' ),
4544
'menu_name' => __( 'Taxonomy_Example', 'osi-features' ),
46-
];
47-
45+
);
4846
}
4947

5048
/**
@@ -53,11 +51,8 @@ public function get_labels() {
5351
* @return array
5452
*/
5553
public function get_post_types() {
56-
57-
return [
54+
return array(
5855
'post',
59-
];
60-
56+
);
6157
}
62-
6358
}

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class Taxonomy_License_Category extends Base {
2727
* @return array
2828
*/
2929
public function get_labels() {
30-
31-
return [
30+
return array(
3231
'name' => _x( 'Category', 'taxonomy general name', 'osi-features' ),
3332
'singular_name' => _x( 'Category', 'taxonomy singular name', 'osi-features' ),
3433
'search_items' => __( 'Search Category', 'osi-features' ),
@@ -45,8 +44,7 @@ public function get_labels() {
4544
'choose_from_most_used' => __( 'Choose from the most used Categories', 'osi-features' ),
4645
'not_found' => __( 'No Category found.', 'osi-features' ),
4746
'menu_name' => __( 'Categories', 'osi-features' ),
48-
];
49-
47+
);
5048
}
5149

5250
/**
@@ -55,11 +53,9 @@ public function get_labels() {
5553
* @return array
5654
*/
5755
public function get_post_types() {
58-
59-
return [
56+
return array(
6057
Post_Type_License::get_instance()->get_slug(),
61-
];
62-
58+
);
6359
}
6460

6561
/**
@@ -68,13 +64,14 @@ public function get_post_types() {
6864
* @return array
6965
*/
7066
public function get_args() {
71-
72-
return wp_parse_args(
73-
[
74-
'rewrite' => array( 'slug' => 'license-category' ),
75-
],
67+
return wp_parse_args(
68+
array(
69+
'rewrite' => array(
70+
'slug' => Post_Type_License::get_instance()->get_slug() . '/category',
71+
'with_front' => false,
72+
),
73+
),
7674
parent::get_args()
7775
);
7876
}
79-
8077
}

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class Taxonomy_Publication extends Base {
2727
* @return array
2828
*/
2929
public function get_labels() {
30-
31-
return [
30+
return array(
3231
'name' => _x( 'Publication', 'taxonomy general name', 'osi-features' ),
3332
'singular_name' => _x( 'Publication', 'taxonomy singular name', 'osi-features' ),
3433
'search_items' => __( 'Search Publication', 'osi-features' ),
@@ -45,8 +44,7 @@ public function get_labels() {
4544
'choose_from_most_used' => __( 'Choose from the most used Publications', 'osi-features' ),
4645
'not_found' => __( 'No Publication found.', 'osi-features' ),
4746
'menu_name' => __( 'Publications', 'osi-features' ),
48-
];
49-
47+
);
5048
}
5149

5250
/**
@@ -55,11 +53,9 @@ public function get_labels() {
5553
* @return array
5654
*/
5755
public function get_post_types() {
58-
59-
return [
56+
return array(
6057
Post_Type_Press_Mentions::get_instance()->get_slug(),
61-
];
62-
58+
);
6359
}
6460

6561
/**
@@ -68,14 +64,15 @@ public function get_post_types() {
6864
* @return array
6965
*/
7066
public function get_args() {
71-
72-
return wp_parse_args(
73-
[
67+
return wp_parse_args(
68+
array(
7469
'hierarchical' => true,
75-
'rewrite' => array( 'slug' => 'publication' ),
76-
],
70+
'rewrite' => array(
71+
'slug' => Post_Type_Press_Mentions::get_instance()->get_slug() . '/publication',
72+
'with_front' => false,
73+
),
74+
),
7775
parent::get_args()
7876
);
7977
}
80-
8178
}

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class Taxonomy_Seat_Type extends Base {
2727
* @return array
2828
*/
2929
public function get_labels() {
30-
31-
return [
30+
return array(
3231
'name' => _x( 'Seat type', 'taxonomy general name', 'osi-features' ),
3332
'singular_name' => _x( 'Seat type', 'taxonomy singular name', 'osi-features' ),
3433
'search_items' => __( 'Search Seat type', 'osi-features' ),
@@ -45,8 +44,7 @@ public function get_labels() {
4544
'choose_from_most_used' => __( 'Choose from the most used Seat types', 'osi-features' ),
4645
'not_found' => __( 'No Seat type found.', 'osi-features' ),
4746
'menu_name' => __( 'Seat Types', 'osi-features' ),
48-
];
49-
47+
);
5048
}
5149

5250
/**
@@ -55,11 +53,9 @@ public function get_labels() {
5553
* @return array
5654
*/
5755
public function get_post_types() {
58-
59-
return [
56+
return array(
6057
Post_Type_Board_Member::get_instance()->get_slug(),
61-
];
62-
58+
);
6359
}
6460

6561
/**
@@ -68,14 +64,15 @@ public function get_post_types() {
6864
* @return array
6965
*/
7066
public function get_args() {
71-
72-
return wp_parse_args(
73-
[
67+
return wp_parse_args(
68+
array(
7469
'hierarchical' => false,
75-
'rewrite' => array( 'slug' => 'seat-type' ),
76-
],
70+
'rewrite' => array(
71+
'slug' => Post_Type_Board_Member::get_instance()->get_slug() . '/seat-type',
72+
'with_front' => false,
73+
),
74+
),
7775
parent::get_args()
7876
);
7977
}
80-
8178
}

0 commit comments

Comments
 (0)