Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make THA easier to use for Themes supporting all the hooks. #6

Merged
merged 1 commit into from

2 participants

Konstantin Obenland Doug Stewart
Konstantin Obenland

Adding support for the 'all' parameter, including some documentation.
Please feel free to add/modify/correct, since I'm not a native ;)

Doug Stewart zamoose merged commit 1a48386 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 9 deletions.
  1. +40 −9 tha-theme-hooks.php
49 tha-theme-hooks.php
View
@@ -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',
@@ -38,9 +64,9 @@
'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'
) );
@@ -48,9 +74,14 @@
/**
* 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
@@ -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 );
Something went wrong with that request. Please try again.