Skip to content

Commit

Permalink
Replaced hardcoded directory names with constants
Browse files Browse the repository at this point in the history
Implementation of these constants in place of the hardcoded directory
names is incomplete
  • Loading branch information
kittsville committed Jun 17, 2015
1 parent d0db62e commit ef3f380
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/wp-librarian.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
* @todo Define custom post type/taxonomy names as class constants
*/
class WP_Librarian {
/**
* Paths to plugin's subdirectories
* USe these rather than hard-coding subdirectory names
*/
const SCRIPT_DIR = 'scripts';
const STYLE_DIR = 'styles';
const MINIFIED_DIR = 'data';
const CLASS_DIR = 'lib';
const HELPER_DIR = 'helpers';
const TEMPLATE_DIR = 'templates';
const ADMIN_TEMPLATE_DIR= 'admin-templates';

/**
* Path to plugin folder, without trailing slash
* @var string
Expand Down Expand Up @@ -107,15 +119,15 @@ private function registerHooks() {
* @param string $helper Name of helper file, excluding .class.php
*/
public function loadHelper($helper) {
require_once($this->plugin_path . '/helpers/' . $helper . '.class.php');
require_once($this->plugin_path . '/' . self::HELPER_DIR . '/' . $helper . '.class.php');
}

/**
* Loads library class from /lib directory
* @param string $helper Name of library to be loaded, excluding .class.php
*/
public function loadClass($library) {
require_once($this->plugin_path . '/lib/' . $library . '.class.php');
require_once($this->plugin_path . '/' . self::CLASS_DIR . '/' . $library . '.class.php');
}

/**
Expand All @@ -132,7 +144,7 @@ public function loadObjectClasses() {
* @param array $params OPTIONAL Associative array of parameters for the template
*/
public function loadAdminTemplate($name, Array $params = array()) {
require_once($this->plugin_path . '/admin-templates/' . $name . '.php');
require_once($this->plugin_path . '/' . self::ADMIN_TEMPLATE_DIR . '/' . $name . '.php');
}

/**
Expand Down Expand Up @@ -1191,9 +1203,9 @@ public function getUserRoles() {
public function getStyleUrl($name) {
// Loads minified assets in production. Regular for dev/debugging
if ((defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) || WP_LIB_DEBUG_MODE) {
return $this->plugin_url . '/styles/' . $name . '.css';
return $this->plugin_url . '/' . self::STYLE_DIR . '/' . $name . '.css';
} else {
return $this->plugin_url . '/data/' . $name . '.min.css';
return $this->plugin_url . '/' . self::MINIFIED_DIR . '/' . $name . '.min.css';
}
}

Expand All @@ -1205,9 +1217,9 @@ public function getStyleUrl($name) {
public function getScriptUrl($name) {
// Loads minified assets in production. Regular for dev/debugging
if ((defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) || WP_LIB_DEBUG_MODE) {
return $this->plugin_url . '/scripts/' . $name . '.js';
return $this->plugin_url . '/' . self::SCRIPT_DIR . '/' . $name . '.js';
} else {
return $this->plugin_url . '/data/' . $name . '.min.js';
return $this->plugin_url . '/' . self::MINIFIED_DIR . '/' . $name . '.min.js';
}
}

Expand All @@ -1217,7 +1229,7 @@ public function getScriptUrl($name) {
* @return string Full file path e.g. '.../templates/archive-wp_lib_items.php'
*/
public function getTemplateDir($name) {
return $this->plugin_path . '/templates/' . $name . '.php';
return $this->plugin_path . '/' . self::TEMPLATE_DIR . '/' . $name . '.php';
}

/*
Expand Down

0 comments on commit ef3f380

Please sign in to comment.