Skip to content
This repository

Complete theme support implementation #3

Merged
merged 2 commits into from about 2 years ago

2 participants

Konstantin Obenland Doug Stewart
Konstantin Obenland

With the current setup, THA works like Post Formats, where every supported format has to be explicitly registered. Reason: Even if only one hook type is registered with add_theme_support( 'tha_hooks', array( 'head' ) ), current_theme_supports( 'tha_hooks' ) will return true.

This patch reflects that, also moves the core flag to the registration array and fixes current_theme_supports() return value, when a second parameter is specified.

Doug Stewart
Owner

I'm liking where you're headed with this one. I need to sit down and dedicate a bit of time to mulling it over.

Doug Stewart
Owner

Hmm. Does this still work if you specify add_theme_support( 'tha_hooks' ) and current_theme_supports( 'tha_hooks' )? I don't want to have to pass an array in every time -- I'd like the above-listed case to be all-encompassing.

Konstantin Obenland

Only if you do not want to separate support for certain hook types.

With the current core implementation of the API, custom Theme features with arguments have to work like post formats.

Doug Stewart
Owner

Well crap.

Hmm, what about two add_theme_support()s? add_theme_support( 'tha_hooks-all') vs. add_theme_support( 'tha_hooks', $array )? Any advantage in that tack?

Konstantin Obenland

What about adding an 'all' parameter like so: add_theme_support( 'tha_hooks', array( 'all' ) );

This could work until there is a core patch, introducing more filters...

Doug Stewart
Owner

I like that approach. I'll merge this pull request -- mind putting one in that adds "all" compat?

Doug Stewart zamoose merged commit c76a2b4 into from
Doug Stewart zamoose closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jul 06, 2012
Konstantin Obenland obenland Complete Theme Support implementation 2693486
Konstantin Obenland obenland Fix typos. f73d6bf
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 40 additions and 18 deletions. Show diff stats Hide diff stats

  1. +40 18 tha-theme-hooks.php
58 tha-theme-hooks.php
@@ -18,28 +18,50 @@
18 18 * GNU General Public License for more details.
19 19 */
20 20
  21 +/**
  22 + * Define the version of THA support, in case that becomes useful down the road.
  23 + */
  24 +define( 'THA_HOOKS_VERSION', '1.0-draft' );
  25 +
21 26 /**
22   - * Themes and plugins can check for tha_hooks using current_theme_supports( 'tha_hooks' ) to determine
23   - * whether a theme declares itself to support THA hooks.
24   - *
25   - * We can further break down support by semantic type using an array as the second parameter.
26   - * E.g., add_theme_support( 'tha_hooks', $tha_supports ). Check below for nomenclature.
27   - *
28   - * No second parameter == supports ALL THA hooks.
  27 + * Themes and Plugins can check for tha_hooks using current_theme_supports( 'tha_hooks', $hook ) to determine
  28 + * whether a theme declares itself to support this specific hook type.
29 29 */
30   -add_theme_support( 'tha_hooks' );
31   -/**
32   - * Define the version of THA support, in case that becomes useful down the road.
33   - */
34   -define( 'THA_HOOKS_VERSION', '1.0-draft')
  30 +add_theme_support( 'tha_hooks', array(
  31 + 'head',
  32 + 'header',
  33 + 'content',
  34 + 'entry',
  35 + 'comments',
  36 + 'sidebars',
  37 + 'sidebar',
  38 + 'footer',
  39 +
  40 + /**
  41 + * If/when WordPress Core implements similar methodology, themes and plugins will be
  42 + * able to check whether the version of THA supplied by the theme supports Core
  43 + * hooks.
  44 + */
  45 +// 'core'
  46 +) );
  47 +
35 48 /**
36   - * If/when WordPress Core implements similar methodology, themes and plugins will be
37   - * able to check whether the version of THA supplied by the theme supports Core
38   - * hooks.
39   - *
40   - * $tha_supports[] = 'core';
  49 + * Determines, whether the specific hook type is actually supported.
  50 + *
  51 + * Usage:
  52 + * if ( current_theme_supports( 'tha_hooks', 'header' ) )
  53 + * add_action( 'tha_head_top', 'prefix_header_top' );
  54 + *
  55 + * @param bool $bool true
  56 + * @param array $args The hook type being checked
  57 + * @param array $registered All registered hook types
  58 + *
  59 + * @return bool
41 60 */
42   -define( 'THA_CORE_SUPPORT', false );
  61 +function tha_current_theme_supports( $bool, $args, $registered ) {
  62 + return in_array( $args[0], $registered[0] );
  63 +}
  64 +add_filter( 'current_theme_supports-tha_hooks', 'tha_current_theme_supports', 10, 3 );
43 65
44 66 /**
45 67 * HTML <head> hooks

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.