Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make THA easier to use for Themes supporting all the hooks.
  • Loading branch information
obenland committed Jul 9, 2012
1 parent c76a2b4 commit d1bf478
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions tha-theme-hooks.php
Expand Up @@ -24,10 +24,36 @@
define( 'THA_HOOKS_VERSION', '1.0-draft' );

/**
* Themes and Plugins can check for tha_hooks using current_theme_supports( 'tha_hooks', $hook ) to determine
* whether a theme declares itself to support this specific hook type.
* Themes and Plugins can check for tha_hooks using current_theme_supports( 'tha_hooks', $hook )
* to determine whether a theme declares itself to support this specific hook type.
*
* Example:
* <code>
* // Declare support for all hook types
* add_theme_support( 'tha_hooks', array( 'all' ) );
*
* // Declare support for certain hook types only
* add_theme_support( 'tha_hooks', array( 'header', 'content', 'footer' ) );
* </code>
*/
add_theme_support( 'tha_hooks', array(

/**
* As a Theme developer, use the 'all' parameter, to declare support for all
* hook types.
* Please make sure you then actually reference all the hooks in this file,
* Plugin developers depend on it!
*/
'all',

/**
* Themes can also choose to only support certain hook types.
* Please make sure you then actually reference all the hooks in this type
* family.
*
* When the 'all' parameter was set, specific hook types do not need to be
* added explicitly.
*/
'head',
'header',
'content',
Expand All @@ -38,19 +64,24 @@
'footer',

/**
* If/when WordPress Core implements similar methodology, themes and plugins will be
* able to check whether the version of THA supplied by the theme supports Core
* hooks.
* If/when WordPress Core implements similar methodology, Themes and Plugins
* will be able to check whether the version of THA supplied by the theme
* supports Core hooks.
*/
// 'core'
) );

/**
* Determines, whether the specific hook type is actually supported.
*
* Usage:
* if ( current_theme_supports( 'tha_hooks', 'header' ) )
* add_action( 'tha_head_top', 'prefix_header_top' );
* Plugin developers should always check for the support of a <strong>specific</strong>
* hook type before hooking a callback function to a hook of this type.
*
* Example:
* <code>
* if ( current_theme_supports( 'tha_hooks', 'header' ) )
* add_action( 'tha_head_top', 'prefix_header_top' );
* </code>
*
* @param bool $bool true
* @param array $args The hook type being checked
Expand All @@ -59,7 +90,7 @@
* @return bool
*/
function tha_current_theme_supports( $bool, $args, $registered ) {
return in_array( $args[0], $registered[0] );
return in_array( $args[0], $registered[0] ) || in_array( 'all', $registered[0] );
}
add_filter( 'current_theme_supports-tha_hooks', 'tha_current_theme_supports', 10, 3 );

Expand Down

0 comments on commit d1bf478

Please sign in to comment.