Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions plugins/osi-features/inc/classes/class-rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,9 +28,7 @@ class Rewrite {
* Construct method.
*/
protected function __construct() {

$this->setup_hooks();

}

/**
Expand All @@ -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'
);
}
}
21 changes: 6 additions & 15 deletions plugins/osi-features/inc/classes/taxonomies/class-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Osi\Features\Inc\Taxonomies;

use \Osi\Features\Inc\Traits\Singleton;
use Osi\Features\Inc\Traits\Singleton;

/**
* Class Base
Expand All @@ -20,9 +20,7 @@ abstract class Base {
* Base constructor.
*/
protected function __construct() {

$this->setup_hooks();

}

/**
Expand All @@ -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' ) );
}

/**
Expand All @@ -42,7 +38,6 @@ protected function setup_hooks() {
* @return void
*/
public function register_taxonomy() {

if ( empty( static::SLUG ) ) {
return;
}
Expand All @@ -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 );

}

/**
Expand All @@ -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,
];

);
}

/**
Expand All @@ -97,5 +89,4 @@ abstract public function get_labels();
* @return array
*/
abstract public function get_post_types();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -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' ),
];

);
}

/**
Expand All @@ -53,11 +51,8 @@ public function get_labels() {
* @return array
*/
public function get_post_types() {

return [
return array(
'post',
];

);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -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' ),
];

);
}

/**
Expand All @@ -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(),
];

);
}

/**
Expand All @@ -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()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -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' ),
];

);
}

/**
Expand All @@ -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(),
];

);
}

/**
Expand All @@ -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()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -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' ),
];

);
}

/**
Expand All @@ -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(),
];

);
}

/**
Expand All @@ -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()
);
}

}
Loading