-
Notifications
You must be signed in to change notification settings - Fork 44
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
Making functions out of do_action? #17
Comments
I use a Note: I have included the THA project files to provide attribution for their work (as well as a note in the theme 'readme.txt.' file). |
The advantage of using template-tag reference functions to the |
Thanks @chipbennett. Can you give an example? Trying to wrap my mind around it. |
@mindctrl sure, here's the example I used in Issue #11: In the template, I call
When I incorporated THA, I simply dropped in the corresponding THA function:
Note that if/when core adds template hooks, this approach makes it easy to add the core hook, as well:
|
@chipbennett thanks for the example. It helps me think about it. I'm relatively new to all this. It seems like the main benefit to using functions this way (with this not in core) is for backwards compatibility with existing themes. But can't that be worked around by attaching do_action to the existing theme's function/hook? In your example: function oenology_hook_content_after() {
do_action( 'oenology_hook_content_after' );
tha_content_after();
wp_content_after();
} could be: function oenology_hook_content_after() {
do_action( 'oenology_hook_content_after' );
do_action( 'tha_content_after' );
do_action( 'wp_content_after' );
} and that would cover the backwards compatibility in existing themes? If the theme hook "do_action function" (ex: wp_content_after ) isn't pluggable in core, you can't add to the function itself like in your example, but you can attach additional actions to the hook. I think? I'm still trying to wrap my head around it, and still don't see a benefit to wrapping the hook standards inside functions other than it possibly helping a little with adoption - and that's likely negligible unless theme devs are reading core. Otherwise they get the info from the codex and direction from usage in bundled themes. Am I missing something? I probably am. |
Are there benefits to using functions that call do_action versus just agreeing on a set of hook names and using do_action( 'hook_name' )?
With the functions, if something happens and the hook function file isn't included, the site bombs with a white screen php error. With just do_action, that doesn't happen.
The text was updated successfully, but these errors were encountered: