Update PHP files to pass coding standards
This commit is contained in:
2
base.php
2
base.php
@@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Roots\Sage;
|
namespace Roots\Sage;
|
||||||
|
|
||||||
use Roots\Sage\Config;
|
use Roots\Sage\Config;
|
||||||
use Roots\Sage\Wrapper;
|
use Roots\Sage\Wrapper;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php get_template_part('templates/head'); ?>
|
<?php get_template_part('templates/head'); ?>
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ function google_analytics() {
|
|||||||
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
|
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
|
||||||
e.src='//www.google-analytics.com/analytics.js';
|
e.src='//www.google-analytics.com/analytics.js';
|
||||||
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
|
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
|
||||||
<?php else: ?>
|
<?php else : ?>
|
||||||
function ga() {
|
function ga() {
|
||||||
if (window.console) {
|
if (window.console) {
|
||||||
console.log('Google Analytics: ' + [].slice.call(arguments));
|
console.log('Google Analytics: ' + [].slice.call(arguments));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Roots\Sage\Config;
|
namespace Roots\Sage\Config;
|
||||||
|
|
||||||
use Roots\Sage\Sidebar;
|
use Roots\Sage\Sidebar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,7 +42,7 @@ function display_sidebar() {
|
|||||||
static $display;
|
static $display;
|
||||||
|
|
||||||
if (!isset($display)) {
|
if (!isset($display)) {
|
||||||
$sidebar_config = new Sidebar\Sage_Sidebar(
|
$sidebar_config = new Sidebar\SageSidebar(
|
||||||
/**
|
/**
|
||||||
* Conditional tag checks (http://codex.wordpress.org/Conditional_Tags)
|
* 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
|
||||||
|
|||||||
16
lib/nav.php
16
lib/nav.php
@@ -9,15 +9,16 @@ namespace Roots\Sage\Nav;
|
|||||||
* <li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8"><a href="/">Home</a></li>
|
* <li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8"><a href="/">Home</a></li>
|
||||||
* <li id="menu-item-9" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-9"><a href="/sample-page/">Sample Page</a></l
|
* <li id="menu-item-9" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-9"><a href="/sample-page/">Sample Page</a></l
|
||||||
*
|
*
|
||||||
* Sage_Nav_Walker example output:
|
* SageNavWalker example output:
|
||||||
* <li class="menu-home"><a href="/">Home</a></li>
|
* <li class="menu-home"><a href="/">Home</a></li>
|
||||||
* <li class="menu-sample-page"><a href="/sample-page/">Sample Page</a></li>
|
* <li class="menu-sample-page"><a href="/sample-page/">Sample Page</a></li>
|
||||||
*/
|
*/
|
||||||
class Sage_Nav_Walker extends \Walker_Nav_Menu {
|
class SageNavWalker extends \Walker_Nav_Menu {
|
||||||
function check_current($classes) {
|
public function checkCurrent($classes) {
|
||||||
return preg_match('/(current[-_])|active|dropdown/', $classes);
|
return preg_match('/(current[-_])|active|dropdown/', $classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
function start_lvl(&$output, $depth = 0, $args = []) {
|
function start_lvl(&$output, $depth = 0, $args = []) {
|
||||||
$output .= "\n<ul class=\"dropdown-menu\">\n";
|
$output .= "\n<ul class=\"dropdown-menu\">\n";
|
||||||
}
|
}
|
||||||
@@ -29,11 +30,9 @@ class Sage_Nav_Walker extends \Walker_Nav_Menu {
|
|||||||
if ($item->is_dropdown && ($depth === 0)) {
|
if ($item->is_dropdown && ($depth === 0)) {
|
||||||
$item_html = str_replace('<a', '<a class="dropdown-toggle" data-toggle="dropdown" data-target="#"', $item_html);
|
$item_html = str_replace('<a', '<a class="dropdown-toggle" data-toggle="dropdown" data-target="#"', $item_html);
|
||||||
$item_html = str_replace('</a>', ' <b class="caret"></b></a>', $item_html);
|
$item_html = str_replace('</a>', ' <b class="caret"></b></a>', $item_html);
|
||||||
}
|
} elseif (stristr($item_html, 'li class="divider')) {
|
||||||
elseif (stristr($item_html, 'li class="divider')) {
|
|
||||||
$item_html = preg_replace('/<a[^>]*>.*?<\/a>/iU', '', $item_html);
|
$item_html = preg_replace('/<a[^>]*>.*?<\/a>/iU', '', $item_html);
|
||||||
}
|
} elseif (stristr($item_html, 'li class="dropdown-header')) {
|
||||||
elseif (stristr($item_html, 'li class="dropdown-header')) {
|
|
||||||
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html);
|
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +49,7 @@ class Sage_Nav_Walker extends \Walker_Nav_Menu {
|
|||||||
|
|
||||||
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
|
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
|
||||||
}
|
}
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +82,7 @@ add_filter('nav_menu_item_id', '__return_null');
|
|||||||
* Clean up wp_nav_menu_args
|
* Clean up wp_nav_menu_args
|
||||||
*
|
*
|
||||||
* Remove the container
|
* Remove the container
|
||||||
* Use Sage_Nav_Walker() by default
|
* Use SageNavWalker() by default
|
||||||
*/
|
*/
|
||||||
function nav_menu_args($args = '') {
|
function nav_menu_args($args = '') {
|
||||||
$nav_menu_args = [];
|
$nav_menu_args = [];
|
||||||
|
|||||||
@@ -14,25 +14,25 @@ namespace Roots\Sage\Sidebar;
|
|||||||
*
|
*
|
||||||
* @return boolean True will display the sidebar, False will not
|
* @return boolean True will display the sidebar, False will not
|
||||||
*/
|
*/
|
||||||
class Sage_Sidebar {
|
class SageSidebar {
|
||||||
private $conditionals;
|
private $conditionals;
|
||||||
private $templates;
|
private $templates;
|
||||||
|
|
||||||
public $display = true;
|
public $display = true;
|
||||||
|
|
||||||
function __construct($conditionals = [], $templates = []) {
|
public function __construct($conditionals = [], $templates = []) {
|
||||||
$this->conditionals = $conditionals;
|
$this->conditionals = $conditionals;
|
||||||
$this->templates = $templates;
|
$this->templates = $templates;
|
||||||
|
|
||||||
$conditionals = array_map([$this, 'check_conditional_tag'], $this->conditionals);
|
$conditionals = array_map([$this, 'checkConditionalTag'], $this->conditionals);
|
||||||
$templates = array_map([$this, 'check_page_template'], $this->templates);
|
$templates = array_map([$this, 'checkPageTemplate'], $this->templates);
|
||||||
|
|
||||||
if (in_array(true, $conditionals) || in_array(true, $templates)) {
|
if (in_array(true, $conditionals) || in_array(true, $templates)) {
|
||||||
$this->display = false;
|
$this->display = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function check_conditional_tag($conditional_tag) {
|
private function checkConditionalTag($conditional_tag) {
|
||||||
$conditional_arg = is_array($conditional_tag) ? $conditional_tag[1] : false;
|
$conditional_arg = is_array($conditional_tag) ? $conditional_tag[1] : false;
|
||||||
$conditional_tag = $conditional_arg ? $conditional_tag[0] : $conditional_tag;
|
$conditional_tag = $conditional_arg ? $conditional_tag[0] : $conditional_tag;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ class Sage_Sidebar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function check_page_template($page_template) {
|
private function checkPageTemplate($page_template) {
|
||||||
return is_page_template($page_template);
|
return is_page_template($page_template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ namespace Roots\Sage\Wrapper;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function template_path() {
|
function template_path() {
|
||||||
return Sage_Wrapping::$main_template;
|
return SageWrapping::$main_template;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sidebar_path() {
|
function sidebar_path() {
|
||||||
return new Sage_Wrapping('templates/sidebar.php');
|
return new SageWrapping('templates/sidebar.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sage_Wrapping {
|
class SageWrapping {
|
||||||
// Stores the full path to the main template file
|
// Stores the full path to the main template file
|
||||||
public static $main_template;
|
public static $main_template;
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class Sage_Wrapping {
|
|||||||
public $templates;
|
public $templates;
|
||||||
|
|
||||||
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
|
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
|
||||||
static $base;
|
public static $base;
|
||||||
|
|
||||||
public function __construct($template = 'base.php') {
|
public function __construct($template = 'base.php') {
|
||||||
$this->slug = basename($template, '.php');
|
$this->slug = basename($template, '.php');
|
||||||
@@ -45,7 +45,7 @@ class Sage_Wrapping {
|
|||||||
return locate_template($this->templates);
|
return locate_template($this->templates);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function wrap($main) {
|
public static function wrap($main) {
|
||||||
// Check for other filters returning null
|
// Check for other filters returning null
|
||||||
if (!is_string($main)) {
|
if (!is_string($main)) {
|
||||||
return $main;
|
return $main;
|
||||||
@@ -58,7 +58,7 @@ class Sage_Wrapping {
|
|||||||
self::$base = false;
|
self::$base = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Sage_Wrapping();
|
return new SageWrapping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_filter('template_include', [__NAMESPACE__ . '\\Sage_Wrapping', 'wrap'], 99);
|
add_filter('template_include', [__NAMESPACE__ . '\\SageWrapping', 'wrap'], 99);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
if (post_password_required()) {
|
if (post_password_required()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<section id="comments" class="comments">
|
<section id="comments" class="comments">
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
<nav class="collapse navbar-collapse" role="navigation">
|
<nav class="collapse navbar-collapse" role="navigation">
|
||||||
<?php
|
<?php
|
||||||
if (has_nav_menu('primary_navigation')) :
|
if (has_nav_menu('primary_navigation')) :
|
||||||
wp_nav_menu(['theme_location' => 'primary_navigation', 'walker' => new Nav\Sage_Nav_Walker(), 'menu_class' => 'nav navbar-nav']);
|
wp_nav_menu(['theme_location' => 'primary_navigation', 'walker' => new Nav\SageNavWalker(), 'menu_class' => 'nav navbar-nav']);
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user