Open yehiasalam opened 8 years ago
Thanks for this boilerplate.
I'm also having trouble with the loader class. I'm attempting to follow a tutorial on implementing the settings api in a plugin with OOP priniciples (https://tommcfarlin.com/defining-an-interface-for-the-wordpress-settings-api/) and they, and almost everyone else online it seems, want to load their hooks in the construct.
I have no problem with the loader. But, would you please explain to an OOP noob how to alter existing classes that happen to load hooks in their constructs, so that they may instead be used with this loader class?
Putting your actions in the construct is not best practice and Tom definitely would not be recommending it considering he has been digging into testing lately.
You can simply load you hooks into the loader like in the boiler plate...or don't. There is no requirement if you don't like it and find it easier to build without it.
@DevinVinson but why its not a best practice? putting it in the construct will make the class self contained, creating its own hooks
Since every actions and filters are registered soon in the main plugin class (it's executed in the constructor), I think more clarifications about the loader class and maybe some more code development for providing ways to alter/remove hooks would be welcome! +1
Hi,
This boilerplate is great and giving me a head start , and I want to ask something regarding the best practices. I'm creating a separate class for each admin page. so I have for example
class-myplugin-admin-jobs.php
in my admin folder.Now from what i see in the
class-myplugin.php
we are adding all the actions using theloader
, and I was wondering is it a best practice to add all the actions there, or in the construct function in my separateadmin
classes. The construct function makes more sense since the class will be responsible for injecting its own actions and classes.