|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Modules\Html; |
|
7
|
|
|
|
|
8
|
|
|
class TaxonomyController |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @return void |
|
12
|
|
|
* @action Application::TAXONOMY._add_form_fields |
|
13
|
|
|
* @action Application::TAXONOMY._edit_form |
|
14
|
|
|
*/ |
|
15
|
|
|
public function disableParents() |
|
16
|
|
|
{ |
|
17
|
|
|
global $wp_taxonomies; |
|
18
|
|
|
$wp_taxonomies[Application::TAXONOMY]->hierarchical = false; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return void |
|
23
|
|
|
* @action Application::TAXONOMY._term_edit_form_top |
|
24
|
|
|
* @action Application::TAXONOMY._term_new_form_tag |
|
25
|
|
|
*/ |
|
26
|
|
|
public function enableParents() |
|
27
|
|
|
{ |
|
28
|
|
|
global $wp_taxonomies; |
|
29
|
|
|
$wp_taxonomies[Application::TAXONOMY]->hierarchical = true; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return void |
|
34
|
|
|
* @action restrict_manage_posts |
|
35
|
|
|
*/ |
|
36
|
|
|
public function renderTaxonomyFilter() |
|
37
|
|
|
{ |
|
38
|
|
|
if( !is_object_in_taxonomy( get_current_screen()->post_type, Application::TAXONOMY ))return; |
|
39
|
|
|
glsr( Html::class )->render()->label( __( 'Filter by category', 'site-reviews' ), [ |
|
40
|
|
|
'class' => 'screen-reader-text', |
|
41
|
|
|
'for' => Application::TAXONOMY, |
|
42
|
|
|
]); |
|
43
|
|
|
wp_dropdown_categories([ |
|
44
|
|
|
'depth' => 3, |
|
45
|
|
|
'hide_empty' => true, |
|
46
|
|
|
'hide_if_empty' => true, |
|
47
|
|
|
'hierarchical' => true, |
|
48
|
|
|
'name' => Application::TAXONOMY, |
|
49
|
|
|
'orderby' => 'name', |
|
50
|
|
|
'selected' => $this->getSelected(), |
|
51
|
|
|
'show_count' => false, |
|
52
|
|
|
'show_option_all' => $this->getShowOptionAll(), |
|
53
|
|
|
'taxonomy' => Application::TAXONOMY, |
|
54
|
|
|
'value_field' => 'slug', |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function getSelected() |
|
62
|
|
|
{ |
|
63
|
|
|
global $wp_query; |
|
|
|
|
|
|
64
|
|
|
return isset( $wp_query->query[Application::TAXONOMY] ) |
|
65
|
|
|
? $wp_query->query[Application::TAXONOMY] |
|
66
|
|
|
: ''; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function getShowOptionAll() |
|
73
|
|
|
{ |
|
74
|
|
|
$taxonomy = get_taxonomy( Application::TAXONOMY ); |
|
75
|
|
|
return $taxonomy |
|
76
|
|
|
? ucfirst( strtolower( $taxonomy->labels->all_items )) |
|
77
|
|
|
: ''; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state