@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | |
14 | 14 | const TAXONOMY_DEFAULTS = [ |
15 | 15 | 'hierarchical' => true, |
16 | - 'labels' => [], |
|
16 | + 'labels' => [ ], |
|
17 | 17 | 'menu_name' => '', |
18 | 18 | 'plural' => '', |
19 | - 'post_types' => [], |
|
19 | + 'post_types' => [ ], |
|
20 | 20 | 'public' => true, |
21 | 21 | 'rewrite' => true, |
22 | 22 | 'show_admin_column' => true, |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | { |
37 | 37 | $this->normalize(); |
38 | 38 | |
39 | - add_filter( 'parse_query', [ $this, 'filterBy'] ); |
|
40 | - add_action( 'restrict_manage_posts', [ $this, 'printFilters'] ); |
|
41 | - add_action( 'init', [ $this, 'register'] ); |
|
39 | + add_filter( 'parse_query', [ $this, 'filterBy' ] ); |
|
40 | + add_action( 'restrict_manage_posts', [ $this, 'printFilters' ] ); |
|
41 | + add_action( 'init', [ $this, 'register' ] ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | if( !is_admin() || get_current_screen()->base != 'edit' )return; |
50 | 50 | $vars = &$query->query_vars; |
51 | 51 | foreach( array_keys( $this->taxonomies ) as $taxonomy ) { |
52 | - if( !is_numeric( $vars[$taxonomy] ))continue; |
|
53 | - $vars[$taxonomy] = get_term_by( 'id', $vars[$taxonomy], $taxonomy )->slug; |
|
52 | + if( !is_numeric( $vars[ $taxonomy ] ) )continue; |
|
53 | + $vars[ $taxonomy ] = get_term_by( 'id', $vars[ $taxonomy ], $taxonomy )->slug; |
|
54 | 54 | } |
55 | 55 | return $query; |
56 | 56 | } |
@@ -62,18 +62,18 @@ discard block |
||
62 | 62 | { |
63 | 63 | global $wp_query; |
64 | 64 | foreach( $this->taxonomies as $taxonomy => $args ) { |
65 | - if( !in_array( get_current_screen()->post_type, $args['post_types'] ))continue; |
|
66 | - $selected = isset( $wp_query->query[$taxonomy] ) |
|
67 | - ? $wp_query->query[$taxonomy] |
|
65 | + if( !in_array( get_current_screen()->post_type, $args[ 'post_types' ] ) )continue; |
|
66 | + $selected = isset( $wp_query->query[ $taxonomy ] ) |
|
67 | + ? $wp_query->query[ $taxonomy ] |
|
68 | 68 | : false; |
69 | - wp_dropdown_categories([ |
|
69 | + wp_dropdown_categories( [ |
|
70 | 70 | 'hide_if_empty' => true, |
71 | 71 | 'name' => $taxonomy, |
72 | 72 | 'orderby' => 'name', |
73 | 73 | 'selected' => $selected, |
74 | - 'show_option_all' => $args['labels']['all_items'], |
|
74 | + 'show_option_all' => $args[ 'labels' ][ 'all_items' ], |
|
75 | 75 | 'taxonomy' => $taxonomy, |
76 | - ]); |
|
76 | + ] ); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | public function register() |
84 | 84 | { |
85 | 85 | array_walk( $this->taxonomies, function( $args, $taxonomy ) { |
86 | - register_taxonomy( $taxonomy, $args['post_types'], array_diff_key( $args, array_flip( self::CUSTOM_KEYS ))); |
|
87 | - foreach( $args['post_types'] as $type ) { |
|
86 | + register_taxonomy( $taxonomy, $args[ 'post_types' ], array_diff_key( $args, array_flip( self::CUSTOM_KEYS ) ) ); |
|
87 | + foreach( $args[ 'post_types' ] as $type ) { |
|
88 | 88 | register_taxonomy_for_object_type( $taxonomy, $type ); |
89 | 89 | } |
90 | 90 | }); |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | */ |
96 | 96 | protected function normalize() |
97 | 97 | { |
98 | - foreach( $this->app->config['taxonomies'] as $taxonomy => $args ) { |
|
99 | - $this->taxonomies[$taxonomy] = apply_filters( 'pollux/taxonomy/args', |
|
98 | + foreach( $this->app->config[ 'taxonomies' ] as $taxonomy => $args ) { |
|
99 | + $this->taxonomies[ $taxonomy ] = apply_filters( 'pollux/taxonomy/args', |
|
100 | 100 | $this->normalizeThis( $args, self::TAXONOMY_DEFAULTS, $taxonomy ) |
101 | 101 | ); |
102 | 102 | } |
103 | 103 | $this->taxonomies = array_diff_key( |
104 | 104 | $this->taxonomies, |
105 | - get_taxonomies( ['_builtin' => true] ) |
|
105 | + get_taxonomies( [ '_builtin' => true ] ) |
|
106 | 106 | ); |
107 | 107 | } |
108 | 108 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | protected function normalizeLabels( $labels, array $args ) |
114 | 114 | { |
115 | - return wp_parse_args( $labels, $this->setLabels( $args )); |
|
115 | + return wp_parse_args( $labels, $this->setLabels( $args ) ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | protected function normalizeMenuName( $menuname, array $args ) |
123 | 123 | { |
124 | 124 | return empty( $menuname ) |
125 | - ? $args['plural'] |
|
125 | + ? $args[ 'plural' ] |
|
126 | 126 | : $menuname; |
127 | 127 | } |
128 | 128 | |
@@ -141,17 +141,17 @@ discard block |
||
141 | 141 | protected function setLabels( array $args ) |
142 | 142 | { |
143 | 143 | return apply_filters( 'pollux/taxonomy/labels', [ |
144 | - 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new taxonomy', 'pollux' ), $args['single'] ), |
|
145 | - 'all_items' => sprintf( _x( 'All %s', 'All taxonomies', 'pollux' ), $args['plural'] ), |
|
146 | - 'edit_item' => sprintf( _x( 'Edit %s', 'Edit taxonomy', 'pollux' ), $args['single'] ), |
|
147 | - 'menu_name' => $this->normalizeMenuName( $args['menu_name'], $args ), |
|
148 | - 'name' => $args['plural'], |
|
149 | - 'new_item_name' => sprintf( _x( 'New %s Name', 'New taxonomy name', 'pollux' ), $args['single'] ), |
|
150 | - 'not_found' => sprintf( _x( 'No %s found', 'No taxonomies found', 'pollux' ), $args['plural'] ), |
|
151 | - 'search_items' => sprintf( _x( 'Search %s', 'Search taxonomies', 'pollux' ), $args['plural'] ), |
|
152 | - 'singular_name' => $args['single'], |
|
153 | - 'update_item' => sprintf( _x( 'Update %s', 'Update taxonomy', 'pollux' ), $args['single'] ), |
|
154 | - 'view_item' => sprintf( _x( 'View %s', 'View taxonomy', 'pollux' ), $args['single'] ), |
|
144 | + 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
145 | + 'all_items' => sprintf( _x( 'All %s', 'All taxonomies', 'pollux' ), $args[ 'plural' ] ), |
|
146 | + 'edit_item' => sprintf( _x( 'Edit %s', 'Edit taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
147 | + 'menu_name' => $this->normalizeMenuName( $args[ 'menu_name' ], $args ), |
|
148 | + 'name' => $args[ 'plural' ], |
|
149 | + 'new_item_name' => sprintf( _x( 'New %s Name', 'New taxonomy name', 'pollux' ), $args[ 'single' ] ), |
|
150 | + 'not_found' => sprintf( _x( 'No %s found', 'No taxonomies found', 'pollux' ), $args[ 'plural' ] ), |
|
151 | + 'search_items' => sprintf( _x( 'Search %s', 'Search taxonomies', 'pollux' ), $args[ 'plural' ] ), |
|
152 | + 'singular_name' => $args[ 'single' ], |
|
153 | + 'update_item' => sprintf( _x( 'Update %s', 'Update taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
154 | + 'view_item' => sprintf( _x( 'View %s', 'View taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
155 | 155 | ], $args ); |
156 | 156 | } |
157 | 157 | } |
@@ -46,10 +46,14 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function filterBy( WP_Query $query ) |
48 | 48 | { |
49 | - if( !is_admin() || get_current_screen()->base != 'edit' )return; |
|
49 | + if( !is_admin() || get_current_screen()->base != 'edit' ) { |
|
50 | + return; |
|
51 | + } |
|
50 | 52 | $vars = &$query->query_vars; |
51 | 53 | foreach( array_keys( $this->taxonomies ) as $taxonomy ) { |
52 | - if( !is_numeric( $vars[$taxonomy] ))continue; |
|
54 | + if( !is_numeric( $vars[$taxonomy] )) { |
|
55 | + continue; |
|
56 | + } |
|
53 | 57 | $vars[$taxonomy] = get_term_by( 'id', $vars[$taxonomy], $taxonomy )->slug; |
54 | 58 | } |
55 | 59 | return $query; |
@@ -62,7 +66,9 @@ discard block |
||
62 | 66 | { |
63 | 67 | global $wp_query; |
64 | 68 | foreach( $this->taxonomies as $taxonomy => $args ) { |
65 | - if( !in_array( get_current_screen()->post_type, $args['post_types'] ))continue; |
|
69 | + if( !in_array( get_current_screen()->post_type, $args['post_types'] )) { |
|
70 | + continue; |
|
71 | + } |
|
66 | 72 | $selected = isset( $wp_query->query[$taxonomy] ) |
67 | 73 | ? $wp_query->query[$taxonomy] |
68 | 74 | : false; |
@@ -82,7 +88,8 @@ discard block |
||
82 | 88 | */ |
83 | 89 | public function register() |
84 | 90 | { |
85 | - array_walk( $this->taxonomies, function( $args, $taxonomy ) { |
|
91 | + array_walk( $this->taxonomies, function( $args, $taxonomy ) |
|
92 | + { |
|
86 | 93 | register_taxonomy( $taxonomy, $args['post_types'], array_diff_key( $args, array_flip( self::CUSTOM_KEYS ))); |
87 | 94 | foreach( $args['post_types'] as $type ) { |
88 | 95 | register_taxonomy_for_object_type( $taxonomy, $type ); |