WordPress / Learn

WordPress.org Learn - The canonical source for the code and content behind https://learn.WordPress.org
262 stars 89 forks source link

Hook best practices #2821

Open jonathanbossenger opened 1 month ago

jonathanbossenger commented 1 month ago

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.

MichelleBlanchette commented 21 hours ago

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

jonathanbossenger commented 18 hours ago

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.