Learn icon indicating copy to clipboard operation
Learn copied to clipboard

Hook best practices

Open jonathanbossenger opened this issue 1 year ago • 8 comments

jonathanbossenger avatar Aug 03 '24 14:08 jonathanbossenger

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.

jonathanbossenger avatar Aug 03 '24 14:08 jonathanbossenger

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. 🤔

MichelleBlanchette avatar Sep 12 '24 11:09 MichelleBlanchette

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.

jonathanbossenger avatar Sep 12 '24 14:09 jonathanbossenger

@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.

jonathanbossenger avatar Oct 01 '24 13:10 jonathanbossenger

@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 avatar Oct 01 '24 13:10 CrochetFeve0251

@CrochetFeve0251, next week is perfectly fine, as it gives me time to get things updated here.

Enjoy your company retreat! :smiley:

jonathanbossenger avatar Oct 01 '24 13:10 jonathanbossenger

Here is a link to the script: https://github.com/wptrainingteam/learn-wp-content/pull/13

CrochetFeve0251 avatar Oct 20 '24 21:10 CrochetFeve0251

Thanks, I have left my first review comments.

jonathanbossenger avatar Oct 22 '24 10:10 jonathanbossenger

Script: https://github.com/wptrainingteam/learn-wp-content/blob/main/plugin-developer-learning-pathway/02-Advanced-Hooks/04-good-practices.md

jonathanbossenger avatar Oct 31 '24 10:10 jonathanbossenger

Video for review: https://drive.google.com/file/d/1gA-bUge1AwXfIdqA9BmVIV7YohffsONw/view?usp=drive_link

jonathanbossenger avatar Nov 07 '24 19:11 jonathanbossenger

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 avatar Nov 09 '24 17:11 MichelleBlanchette

@MichelleBlanchette apologies, this should be public now.

jonathanbossenger avatar Nov 25 '24 09:11 jonathanbossenger

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!

MichelleBlanchette avatar Nov 27 '24 02:11 MichelleBlanchette

0:27 Mistake "... consider using a the name of..." in the slide

Thanks, I'll make sure to get this fixed before publishing.

jonathanbossenger avatar Dec 09 '24 13:12 jonathanbossenger

WordPress.tv: https://wordpress.tv/2024/12/23/developing-with-hooks/

jonathanbossenger avatar Dec 23 '24 14:12 jonathanbossenger

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

jonathanbossenger avatar Dec 23 '24 14:12 jonathanbossenger

https://youtu.be/5R-0Uqz-rR4

jonathanbossenger avatar Dec 26 '24 19:12 jonathanbossenger

https://learn.wordpress.org/lesson/developing-with-hooks/

jonathanbossenger avatar Dec 27 '24 06:12 jonathanbossenger

//publish

jonathanbossenger avatar Dec 27 '24 06:12 jonathanbossenger