Remove ConditonalTagCheck class

This commit is contained in:
QWp6t
2015-08-11 18:46:58 -07:00
parent 12fe047368
commit 6d05c67f44
4 changed files with 10 additions and 73 deletions

View File

@@ -1,4 +1,5 @@
### HEAD ### HEAD
* Remove ConditionalTagCheck class ([#1494](https://github.com/roots/sage/pull/1494))
* Add search templates ([#1459](https://github.com/roots/sage/issues/1459)) * Add search templates ([#1459](https://github.com/roots/sage/issues/1459))
* Allow `debugger` statements in development JavaScript ([#1487](https://github.com/roots/sage/issues/1487)) * Allow `debugger` statements in development JavaScript ([#1487](https://github.com/roots/sage/issues/1487))

View File

@@ -13,7 +13,6 @@ $sage_includes = [
'lib/utils.php', // Utility functions 'lib/utils.php', // Utility functions
'lib/init.php', // Initial theme setup and constants 'lib/init.php', // Initial theme setup and constants
'lib/wrapper.php', // Theme wrapper class 'lib/wrapper.php', // Theme wrapper class
'lib/conditional-tag-check.php', // ConditionalTagCheck class
'lib/config.php', // Configuration 'lib/config.php', // Configuration
'lib/assets.php', // Scripts and stylesheets 'lib/assets.php', // Scripts and stylesheets
'lib/titles.php', // Page titles 'lib/titles.php', // Page titles

View File

@@ -1,43 +0,0 @@
<?php
namespace Roots\Sage;
/**
* Utility class which takes an array of conditional tags (or any function which returns a boolean)
* and returns `false` if *any* of them are `true`, and `true` otherwise.
*
* @param array list of conditional tags (http://codex.wordpress.org/Conditional_Tags)
* or custom function which returns a boolean
*
* @return boolean
*/
class ConditionalTagCheck {
private $conditionals;
public $result = true;
public function __construct($conditionals = []) {
$this->conditionals = $conditionals;
$conditionals = array_map([$this, 'checkConditionalTag'], $this->conditionals);
if (in_array(true, $conditionals)) {
$this->result = false;
}
}
private function checkConditionalTag($conditional) {
if (is_array($conditional)) {
list($tag, $args) = $conditional;
} else {
$tag = $conditional;
$args = false;
}
if (function_exists($tag)) {
return $args ? $tag($args) : $tag();
} else {
return false;
}
}
}

View File

@@ -28,38 +28,18 @@ if (!defined('DIST_DIR')) {
} }
/** /**
* Define which pages shouldn't have the sidebar * Determine which pages should NOT display the sidebar
*/ */
function display_sidebar() { function display_sidebar() {
static $display; static $display;
if (!isset($display)) { isset($display) || $display = !in_array(true, [
$conditionalCheck = new ConditionalTagCheck( // The sidebar will NOT be displayed if ANY of the following return true.
/** // @link https://codex.wordpress.org/Conditional_Tags
* Any of these conditional tags that return true won't show the sidebar. is_404(),
* You can also specify your own custom function as long as it returns a boolean. is_front_page(),
* is_page_template('template-custom.php'),
* To use a function that accepts arguments, use an array instead of just the function name as a string. ]);
*
* Examples:
*
* 'is_single'
* 'is_archive'
* ['is_page', 'about-me']
* ['is_tax', ['flavor', 'mild']]
* ['is_page_template', 'about.php']
* ['is_post_type_archive', ['foo', 'bar', 'baz']]
*
*/
[
'is_404',
'is_front_page',
['is_page_template', 'template-custom.php']
]
);
$display = apply_filters('sage/display_sidebar', $conditionalCheck->result); return apply_filters('sage/display_sidebar', $display);
}
return $display;
} }