Usage of register() vs boot() in Radicle/Acorn service providers

I’m using Radicle 2.2.0 and I noticed that all the example service providers do all of their work in their register() method.

In my own service provider I had to move some of my code to the boot() method to get it to work, and this prompted a quick search on the difference between the two.

According to the documentation:

As mentioned previously, within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.

In this context, shouldn’t WP hooks like add_action() and add_filter() be performed in the boot phase, since they are not registering classes into Laravel’s service container? Was this done on purpose to work around some specific quirk of Acorn / WP? If so, what is the rule on which phase to use when registering WP hooks?

1 Like

Hey Tobia, great catch.

Opened a PR to move the side effects from register() to boot() across all four service providers: https://github.com/roots/radicle/pull/298

Thanks for raising this!

1 Like