You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @CrochetFeve0251, apologies if this wasn't clear. The objective of this lesson would be how to determine which hook or filter to use, in order to achieve a specific goal.
So, for example, if I want to enqueue admin-only scripts, which hook do I use? If I want to process a form submission, which hook should I use?
The general process would be:
determine if I need an action or filter hook
then review the relevant reference (action or filter) to decide which hook should be used.
The beginner developer lessons on Hooks, Actions and Filters does already cover the basic purpose of the two, but you certainly can expand on that based on what you've shared here already.
Then after that, you can include the process of how to decide which one to use, when developing plugins.
I see this lesson also had the wrong name for some reason, so I've updated it. It also didn't have prerequisite lessons or objectives set, so I've added those as well.
So, for example, if I want to enqueue admin-only scripts, which hook do I use? If I want to process a form submission, which hook should I use?
The general process would be:
determine if I need an action or filter hook
then review the relevant reference (action or filter) to decide which hook should be used.
...
Then after that, you can include the process of how to decide which one to use, when developing plugins.
When I think about which hook is best at an advanced level, I also consider (1) what data is made available in the hook's parameters and (2) the execution order of the hook. (eg. filtering a post's data before it is inserted into the database rather than acting on it after creation to then update it is generally more efficient)
These are the two main reasons I often cannot use a particular hook: it either doesn't provide crucial data needed for my custom functionality or it executes too early or late in the execution flow.
Additionally, a nifty trick is you can certainly use a filter hook as an action hook if it meets the necessary criteria. You simply perform your logic and then pass back the filtered value with no modifications to it.
Maybe these are also good concepts to consider for this lession.
I really enjoyed this lesson. The description and purpose of each mentioned hook was spot on and clearly communicated. I was particularly impressed by the explanation of the plugins_loaded hook and your tips for working with third-party plugins' hooks. 😁 Great work!
Activity
github-actions commentedon Jul 24, 2024
Lesson Development Checklist
[-]Determining the correct hook[/-][+]Hook best practices[/+]CrochetFeve0251 commentedon Aug 21, 2024
@jonathanbossenger from what I got from this issue, this section is here to teach the learner when to use a filter or an action?
CrochetFeve0251 commentedon Aug 21, 2024
Understand the purpose of an action vs a filter: (Maybe we can talk a bit about the CQRS approach)
When to use an action:
When to use filter:
If you see other scenarios feel free to add them
[-]Hook best practices[/-][+]Determining the correct hook[/+]jonathanbossenger commentedon Aug 22, 2024
Hi @CrochetFeve0251, apologies if this wasn't clear. The objective of this lesson would be how to determine which hook or filter to use, in order to achieve a specific goal.
So, for example, if I want to enqueue admin-only scripts, which hook do I use? If I want to process a form submission, which hook should I use?
The general process would be:
The beginner developer lessons on Hooks, Actions and Filters does already cover the basic purpose of the two, but you certainly can expand on that based on what you've shared here already.
Then after that, you can include the process of how to decide which one to use, when developing plugins.
jonathanbossenger commentedon Aug 22, 2024
I see this lesson also had the wrong name for some reason, so I've updated it. It also didn't have prerequisite lessons or objectives set, so I've added those as well.
jonathanbossenger commentedon Sep 9, 2024
@CrochetFeve0251 I'm checking in to see if you're still happy to continue with scripting the next lesson in this module?
CrochetFeve0251 commentedon Sep 9, 2024
@jonathanbossenger I started to work on it but I didn't push yet the script
jonathanbossenger commentedon Sep 9, 2024
Thank you, no pressure from my side, just wanted to make sure the process is still enjoyable. 🙂
MichelleBlanchette commentedon Sep 11, 2024
When I think about which hook is best at an advanced level, I also consider (1) what data is made available in the hook's parameters and (2) the execution order of the hook. (eg. filtering a post's data before it is inserted into the database rather than acting on it after creation to then update it is generally more efficient)
These are the two main reasons I often cannot use a particular hook: it either doesn't provide crucial data needed for my custom functionality or it executes too early or late in the execution flow.
Additionally, a nifty trick is you can certainly use a filter hook as an action hook if it meets the necessary criteria. You simply perform your logic and then pass back the filtered value with no modifications to it.
Maybe these are also good concepts to consider for this lession.
5 remaining items
jonathanbossenger commentedon Oct 31, 2024
Script: https://github.com/wptrainingteam/learn-wp-content/blob/main/plugin-developer-learning-pathway/02-Advanced-Hooks/03-correct-the-hook.md
jonathanbossenger commentedon Nov 7, 2024
Video for review: https://drive.google.com/file/d/1OtO1GN945fK2MwUwE1MtbvA6Ocn34Foq/view?usp=drive_link
MichelleBlanchette commentedon Nov 9, 2024
@jonathanbossenger I'm unable to access the video for review.
jonathanbossenger commentedon Nov 25, 2024
@MichelleBlanchette apologies, this should be public now.
MichelleBlanchette commentedon Nov 27, 2024
Tutorial/Lessons Review Checklist
Please tick all items you've confirmed:
I really enjoyed this lesson. The description and purpose of each mentioned hook was spot on and clearly communicated. I was particularly impressed by the explanation of the
plugins_loadedhook and your tips for working with third-party plugins' hooks. 😁 Great work!jonathanbossenger commentedon Dec 23, 2024
WordPress.tv: https://wordpress.tv/2024/12/23/determining-the-correct-hook/
jonathanbossenger commentedon Dec 23, 2024
00:00 Introduction
00:58 Finding available hooks
01:59 Important hooks to remember
03:12 Using hooks outside of WordPress Core
jonathanbossenger commentedon Dec 26, 2024
https://youtu.be/Vy_k100F0Lw
jonathanbossenger commentedon Dec 27, 2024
https://learn.wordpress.org/lesson/determining-the-correct-hook/
jonathanbossenger commentedon Dec 27, 2024
//publish