forked from roots/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of editing an if statement (which could get ugly quickly), just edit configuration arrays of conditional tags and page template checks.
- Loading branch information
1 parent
33d78b7
commit 588ea8a
Showing
6 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* Determines whether or not to display the sidebar based on an array of conditional tags or page templates. | ||
* | ||
* If any of the is_* conditional tags or is_page_template(template_file) checks return true, the sidebar will NOT be displayed. | ||
* | ||
* @param array list of conditional tags (http://codex.wordpress.org/Conditional_Tags) without the 'is_' prefix | ||
* @param array list of templates without the '.php' extension. These will be checked via is_page_template() | ||
* | ||
* @return boolean True will display the sidebar, False will not | ||
* | ||
*/ | ||
class Roots_Sidebar { | ||
const EXTENSION = '.php'; | ||
private $conditionals; | ||
private $templates; | ||
public $display = true; | ||
|
||
function __construct($conditionals = array(), $templates = array()) { | ||
$this->conditionals = $conditionals; | ||
$this->templates = $templates; | ||
|
||
foreach($this->conditionals as $conditional_tag) { | ||
if ($this->check_conditional_tag($conditional_tag)) { | ||
$this->display = false; | ||
} | ||
} | ||
|
||
foreach($this->templates as $page_template) { | ||
if ($this->check_page_template($page_template)) { | ||
$this->display = false; | ||
} | ||
} | ||
} | ||
|
||
private function check_conditional_tag($conditional_tag) { | ||
$function = "is_$conditional_tag"; | ||
return $function(); | ||
} | ||
|
||
private function check_page_template($page_template) { | ||
return is_page_template($page_template . self::EXTENSION); | ||
} | ||
} | ||
|
||
?> |