Merge pull request #1365 from roots/conditional-tag-check-args-fix
Update ConditionalTagCheck and usage docs
This commit is contained in:
@@ -26,12 +26,16 @@ class ConditionalTagCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkConditionalTag($conditional_tag) {
|
private function checkConditionalTag($conditional) {
|
||||||
$conditional_arg = is_array($conditional_tag) ? $conditional_tag[1] : false;
|
if (is_array($conditional)) {
|
||||||
$conditional_tag = $conditional_arg ? $conditional_tag[0] : $conditional_tag;
|
list($tag, $args) = $conditional;
|
||||||
|
} else {
|
||||||
|
$tag = $conditional;
|
||||||
|
$args = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (function_exists($conditional_tag)) {
|
if (function_exists($tag)) {
|
||||||
return $conditional_arg ? $conditional_tag($conditional_arg) : $conditional_tag();
|
return $args ? $tag($args) : $tag();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,26 +39,22 @@ function display_sidebar() {
|
|||||||
* Any of these conditional tags that return true won't show the sidebar.
|
* Any of these conditional tags that return true won't show the sidebar.
|
||||||
* You can also specify your own custom function as long as it returns a boolean.
|
* You can also specify your own custom function as long as it returns a boolean.
|
||||||
*
|
*
|
||||||
* To use a function that accepts arguments, use the following format:
|
* To use a function that accepts arguments, use an array instead of just the function name as a string.
|
||||||
*
|
|
||||||
* ['function_name', ['arg1', 'arg2']]
|
|
||||||
*
|
|
||||||
* Note: The second element must be an array even if there's only 1 argument.
|
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
* 'is_single'
|
* 'is_single'
|
||||||
* 'is_archive'
|
* 'is_archive'
|
||||||
* ['is_page', ['about-me']]
|
* ['is_page', 'about-me']
|
||||||
* ['is_tax', ['flavor', 'mild']]
|
* ['is_tax', ['flavor', 'mild']]
|
||||||
* ['is_page_template', ['about.php']]
|
* ['is_page_template', 'about.php']
|
||||||
* ['is_post_type_archive', [['foo', 'bar', 'baz']]]
|
* ['is_post_type_archive', ['foo', 'bar', 'baz']]
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
[
|
[
|
||||||
'is_404',
|
'is_404',
|
||||||
'is_front_page',
|
'is_front_page',
|
||||||
['is_page_template', ['template-custom.php']]
|
['is_page_template', 'template-custom.php']
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user