@@ -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,9 +49,9 @@ 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( !isset( $vars[$taxonomy] ))return; |
|
53 | - if( $term = get_term_by( 'id', $vars[$taxonomy], $taxonomy )) { |
|
54 | - $vars[$taxonomy] = $term->slug; |
|
52 | + if( !isset( $vars[ $taxonomy ] ) )return; |
|
53 | + if( $term = get_term_by( 'id', $vars[ $taxonomy ], $taxonomy ) ) { |
|
54 | + $vars[ $taxonomy ] = $term->slug; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | return $query; |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | { |
65 | 65 | global $wp_query; |
66 | 66 | foreach( $this->taxonomies as $taxonomy => $args ) { |
67 | - if( !in_array( get_current_screen()->post_type, $args['post_types'] ))continue; |
|
68 | - $selected = isset( $wp_query->query[$taxonomy] ) |
|
69 | - ? $wp_query->query[$taxonomy] |
|
67 | + if( !in_array( get_current_screen()->post_type, $args[ 'post_types' ] ) )continue; |
|
68 | + $selected = isset( $wp_query->query[ $taxonomy ] ) |
|
69 | + ? $wp_query->query[ $taxonomy ] |
|
70 | 70 | : false; |
71 | - wp_dropdown_categories([ |
|
71 | + wp_dropdown_categories( [ |
|
72 | 72 | 'hide_if_empty' => true, |
73 | 73 | 'name' => $taxonomy, |
74 | 74 | 'orderby' => 'name', |
75 | 75 | 'selected' => $selected, |
76 | - 'show_option_all' => $args['labels']['all_items'], |
|
76 | + 'show_option_all' => $args[ 'labels' ][ 'all_items' ], |
|
77 | 77 | 'taxonomy' => $taxonomy, |
78 | - ]); |
|
78 | + ] ); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | public function register() |
86 | 86 | { |
87 | 87 | array_walk( $this->taxonomies, function( $args, $taxonomy ) { |
88 | - register_taxonomy( $taxonomy, $args['post_types'], array_diff_key( $args, array_flip( self::CUSTOM_KEYS ))); |
|
89 | - foreach( $args['post_types'] as $type ) { |
|
88 | + register_taxonomy( $taxonomy, $args[ 'post_types' ], array_diff_key( $args, array_flip( self::CUSTOM_KEYS ) ) ); |
|
89 | + foreach( $args[ 'post_types' ] as $type ) { |
|
90 | 90 | register_taxonomy_for_object_type( $taxonomy, $type ); |
91 | 91 | } |
92 | 92 | }); |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | */ |
98 | 98 | protected function normalize() |
99 | 99 | { |
100 | - foreach( $this->app->config['taxonomies'] as $taxonomy => $args ) { |
|
101 | - $this->taxonomies[$taxonomy] = apply_filters( 'pollux/taxonomy/args', |
|
100 | + foreach( $this->app->config[ 'taxonomies' ] as $taxonomy => $args ) { |
|
101 | + $this->taxonomies[ $taxonomy ] = apply_filters( 'pollux/taxonomy/args', |
|
102 | 102 | $this->normalizeThis( $args, self::TAXONOMY_DEFAULTS, $taxonomy ) |
103 | 103 | ); |
104 | 104 | } |
105 | 105 | $this->taxonomies = array_diff_key( |
106 | 106 | $this->taxonomies, |
107 | - get_taxonomies( ['_builtin' => true] ) |
|
107 | + get_taxonomies( [ '_builtin' => true ] ) |
|
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function normalizeLabels( $labels, array $args ) |
116 | 116 | { |
117 | - return wp_parse_args( $labels, $this->setLabels( $args )); |
|
117 | + return wp_parse_args( $labels, $this->setLabels( $args ) ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | protected function normalizeMenuName( $menuname, array $args ) |
125 | 125 | { |
126 | 126 | return empty( $menuname ) |
127 | - ? $args['plural'] |
|
127 | + ? $args[ 'plural' ] |
|
128 | 128 | : $menuname; |
129 | 129 | } |
130 | 130 | |
@@ -143,17 +143,17 @@ discard block |
||
143 | 143 | protected function setLabels( array $args ) |
144 | 144 | { |
145 | 145 | return apply_filters( 'pollux/taxonomy/labels', [ |
146 | - 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new taxonomy', 'pollux' ), $args['single'] ), |
|
147 | - 'all_items' => sprintf( _x( 'All %s', 'All taxonomies', 'pollux' ), $args['plural'] ), |
|
148 | - 'edit_item' => sprintf( _x( 'Edit %s', 'Edit taxonomy', 'pollux' ), $args['single'] ), |
|
149 | - 'menu_name' => $this->normalizeMenuName( $args['menu_name'], $args ), |
|
150 | - 'name' => $args['plural'], |
|
151 | - 'new_item_name' => sprintf( _x( 'New %s Name', 'New taxonomy name', 'pollux' ), $args['single'] ), |
|
152 | - 'not_found' => sprintf( _x( 'No %s found', 'No taxonomies found', 'pollux' ), $args['plural'] ), |
|
153 | - 'search_items' => sprintf( _x( 'Search %s', 'Search taxonomies', 'pollux' ), $args['plural'] ), |
|
154 | - 'singular_name' => $args['single'], |
|
155 | - 'update_item' => sprintf( _x( 'Update %s', 'Update taxonomy', 'pollux' ), $args['single'] ), |
|
156 | - 'view_item' => sprintf( _x( 'View %s', 'View taxonomy', 'pollux' ), $args['single'] ), |
|
146 | + 'add_new_item' => sprintf( _x( 'Add New %s', 'Add new taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
147 | + 'all_items' => sprintf( _x( 'All %s', 'All taxonomies', 'pollux' ), $args[ 'plural' ] ), |
|
148 | + 'edit_item' => sprintf( _x( 'Edit %s', 'Edit taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
149 | + 'menu_name' => $this->normalizeMenuName( $args[ 'menu_name' ], $args ), |
|
150 | + 'name' => $args[ 'plural' ], |
|
151 | + 'new_item_name' => sprintf( _x( 'New %s Name', 'New taxonomy name', 'pollux' ), $args[ 'single' ] ), |
|
152 | + 'not_found' => sprintf( _x( 'No %s found', 'No taxonomies found', 'pollux' ), $args[ 'plural' ] ), |
|
153 | + 'search_items' => sprintf( _x( 'Search %s', 'Search taxonomies', 'pollux' ), $args[ 'plural' ] ), |
|
154 | + 'singular_name' => $args[ 'single' ], |
|
155 | + 'update_item' => sprintf( _x( 'Update %s', 'Update taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
156 | + 'view_item' => sprintf( _x( 'View %s', 'View taxonomy', 'pollux' ), $args[ 'single' ] ), |
|
157 | 157 | ], $args ); |
158 | 158 | } |
159 | 159 | } |
@@ -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( !isset( $vars[$taxonomy] ))return; |
|
54 | + if( !isset( $vars[$taxonomy] )) { |
|
55 | + return; |
|
56 | + } |
|
53 | 57 | if( $term = get_term_by( 'id', $vars[$taxonomy], $taxonomy )) { |
54 | 58 | $vars[$taxonomy] = $term->slug; |
55 | 59 | } |
@@ -64,7 +68,9 @@ discard block |
||
64 | 68 | { |
65 | 69 | global $wp_query; |
66 | 70 | foreach( $this->taxonomies as $taxonomy => $args ) { |
67 | - if( !in_array( get_current_screen()->post_type, $args['post_types'] ))continue; |
|
71 | + if( !in_array( get_current_screen()->post_type, $args['post_types'] )) { |
|
72 | + continue; |
|
73 | + } |
|
68 | 74 | $selected = isset( $wp_query->query[$taxonomy] ) |
69 | 75 | ? $wp_query->query[$taxonomy] |
70 | 76 | : false; |
@@ -84,7 +90,8 @@ discard block |
||
84 | 90 | */ |
85 | 91 | public function register() |
86 | 92 | { |
87 | - array_walk( $this->taxonomies, function( $args, $taxonomy ) { |
|
93 | + array_walk( $this->taxonomies, function( $args, $taxonomy ) |
|
94 | + { |
|
88 | 95 | register_taxonomy( $taxonomy, $args['post_types'], array_diff_key( $args, array_flip( self::CUSTOM_KEYS ))); |
89 | 96 | foreach( $args['post_types'] as $type ) { |
90 | 97 | register_taxonomy_for_object_type( $taxonomy, $type ); |