gocodebox / lifterlms

LifterLMS, a WordPress LMS Solution: Easily create, sell, and protect engaging online courses.
https://lifterlms.com
GNU General Public License v3.0
174 stars 134 forks source link

Initialize Dependencies #2131

Open pondermatic opened 2 years ago

pondermatic commented 2 years ago

Is your feature request related to a problem? Please describe.

When LifterLMS is loaded by WordPress, it is important for some LifterLMS classes to be loaded, instantiated, and hooked into the system in a certain order. See #2070.

Describe the solution you'd like.

  1. Create a class, named LLMS_Classes, extended from the WP_Dependencies class and using LLMS_Trait_Singleton, that helps to initialize LifterLMS objects in the correct order.

  2. Add a LifterLMS::classes() method that returns a singleton instance of LLMS_Classes.

  3. Add a static method to every class loaded by LifterLMS::bootstrap_X() methods, that returns an array of classes it is dependent on.

  4. Add a LifterLMS::bootstrap_always() method that registers classes with LLMS_Classes::add() that are currently listed in LLMS_Loader::includes() .

  5. Add a LifterLMS::bootstrap_admin() method that registers classes with LLMS_Classes::add() that are currently listed in LLMS_Loader::includes_admin().

  6. Add a LifterLMS::bootstrap_frontend() method that registers classes with LLMS_Classes::add() that are currently listed in LLMS_Loader::includes_frontend().

  7. Add a LifterLMS::bootstrap() method that calls LifterLMS::bootstrap_always() and either LifterLMS::bootstrap_admin() or LifterLMS::bootstrap_frontend().

  8. Add a call to LifterLMS::bootstrap() in LifterLMS::__construct().

  9. The LLMS_Classes::__constructor() method should register LLMS_Classes::do_items() as a callback on the before_lifterlms_init or maybe lifterlms_init action hook.

  10. Add a LLMS_Classes::do_item() method (not to be confused with do_items()) that either includes the class file which also instantiates the class (LifterLMS pattern) or instantiates the class using the autoloader (PSR-1 standard).

Describe alternatives you've considered.

Quitting programming and opening up a bait shop in Minnesota, but that would just exchange software bugs for actual bugs.

Oh, you meant loading classes in an order based on dependencies?

Changing the hook used by classes when they hook into the system. Hook options, init, admin_init, before_lifterlms_init, lifterlms_init, lifterlms_loaded.

eri-trabiccolo commented 2 years ago

I don't exactly know how much we need this right now, and probably doesn't matter, but I really like the idea <3