4: Preconfigured Hooks
In NOUVEAU all the usual hooks are already set up for you.
To start customizing your theme, you simply need to edit the appropriate hook class/file and locate the method you need, which should be logically named and located in the NV/hooks
directory.
Each file contains a single static class. The classes are little more than an organizational structure, while their respective methods correspond to a hook.
Hooked Files & Classes
_pluggable.php
This contains any pluggable WordPress functions you want to include in your theme. In this case, the underscore prefix tells you that this is a global scope file. Any functions declared in it will be available in PHP’s global scope.
Config.php
The \NV\Hooks\Config
class contains methods that are related to general theme setup and configuration.
This includes features like:
- Configuring the theme with the
after_setup_theme
hook - Enqueuing scripts and styles
- Loading languages
- Customizing the automatic body class
- Configuring sidebars
Editor.php
The \NV\Hooks\Editor
class contains methods that are hooked into WordPress’s TinyMCE editor. When you need to add features to the TinyMCE editor, this is where you should start.
ThemeCustomize.php
The \NV\Hooks\ThemeCustomize
class contains methods that are hooked into theme & frontend-oriented features.
Anonymous Functions
NOUVEAU requires PHP 5.3+ to function, so don’t be afraid to use anonymous functions in WordPress hooks or callbacks, when appropriate. This is ideal for circumstances when a hook needs to do nothing more than load a template file or execute a single line of code.
An example of an anonymous function as a WordPress callback might look like this:
<br />
add_theme_page(<br />
__( 'Example Admin Page', 'nvLangScope' ),<br />
__( 'Example Page', 'nvLangScope' ),<br />
'manage_options',<br />
'example-nouveau-admin',<br />
function(){ require 'template-file.php'; } //anonymous function<br />
);<br />
If your anonymous function is going to be longer than a line or two, or if it might need to be re-used, it might be better to create a named function or method instead. Nevertheless, this one feature of PHP 5.3 can be a huge benefit to WordPress developers.
This page was last updated on September 15, 2016 – it is currently considered COMPLETE.