Last active
August 29, 2015 14:19
-
-
Save GuerrillaCoder/2a439634cb2c2a589a45 to your computer and use it in GitHub Desktop.
Idea for set up structure
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
<?php | |
namespace themename\setup; | |
//todo: abstract actual values to another object and pass it to this contructor | |
class MainThemeSetupMaster | |
{ | |
private $cssSetup; | |
private $jsSetup; | |
public function __construct() | |
{ | |
$this->cssSetup = new CssSetup(); | |
$this->jsSetup = new ScriptSetup(); | |
} | |
public function initScripts() | |
{ | |
$this->cssSetup->init(); | |
$this->jsSetup->init(); | |
} | |
} | |
class CssSetup | |
{ | |
public function init() | |
{ | |
// call privates | |
add_action( 'wp_enqueue_scripts', | |
function () | |
{ | |
$this->_theme_styles(); | |
}); | |
add_action( 'wp_enqueue_scripts', | |
function () | |
{ | |
$this->_vendor_styles(); | |
}); | |
} | |
private function _theme_styles() | |
{ | |
// queue theme styles | |
} | |
private function _vendor_styles() | |
{ | |
// queue vendor styles | |
} | |
} | |
class ScriptSetup | |
{ | |
public function init() | |
{ | |
// call privates | |
add_action( 'wp_enqueue_scripts', | |
function () | |
{ | |
$this->_theme_scripts(); | |
}); | |
add_action( 'wp_enqueue_scripts', | |
function () | |
{ | |
$this->_vendor_scripts(); | |
}); | |
} | |
private function _theme_scripts() | |
{ | |
// queue theme scripts | |
} | |
private function _vendor_scripts() | |
{ | |
// queue vendor scripts | |
} | |
} |
Looks good.
One thing I'd probably do slightly different is start with all of those classes being just one class that handles all the CSS/JS/etc. and then only split them out into different classes if they become too complex. Otherwise you have to switch context a lot between the different classes. If you do that, you'll find that it cuts the size of the current file at least in half.
Cool thanks. I am going to refactor it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thinking of having one main set up class that can be called like:
I would then just add other functions like initPlugins() or whatever.
Am I on the right track or is there better way?