Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

Cais opened this issue Oct 5, 2012 · 4 comments

Comments

@Cais
Copy link

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
Copy link
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
Copy link
Author

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
Copy link
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();
}

@Cais
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants