diff --git a/functions.php b/functions.php index c90e6bb..9485636 100644 --- a/functions.php +++ b/functions.php @@ -10,16 +10,16 @@ * @link https://github.com/roots/sage/pull/1042 */ $sage_includes = [ - 'lib/utils.php', // Utility functions - 'lib/init.php', // Initial theme setup and constants - 'lib/wrapper.php', // Theme wrapper class - 'lib/sidebar.php', // Sidebar class - 'lib/config.php', // Configuration - 'lib/assets.php', // Scripts and stylesheets - 'lib/titles.php', // Page titles - 'lib/nav.php', // Custom nav modifications - 'lib/gallery.php', // Custom [gallery] modifications - 'lib/extras.php', // Custom functions + 'lib/utils.php', // Utility functions + 'lib/init.php', // Initial theme setup and constants + 'lib/wrapper.php', // Theme wrapper class + 'lib/conditional-tag-check.php', // ConditionalTagCheck class + 'lib/config.php', // Configuration + 'lib/assets.php', // Scripts and stylesheets + 'lib/titles.php', // Page titles + 'lib/nav.php', // Custom nav modifications + 'lib/gallery.php', // Custom [gallery] modifications + 'lib/extras.php', // Custom functions ]; foreach ($sage_includes as $file) { diff --git a/lib/conditional-tag-check.php b/lib/conditional-tag-check.php new file mode 100644 index 0000000..e16169b --- /dev/null +++ b/lib/conditional-tag-check.php @@ -0,0 +1,39 @@ +conditionals = $conditionals; + + $conditionals = array_map([$this, 'checkConditionalTag'], $this->conditionals); + + if (in_array(true, $conditionals)) { + $this->result = false; + } + } + + private function checkConditionalTag($conditional_tag) { + $conditional_arg = is_array($conditional_tag) ? $conditional_tag[1] : false; + $conditional_tag = $conditional_arg ? $conditional_tag[0] : $conditional_tag; + + if (function_exists($conditional_tag)) { + return $conditional_arg ? $conditional_tag($conditional_arg) : $conditional_tag(); + } else { + return false; + } + } +} diff --git a/lib/config.php b/lib/config.php index 3579b1a..f97441a 100644 --- a/lib/config.php +++ b/lib/config.php @@ -2,7 +2,7 @@ namespace Roots\Sage\Config; -use Roots\Sage\Sidebar; +use Roots\Sage; /** * Enable theme features @@ -42,30 +42,33 @@ function display_sidebar() { static $display; if (!isset($display)) { - $sidebar_config = new Sidebar\SageSidebar( + $conditionalCheck = new ConditionalTagCheck( /** - * Conditional tag checks (http://codex.wordpress.org/Conditional_Tags) - * 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. * * To use a function that accepts arguments, use the following format: * * ['function_name', ['arg1', 'arg2']] * - * The second element must be an array even if there's only 1 argument. + * Note: The second element must be an array even if there's only 1 argument. + * + * Examples: + * + * 'is_single' + * ['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' - ], - /** - * Page template checks (via is_page_template()) - * Any of these page templates that return true won't show the sidebar - */ - [ - 'template-custom.php' ] ); - $display = apply_filters('sage/display_sidebar', $sidebar_config->display); + + $display = apply_filters('sage/display_sidebar', $conditionalCheck->result); } return $display; diff --git a/lib/sidebar.php b/lib/sidebar.php deleted file mode 100644 index 1260668..0000000 --- a/lib/sidebar.php +++ /dev/null @@ -1,51 +0,0 @@ -conditionals = $conditionals; - $this->templates = $templates; - - $conditionals = array_map([$this, 'checkConditionalTag'], $this->conditionals); - $templates = array_map([$this, 'checkPageTemplate'], $this->templates); - - if (in_array(true, $conditionals) || in_array(true, $templates)) { - $this->display = false; - } - } - - private function checkConditionalTag($conditional_tag) { - $conditional_arg = is_array($conditional_tag) ? $conditional_tag[1] : false; - $conditional_tag = $conditional_arg ? $conditional_tag[0] : $conditional_tag; - - if (function_exists($conditional_tag)) { - return $conditional_arg ? $conditional_tag($conditional_arg) : $conditional_tag(); - } else { - return false; - } - } - - private function checkPageTemplate($page_template) { - return is_page_template($page_template) || Wrapper\SageWrapping::$base . '.php' === $page_template; - } -}