Idea: Hook into a specific theme's existing hooks #11

Open
Cais opened this Issue Oct 5, 2012 · 4 comments

Comments

Projects
None yet
3 participants
@Cais

Cais commented Oct 5, 2012

Just a thought/idea to help make this idea more palatable to theme developers already using their own hook system / architecture. Using an example snippet:

/**
* Semantic <header> hooks
*
* $tha_supports[] = 'header';
*/
function tha_header_before() {
do_action( 'tha_header_before' );
}

I suggest adding to the tha-theme-hooks.php code a commented out line after each function to hook the THA supported hook into an existing theme's hook, for example:

/**
* Semantic <header> hooks
*
* $tha_supports[] = 'header';
*/
function tha_header_before() {
do_action( 'tha_header_before' );
}
/** Change 'existing_theme_hook_before_header' to something more appropriate */
// add_action( 'existing_theme_hook_before_header', 'tha_header_before');

This works in practice but I will leave it to you to decide if you want to make it obvious to others. Of course, this would also be unique for each theme that implements this idea.

I plan to add something like this as an enhancement plugin for my latest theme.

@zamoose

This comment has been minimized.

Show comment
Hide comment
@zamoose

zamoose Oct 5, 2012

Owner

I'd actually spoken to Nathan Rice about this in re: Genesis eventually supporting such a thing. A shim plugin such as the one you suggest is actually a good idea.

Hmm. How best to formalize it, though?

Owner

zamoose commented Oct 5, 2012

I'd actually spoken to Nathan Rice about this in re: Genesis eventually supporting such a thing. A shim plugin such as the one you suggest is actually a good idea.

Hmm. How best to formalize it, though?

@Cais

This comment has been minimized.

Show comment
Hide comment
@Cais

Cais Feb 6, 2013

I finally got to the point where I could properly add this into Opus Primus (soon to be released WordPress theme). Here is a link to the gist "bridge" https://gist.github.com/Cais/4719335 ... if nothing else it can serve as a starting point for formalization discussions?

Cais commented Feb 6, 2013

I finally got to the point where I could properly add this into Opus Primus (soon to be released WordPress theme). Here is a link to the gist "bridge" https://gist.github.com/Cais/4719335 ... if nothing else it can serve as a starting point for formalization discussions?

@chipbennett

This comment has been minimized.

Show comment
Hide comment
@chipbennett

chipbennett Feb 21, 2013

Contributor

The way I implemented this in Oenology, since I already had template-tag functions in the template, that fired the custom Theme template hooks (such as oenology_hook_content_after()), was simply to add the tha_hook_name() inside the appropriate template-tag function:

/**
 * Define custom action hooks
 */

/**
 * Action hook after div#content
 * 
 * This action hook fires after the div#content container. It
 * can be used to add content after div#content is output.
 * 
 * Template file: footer.php
 * 
 * @uses do_action()
 * 
 * @since Oenology 2.0
 */
function oenology_hook_content_after() {
    do_action( 'oenology_hook_content_after' );
    tha_content_after();
}
Contributor

chipbennett commented Feb 21, 2013

The way I implemented this in Oenology, since I already had template-tag functions in the template, that fired the custom Theme template hooks (such as oenology_hook_content_after()), was simply to add the tha_hook_name() inside the appropriate template-tag function:

/**
 * Define custom action hooks
 */

/**
 * Action hook after div#content
 * 
 * This action hook fires after the div#content container. It
 * can be used to add content after div#content is output.
 * 
 * Template file: footer.php
 * 
 * @uses do_action()
 * 
 * @since Oenology 2.0
 */
function oenology_hook_content_after() {
    do_action( 'oenology_hook_content_after' );
    tha_content_after();
}
@Cais

This comment has been minimized.

Show comment
Hide comment
@Cais

Cais Feb 21, 2013

I just finished refactoring all of my action hooks to the same "format" of < namespace >-< function >-< location > where < function > can be whatever and location is either top/bottom or before/after. Which mean my "bridge" now is simply using add_action( < my_namespace >_*, tha_* );

If WordPress core adopts these, I will simple write an appropriate "bridge" for those hook names in the same manner I added the THA hooks. The only thing to be considered with either of these methods is without a priority being set specifically they will fire in their order of definition.

I intend to go back and look at the add_action() priority values after I write a "real" plugin to take advantage of the THA system. Then I will be able to work with some reasonable expectations and output.

Cais commented Feb 21, 2013

I just finished refactoring all of my action hooks to the same "format" of < namespace >-< function >-< location > where < function > can be whatever and location is either top/bottom or before/after. Which mean my "bridge" now is simply using add_action( < my_namespace >_*, tha_* );

If WordPress core adopts these, I will simple write an appropriate "bridge" for those hook names in the same manner I added the THA hooks. The only thing to be considered with either of these methods is without a priority being set specifically they will fire in their order of definition.

I intend to go back and look at the add_action() priority values after I write a "real" plugin to take advantage of the THA system. Then I will be able to work with some reasonable expectations and output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment