Hook best practices
From a disucssion on #2700, this is a new lesson with some additional notes on working with hooks. A better title also needs to be decided.
- Filter hook return types
- Determining the Current Hook
- Checking How Many Times a Hook Has Run.
Ideas that come to mind for this lesson: • Always use a named callback rather than anonymous functions (aka lambdas) to help with debugging (ie stack traces) and the ability to remove the hook easily. • When creating custom hooks, try to keep the passed parameters and their order the same in all areas the hook (same name) is used. • How to properly document custom hooks per WordPress's documentation standards. • Suggest naming conventions for custom hooks..? I'm not sure there are any and this might just be up to personal preference. • The recommended hooks for common needs, such as enqueueing scripts and styles..? This might be in the weeds as it varies heavily per project. Also, other lessons likely dive into these concepts more thoroughly.
@jonathanbossenger Did you have ideas in mind for this lesson? I'm wondering if there's enough to say to justify this lesson, but maybe it's simply going to be a shorter lesson... I could just be missing the idea here. 🤔
Shorter lessons are also perfectly fine :grin: We typically aim for lessons that can be watched in around 5-10 minutes. Sometimes they do go longer if we need to a deeper dive into a topic.
@CrochetFeve0251 I wanted to check if you are still interested in drafting a script for this lesson?
If you are, I will make sure to get the description and learning outcomes updated tomorrow.
I'll also be reviewing your script for #2702 this week.
@CrochetFeve0251 I wanted to check if you are still interested in drafting a script for this lesson. I'll be reviewing your script for #2702 this week.
@jonathanbossenger I am at the retreat from my company so it is hard to contribute before I had a WC so I didn't advance much last weeks.
I'm gonna make that script next week.
@CrochetFeve0251, next week is perfectly fine, as it gives me time to get things updated here.
Enjoy your company retreat! :smiley:
Here is a link to the script: https://github.com/wptrainingteam/learn-wp-content/pull/13
Thanks, I have left my first review comments.
Script: https://github.com/wptrainingteam/learn-wp-content/blob/main/plugin-developer-learning-pathway/02-Advanced-Hooks/04-good-practices.md
Video for review: https://drive.google.com/file/d/1gA-bUge1AwXfIdqA9BmVIV7YohffsONw/view?usp=drive_link
Video for review: https://drive.google.com/file/d/1gA-bUge1AwXfIdqA9BmVIV7YohffsONw/view?usp=drive_link
@jonathanbossenger I'm unable to access this one for review as well.
@MichelleBlanchette apologies, this should be public now.
Tutorial/Lessons Review Checklist
Please tick all items you've confirmed:
- [x] Learning outcomes/objectives are clear.
- [x] Technical concepts introduced in the content are accurate.
- [x] The speed of demonstrations are easy to follow.
- [x] The narration audio matches what is shown visually.
- [ ] Spelling and grammar are correct.
- 0:27 Mistake "... consider using a the name of..." in the slide
- [x] Sound quality is consistent throughout the video.
- [x] Brand Usage Guidelines and Promotional Guidelines are being followed.
- [x] Media assets are all in the public domain (CC0).
Really great insights. 😃 I was intrigued by the mentioning of current_filter() and current_action() functions. I know what you mean about a function being used for multiple hooks—good stuff!
0:27 Mistake "... consider using a the name of..." in the slide
Thanks, I'll make sure to get this fixed before publishing.
WordPress.tv: https://wordpress.tv/2024/12/23/developing-with-hooks/
00:00 Introduction 00:16 Naming hooks 01:25 Handling filter variable types 02:19 Validating return values 04:01 Getting information about hooks 04:51 Further reading
https://youtu.be/5R-0Uqz-rR4
https://learn.wordpress.org/lesson/developing-with-hooks/
//publish