diff --git a/plugins/osi-features/inc/classes/class-rewrite.php b/plugins/osi-features/inc/classes/class-rewrite.php index 675852d..13116d8 100644 --- a/plugins/osi-features/inc/classes/class-rewrite.php +++ b/plugins/osi-features/inc/classes/class-rewrite.php @@ -8,6 +8,14 @@ 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 @@ -20,9 +28,7 @@ class Rewrite { * Construct method. */ protected function __construct() { - $this->setup_hooks(); - } /** @@ -32,12 +38,60 @@ protected function __construct() { */ protected function setup_hooks() { add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10 ); + add_action( 'init', array( $this, 'add_custom_rewrite_rules' ), 20 ); } - public function add_query_vars( $vars ) { + /** + * 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' + ); + } } diff --git a/plugins/osi-features/inc/classes/taxonomies/class-base.php b/plugins/osi-features/inc/classes/taxonomies/class-base.php index 8b7c397..47daaa7 100644 --- a/plugins/osi-features/inc/classes/taxonomies/class-base.php +++ b/plugins/osi-features/inc/classes/taxonomies/class-base.php @@ -7,7 +7,7 @@ namespace Osi\Features\Inc\Taxonomies; -use \Osi\Features\Inc\Traits\Singleton; +use Osi\Features\Inc\Traits\Singleton; /** * Class Base @@ -20,9 +20,7 @@ abstract class Base { * Base constructor. */ protected function __construct() { - $this->setup_hooks(); - } /** @@ -31,9 +29,7 @@ protected function __construct() { * @return void */ protected function setup_hooks() { - - add_action( 'init', [ $this, 'register_taxonomy' ] ); - + add_action( 'init', array( $this, 'register_taxonomy' ) ); } /** @@ -42,7 +38,6 @@ protected function setup_hooks() { * @return void */ public function register_taxonomy() { - if ( empty( static::SLUG ) ) { return; } @@ -54,17 +49,16 @@ public function register_taxonomy() { } $args = $this->get_args(); - $args = ( ! empty( $args ) && is_array( $args ) ) ? $args : []; + $args = ( ! empty( $args ) && is_array( $args ) ) ? $args : array(); $labels = $this->get_labels(); - $labels = ( ! empty( $labels ) && is_array( $labels ) ) ? $labels : []; + $labels = ( ! empty( $labels ) && is_array( $labels ) ) ? $labels : array(); if ( ! empty( $labels ) && is_array( $labels ) ) { $args['labels'] = $labels; } register_taxonomy( static::SLUG, $post_types, $args ); - } /** @@ -73,15 +67,13 @@ public function register_taxonomy() { * @return array */ public function get_args() { - - return [ + return array( 'hierarchical' => true, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'show_in_rest' => true, - ]; - + ); } /** @@ -97,5 +89,4 @@ abstract public function get_labels(); * @return array */ abstract public function get_post_types(); - } diff --git a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-example.php b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-example.php index 91a0349..edd800b 100644 --- a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-example.php +++ b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-example.php @@ -25,8 +25,7 @@ class Taxonomy_Example extends Base { * @return array */ public function get_labels() { - - return [ + return array( 'name' => _x( 'Taxonomy_Example', 'taxonomy general name', 'osi-features' ), 'singular_name' => _x( 'Taxonomy_Example', 'taxonomy singular name', 'osi-features' ), 'search_items' => __( 'Search Taxonomy_Example', 'osi-features' ), @@ -43,8 +42,7 @@ public function get_labels() { 'choose_from_most_used' => __( 'Choose from the most used Taxonomy_Example', 'osi-features' ), 'not_found' => __( 'No Taxonomy_Example found.', 'osi-features' ), 'menu_name' => __( 'Taxonomy_Example', 'osi-features' ), - ]; - + ); } /** @@ -53,11 +51,8 @@ public function get_labels() { * @return array */ public function get_post_types() { - - return [ + return array( 'post', - ]; - + ); } - } diff --git a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-license-category.php b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-license-category.php index b30eb4a..1ce8544 100644 --- a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-license-category.php +++ b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-license-category.php @@ -27,8 +27,7 @@ class Taxonomy_License_Category extends Base { * @return array */ public function get_labels() { - - return [ + return array( 'name' => _x( 'Category', 'taxonomy general name', 'osi-features' ), 'singular_name' => _x( 'Category', 'taxonomy singular name', 'osi-features' ), 'search_items' => __( 'Search Category', 'osi-features' ), @@ -45,8 +44,7 @@ public function get_labels() { 'choose_from_most_used' => __( 'Choose from the most used Categories', 'osi-features' ), 'not_found' => __( 'No Category found.', 'osi-features' ), 'menu_name' => __( 'Categories', 'osi-features' ), - ]; - + ); } /** @@ -55,11 +53,9 @@ public function get_labels() { * @return array */ public function get_post_types() { - - return [ + return array( Post_Type_License::get_instance()->get_slug(), - ]; - + ); } /** @@ -68,13 +64,14 @@ public function get_post_types() { * @return array */ public function get_args() { - - return wp_parse_args( - [ - 'rewrite' => array( 'slug' => 'license-category' ), - ], + return wp_parse_args( + array( + 'rewrite' => array( + 'slug' => Post_Type_License::get_instance()->get_slug() . '/category', + 'with_front' => false, + ), + ), parent::get_args() ); } - } diff --git a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-publication.php b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-publication.php index 2b18071..6eca600 100644 --- a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-publication.php +++ b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-publication.php @@ -27,8 +27,7 @@ class Taxonomy_Publication extends Base { * @return array */ public function get_labels() { - - return [ + return array( 'name' => _x( 'Publication', 'taxonomy general name', 'osi-features' ), 'singular_name' => _x( 'Publication', 'taxonomy singular name', 'osi-features' ), 'search_items' => __( 'Search Publication', 'osi-features' ), @@ -45,8 +44,7 @@ public function get_labels() { 'choose_from_most_used' => __( 'Choose from the most used Publications', 'osi-features' ), 'not_found' => __( 'No Publication found.', 'osi-features' ), 'menu_name' => __( 'Publications', 'osi-features' ), - ]; - + ); } /** @@ -55,11 +53,9 @@ public function get_labels() { * @return array */ public function get_post_types() { - - return [ + return array( Post_Type_Press_Mentions::get_instance()->get_slug(), - ]; - + ); } /** @@ -68,14 +64,15 @@ public function get_post_types() { * @return array */ public function get_args() { - - return wp_parse_args( - [ + return wp_parse_args( + array( 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'publication' ), - ], + 'rewrite' => array( + 'slug' => Post_Type_Press_Mentions::get_instance()->get_slug() . '/publication', + 'with_front' => false, + ), + ), parent::get_args() ); } - } diff --git a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-seat-type.php b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-seat-type.php index faa701a..45e3431 100644 --- a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-seat-type.php +++ b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-seat-type.php @@ -27,8 +27,7 @@ class Taxonomy_Seat_Type extends Base { * @return array */ public function get_labels() { - - return [ + return array( 'name' => _x( 'Seat type', 'taxonomy general name', 'osi-features' ), 'singular_name' => _x( 'Seat type', 'taxonomy singular name', 'osi-features' ), 'search_items' => __( 'Search Seat type', 'osi-features' ), @@ -45,8 +44,7 @@ public function get_labels() { 'choose_from_most_used' => __( 'Choose from the most used Seat types', 'osi-features' ), 'not_found' => __( 'No Seat type found.', 'osi-features' ), 'menu_name' => __( 'Seat Types', 'osi-features' ), - ]; - + ); } /** @@ -55,11 +53,9 @@ public function get_labels() { * @return array */ public function get_post_types() { - - return [ + return array( Post_Type_Board_Member::get_instance()->get_slug(), - ]; - + ); } /** @@ -68,14 +64,15 @@ public function get_post_types() { * @return array */ public function get_args() { - - return wp_parse_args( - [ + return wp_parse_args( + array( 'hierarchical' => false, - 'rewrite' => array( 'slug' => 'seat-type' ), - ], + 'rewrite' => array( + 'slug' => Post_Type_Board_Member::get_instance()->get_slug() . '/seat-type', + 'with_front' => false, + ), + ), parent::get_args() ); } - } diff --git a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-status.php b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-status.php index 369182d..9ccfeee 100644 --- a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-status.php +++ b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-status.php @@ -27,8 +27,7 @@ class Taxonomy_Status extends Base { * @return array */ public function get_labels() { - - return [ + return array( 'name' => _x( 'Status', 'taxonomy general name', 'osi-features' ), 'singular_name' => _x( 'Status', 'taxonomy singular name', 'osi-features' ), 'search_items' => __( 'Search Status', 'osi-features' ), @@ -45,8 +44,7 @@ public function get_labels() { 'choose_from_most_used' => __( 'Choose from the most used Statuses', 'osi-features' ), 'not_found' => __( 'No Status found.', 'osi-features' ), 'menu_name' => __( 'Statuses', 'osi-features' ), - ]; - + ); } /** @@ -55,11 +53,9 @@ public function get_labels() { * @return array */ public function get_post_types() { - - return [ + return array( Post_Type_Board_Member::get_instance()->get_slug(), - ]; - + ); } /** @@ -68,14 +64,15 @@ public function get_post_types() { * @return array */ public function get_args() { - - return wp_parse_args( - [ + return wp_parse_args( + array( 'hierarchical' => false, - 'rewrite' => array( 'slug' => 'status' ), - ], + 'rewrite' => array( + 'slug' => Post_Type_Board_Member::get_instance()->get_slug() . '/status', + 'with_front' => false, + ), + ), parent::get_args() ); } - } diff --git a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-steward.php b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-steward.php index 2140780..4acbff6 100644 --- a/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-steward.php +++ b/plugins/osi-features/inc/classes/taxonomies/class-taxonomy-steward.php @@ -27,8 +27,7 @@ class Taxonomy_Steward extends Base { * @return array */ public function get_labels() { - - return [ + return array( 'name' => _x( 'License Steward', 'taxonomy general name', 'osi-features' ), 'singular_name' => _x( 'License Steward', 'taxonomy singular name', 'osi-features' ), 'search_items' => __( 'Search License Steward', 'osi-features' ), @@ -45,8 +44,7 @@ public function get_labels() { 'choose_from_most_used' => __( 'Choose from the most used License Stewards', 'osi-features' ), 'not_found' => __( 'No License Steward found.', 'osi-features' ), 'menu_name' => __( 'License Stewards', 'osi-features' ), - ]; - + ); } /** @@ -55,11 +53,9 @@ public function get_labels() { * @return array */ public function get_post_types() { - - return [ + return array( Post_Type_License::get_instance()->get_slug(), - ]; - + ); } /** @@ -68,14 +64,15 @@ public function get_post_types() { * @return array */ public function get_args() { - - return wp_parse_args( - [ + return wp_parse_args( + array( 'hierarchical' => false, - 'rewrite' => array( 'slug' => 'steward' ), - ], + 'rewrite' => array( + 'slug' => Post_Type_License::get_instance()->get_slug() . '/steward', + 'with_front' => false, + ), + ), parent::get_args() ); } - }