Update PHP files to pass coding standards

This commit is contained in:
Ben Word
2015-01-24 00:48:50 -06:00
parent 33fe490cb0
commit f4d64d23c9
8 changed files with 32 additions and 29 deletions

View File

@@ -93,7 +93,7 @@ function google_analytics() {
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
<?php else: ?>
<?php else : ?>
function ga() {
if (window.console) {
console.log('Google Analytics: ' + [].slice.call(arguments));

View File

@@ -1,6 +1,7 @@
<?php
namespace Roots\Sage\Config;
use Roots\Sage\Sidebar;
/**
@@ -41,7 +42,7 @@ function display_sidebar() {
static $display;
if (!isset($display)) {
$sidebar_config = new Sidebar\Sage_Sidebar(
$sidebar_config = new Sidebar\SageSidebar(
/**
* Conditional tag checks (http://codex.wordpress.org/Conditional_Tags)
* Any of these conditional tags that return true won't show the sidebar

View File

@@ -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-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-sample-page"><a href="/sample-page/">Sample Page</a></li>
*/
class Sage_Nav_Walker extends \Walker_Nav_Menu {
function check_current($classes) {
class SageNavWalker extends \Walker_Nav_Menu {
public function checkCurrent($classes) {
return preg_match('/(current[-_])|active|dropdown/', $classes);
}
// @codingStandardsIgnoreStart
function start_lvl(&$output, $depth = 0, $args = []) {
$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)) {
$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);
}
elseif (stristr($item_html, 'li class="divider')) {
} elseif (stristr($item_html, 'li class="divider')) {
$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);
}
@@ -50,6 +49,7 @@ class Sage_Nav_Walker extends \Walker_Nav_Menu {
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
*
* Remove the container
* Use Sage_Nav_Walker() by default
* Use SageNavWalker() by default
*/
function nav_menu_args($args = '') {
$nav_menu_args = [];

View File

@@ -14,25 +14,25 @@ namespace Roots\Sage\Sidebar;
*
* @return boolean True will display the sidebar, False will not
*/
class Sage_Sidebar {
class SageSidebar {
private $conditionals;
private $templates;
public $display = true;
function __construct($conditionals = [], $templates = []) {
public function __construct($conditionals = [], $templates = []) {
$this->conditionals = $conditionals;
$this->templates = $templates;
$conditionals = array_map([$this, 'check_conditional_tag'], $this->conditionals);
$templates = array_map([$this, 'check_page_template'], $this->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 check_conditional_tag($conditional_tag) {
private function checkConditionalTag($conditional_tag) {
$conditional_arg = is_array($conditional_tag) ? $conditional_tag[1] : false;
$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);
}
}

View File

@@ -10,14 +10,14 @@ namespace Roots\Sage\Wrapper;
*/
function template_path() {
return Sage_Wrapping::$main_template;
return SageWrapping::$main_template;
}
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
public static $main_template;
@@ -28,7 +28,7 @@ class Sage_Wrapping {
public $templates;
// 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') {
$this->slug = basename($template, '.php');
@@ -45,7 +45,7 @@ class Sage_Wrapping {
return locate_template($this->templates);
}
static function wrap($main) {
public static function wrap($main) {
// Check for other filters returning null
if (!is_string($main)) {
return $main;
@@ -58,7 +58,7 @@ class Sage_Wrapping {
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);