Configuration - mixatheme/Wireframe GitHub Wiki

NOTE: THIS WIKI PAGE WAS WRITTEN WAY BACK IN 2015 FOR WIREFRAME ALPHA. WE ARE CURRENTLY IN THE PROCESS OF UPDATING THESE DOCS HOPEFULLY FOR A JUNE 2017 RELEASE. THANK YOU FOR YOUR PATIENCE.

Bootstrapping

Wireframe uses WordPress' functions.php essentially as its own bootstrapper where most of the configuration, setup and default weirdness happens. The functions.php file is split up into easy-to-read and well-documented sections:

💡 TIP |

Wireframe's functions.php file is gigant0r. We recommend using code folding in your IDE or Text Editor, then only work on the blocks you need at any given time. In case you're wondering, we use Sublime Text 3 with Seti_UI. |

Namespaces

Declare your namespaces and any sub-namespace dependencies in all of your class files. In your functions.php file, you need to declare all sub-namespace dependencies. If you create or extend a class, don't forget to add your namespace dependencies and maybe recompile your autoloader for changes to take effect.

Example of the Wireframe Namespace:

// Namespace for base classes in: wireframe_dev/classes.
namespace MIXA\Wireframe\Base;
// Namespace for a dependency in: wireframe_dev/classes.
namespace MIXA\Wireframe\Dependency;
// Namespace for an optional module in: wireframe_dev/modules.
namespace MIXA\Wireframe\Module;

Example use in Wireframe's functions.php Namespaces section:

// Your theme's base namespace alias declarations.
use MIXA\Wireframe\Base\Theme;
use MIXA\Wireframe\Base\Container;
// These declarations use a sub-namespace name for dependencies.
use MIXA\Wireframe\Dependency\Language;
use MIXA\Wireframe\Dependency\Features;
use MIXA\Wireframe\Dependency\Enqueue;
use MIXA\Wireframe\Dependency\Widgets;
use MIXA\Wireframe\Dependency\Navigation;
// These declarations use a sub-namespace name for modules.
use MIXA\Wireframe\Module\Walker;
use MIXA\Wireframe\Module\Editor;
use MIXA\Wireframe\Module\Customizer;

💡 TIP |

Don't forget to add an alias use MIXA\Wireframe\<sub-namespace>\<Object> declaration within your template files. |

Top

Constants

After declaring your namespaces, you set the global constants you need throughout your custom WordPress theme.

Example of the Wireframe Constants section:

define( 'WIREFRAME_WALKERS',  WIREFRAME_DEV . 'walkers' . DS );
define( 'WIREFRAME_CLASSES',  WIREFRAME_DEV . 'classes' . DS );
define( 'WIREFRAME_AUTOLOAD', WIREFRAME_DEV . 'vendor' . DS );

Top

Closures

Wireframe "closures" hold arrays of config variables. Your base Theme() object uses these closures to pass arguments into your dependency objects (as a parameter).

Example of a Wireframe closure with an array of config variables:

// The $features closure is passed to (object) Features().
$features = function() {
    $post_formats = array(
        'aside',
        'image',
        'video',
        'quote',
        'link',
        'gallery',
        'status',
        'audio',
        'chat',
    );
    return array(
		'post_formats' => $post_formats
	);
};

💡 TIP |

Since PHP 5.3 you can use anonymous functions. Wireframe is not compatible with PHP 5.2. |

💡 TIP: |

Since PHP 5.4 you can use array brackets [ ] but Wireframe uses array() downstream to better identify arrays or for search & replace situations. |

Top

Wireframe

You can now "wire" all your dependencies together (hence, the name, Wireframe) by instantiating your dependencies into Wireframe's Theme() object. Voila! Happy Dance?

Example of multiple Wireframe objects passed into the Theme() base object:

// Your new `theme` container!
// Use closures for passing config variables into your objects.
$container->theme = function () use (
        
        $container, $language, $features, $enqueue, $navigation,
        $widgets, $editor, $customizer ) {
	
        // Instantiate your `Theme` object with your dependency objects.
        // Dependencies accept a closure (with parenthesis) as a parameter.
        return new Theme(
		new Language( $language() ),
		new Features( $features() ),
		new Enqueue( $enqueue() ),
		new Navigation( $navigation() ),
		new Widgets( $widgets() ),
		new Editor( $editor() ),
		new Customizer( $customizer() )
	);
};

💡 TIP: |

You might habitually add a comma at the end of array arguments, but do not add a trailing comma on the last parameter of an object. |

Top

Helpers

Some of your template files and objects may use helper functions. You need to grab them so they're available throughout your theme.

Example of the Wireframe Helpers section:

require_once WIREFRAME_HELPERS . 'custom-header.php';
require_once WIREFRAME_HELPERS . 'template-tags.php';
require_once WIREFRAME_HELPERS . 'extras.php';
require_once WIREFRAME_HELPERS . 'jetpack.php';

💡 TIP: |

You can use require() or require_once() on final parent files. If you wish to allow child theme overloading, you can use the locate_template() function. |

Top

Hooks

After your objects are initialized, you can target any public object method you need using hooks. You generally do not need to run hooks via the __construct() magic method, since you can fire hooks via functions.php like so...

Example of the Wireframe Hooks section:

// Hook object methods with array callable syntax.
add_action( 'after_setup_theme', array( $wireframe->features(), 'post_formats' ) );

Top

💡 TIP |

After you get the hang of Wireframe, you'll probably want to condense things. You may wish to split the functions.php file into multiple includes for maintainability. Our main objective was to bootstrap ALL config variables in 1 single file for your development pleasure. |

⚠️ **GitHub.com Fallback** ⚠️