|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Page Framework |
|
4
|
|
|
* |
|
5
|
|
|
* http://admin-page-framework.michaeluno.jp/ |
|
6
|
|
|
* Copyright (c) 2013-2022, Michael Uno; Licensed MIT |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Provides methods for rendering taxonomy check lists. |
|
12
|
|
|
* |
|
13
|
|
|
* Used for the wp_list_categories() function to render category hierarchical checklist. |
|
14
|
|
|
* |
|
15
|
|
|
* @see Walker : wp-includes/class-wp-walker.php |
|
16
|
|
|
* @see Walker_Category : wp-includes/category-template.php |
|
17
|
|
|
* @since 2.0.0 |
|
18
|
|
|
* @since 2.1.5 Added the tag_id key to the argument array. Changed the format of 'id' and 'for' attribute of the input and label tags. |
|
19
|
|
|
* @extends Walker_Category |
|
20
|
|
|
* @package AdminPageFramework/Common/Form/FieldType |
|
21
|
|
|
* @internal |
|
22
|
|
|
*/ |
|
23
|
|
|
class AdminPageFramework_WalkerTaxonomyChecklist extends Walker_Category { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Modifies the variable string the opening 'li' tag of the list. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $sOutput |
|
29
|
|
|
* @param object $oTerm |
|
30
|
|
|
* @param integer $iDepth |
|
31
|
|
|
* @param array $aArgs The argument passed from the field output. |
|
32
|
|
|
* <h4>Arguments</h4> |
|
33
|
|
|
* - show_option_all (string) Text to display for showing all categories. default: `` |
|
34
|
|
|
* - show_option_none (string) Text to display for showing no categories. e.g. `__( 'No categories' )` |
|
35
|
|
|
* - orderby (string) Accepts 'name' or 'ID'. What column to use for ordering the terms. e.g. `name`. default: `ID` |
|
36
|
|
|
* - order (string) What direction to order categories. Accepts 'ASC' (ascending) or 'DESC' (descending). default: `ASC` |
|
37
|
|
|
* - title_li (string) The string that is inserted before the list starts. Default: __( 'Categories' ), |
|
38
|
|
|
* - echo (boolean|integer) Whether to echo the output or return the output string value. |
|
39
|
|
|
* - hierarchical (boolean) Whether to show the terms in a hierarchical structure. |
|
40
|
|
|
* - depth (integer) The max level to display the hierarchical depth. Default: 0. |
|
41
|
|
|
* - hide_empty (boolean|integer) Whether to hide terms that have no post associated. |
|
42
|
|
|
* - pad_counts (boolean|integer) Whether to sum up the post count with the child post counts. |
|
43
|
|
|
* - number (integer) The maximum number of terms to display. Default 0. |
|
44
|
|
|
* - exclude (string) Comma separated term ID(s) to exclude from the list. |
|
45
|
|
|
* - include (string) Comma separated term ID(s) to include in the list. |
|
46
|
|
|
* - child_of (integer) Term ID to retrieve child terms of. If multiple taxonomies are passed, $child_of is ignored. Default 0. |
|
47
|
|
|
* |
|
48
|
|
|
* <h4>Known Existing Arguments</h4> |
|
49
|
|
|
* - feed => '', |
|
50
|
|
|
* - feed_type => '', |
|
51
|
|
|
* - feed_image => '', |
|
52
|
|
|
* - exclude_tree => '', |
|
53
|
|
|
* - current_category => 0, |
|
54
|
|
|
* - class => categories, |
|
55
|
|
|
* |
|
56
|
|
|
* <h4>Unknown Arguments</h4> |
|
57
|
|
|
* - taxonomy => 'category', // 'post_tag' or any other registered taxonomy slug will work. side note: the framework option will be used |
|
58
|
|
|
* - has_children => 1, |
|
59
|
|
|
* - option_none_value (mixed) Value to use when no taxonomy term is selected. |
|
60
|
|
|
* - show_count (bool|int) Whether to show how many posts are associated with the term. default: `0` side note: did not take effect |
|
61
|
|
|
* - style (string) 'list', side note: Could not confirm whether there are other option besides 'list'. |
|
62
|
|
|
* - use_desc_for_title (boolean|int) default is 1 - Whether to use the category description as the title attribute. side note: the framework enables this by default. |
|
63
|
|
|
* @param integer $iCurrentObjectID |
|
64
|
|
|
*/ |
|
65
|
|
|
function start_el( &$sOutput, $oTerm, $iDepth=0, $aArgs=array(), $iCurrentObjectID=0 ) { |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$aArgs = $aArgs + array( |
|
68
|
|
|
'_name_prefix' => null, |
|
69
|
|
|
'_input_id_prefix' => null, |
|
70
|
|
|
'_attributes' => array(), |
|
71
|
|
|
'_selected_items' => array(), |
|
72
|
|
|
'taxonomy' => null, // parsed by the core function to perform the database query. |
|
73
|
|
|
'disabled' => null, // not sure what this was for |
|
74
|
|
|
'_save_unchecked' => true, // 3.8.8+ |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
// Local variables |
|
78
|
|
|
$_iID = $oTerm->term_id; |
|
79
|
|
|
$_sTaxonomySlug = empty( $aArgs[ 'taxonomy' ] ) |
|
80
|
|
|
? 'category' |
|
81
|
|
|
: $aArgs[ 'taxonomy' ]; |
|
82
|
|
|
$_sID = "{$aArgs[ '_input_id_prefix' ]}_{$_sTaxonomySlug}_{$_iID}"; |
|
83
|
|
|
|
|
84
|
|
|
// Post count |
|
85
|
|
|
$_sPostCount = $aArgs[ 'show_post_count' ] |
|
86
|
|
|
? " <span class='font-lighter'>(" . $oTerm->count . ")</span>" |
|
87
|
|
|
: ''; |
|
88
|
|
|
|
|
89
|
|
|
// Attributes |
|
90
|
|
|
$_aInputAttributes = isset( $_aInputAttributes[ $_iID ] ) |
|
|
|
|
|
|
91
|
|
|
? $_aInputAttributes[ $_iID ] + $aArgs[ '_attributes' ] |
|
92
|
|
|
: $aArgs[ '_attributes' ]; |
|
93
|
|
|
$_aInputAttributes = array( |
|
94
|
|
|
'id' => $_sID, |
|
95
|
|
|
'value' => 1, // must be 1 because the index of zero exists so the index value cannot be assigned here. |
|
96
|
|
|
'type' => 'checkbox', |
|
97
|
|
|
'name' => "{$aArgs[ '_name_prefix' ]}[{$_iID}]", |
|
98
|
|
|
'checked' => in_array( $_iID, ( array ) $aArgs[ '_selected_items' ] ) |
|
99
|
|
|
? 'checked' |
|
100
|
|
|
: null, |
|
101
|
|
|
) + $_aInputAttributes |
|
102
|
|
|
+ array( |
|
103
|
|
|
'class' => null, |
|
104
|
|
|
); |
|
105
|
|
|
$_aInputAttributes['class'] .= ' apf_checkbox'; |
|
106
|
|
|
|
|
107
|
|
|
$_aLiTagAttributes = array( |
|
108
|
|
|
'id' => "list-{$_sID}", |
|
109
|
|
|
'class' => 'category-list', |
|
110
|
|
|
'title' => $oTerm->description, |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
|
|
$_sHiddenInputForUnchecked = $aArgs[ '_save_unchecked' ] |
|
114
|
|
|
? "<input value='0' type='hidden' name='" . $_aInputAttributes[ 'name' ] . "' class='apf_checkbox' />" |
|
115
|
|
|
: ''; |
|
116
|
|
|
|
|
117
|
|
|
// Output - the variable is by reference so the modification takes effect |
|
118
|
|
|
$sOutput .= "\n" |
|
119
|
|
|
. "<li " . AdminPageFramework_WPUtility::getAttributes( $_aLiTagAttributes ) . ">" |
|
120
|
|
|
. "<label for='{$_sID}' class='taxonomy-checklist-label'>" |
|
121
|
|
|
. $_sHiddenInputForUnchecked // 3.8.8+ |
|
122
|
|
|
. "<input " . AdminPageFramework_WPUtility::getAttributes( $_aInputAttributes ) . " />" |
|
123
|
|
|
. esc_html( apply_filters( 'the_category', $oTerm->name ) ) |
|
124
|
|
|
. $_sPostCount |
|
125
|
|
|
. "</label>"; |
|
126
|
|
|
/* no need to close the </li> tag since it is dealt in the end_el() method. */ |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.