| @@ -27,19 +27,26 @@ | ||
| 27 | 27 | /** |
| 28 | 28 | * Register client services |
| 29 | 29 | */ |
| 30 | 30 | public function register() { |
| 31 | - // Register the `customer` role on init:1. | |
| 31 | + // Register the `customer` role. | |
| 32 | 32 | // |
| 33 | - // This was previously hooked to `after_setup_theme` from inside | |
| 34 | - // a callback that itself only runs on init:10 — so by the time | |
| 35 | - // add_action() was called, `after_setup_theme` had already fired | |
| 36 | - // and the registration silently never ran. On sites without | |
| 37 | - // WooCommerce (which also registers `customer`), the role stayed | |
| 38 | - // unregistered, WP_User::roles filtered it out as unknown, and | |
| 39 | - // the Clients page fell back to a "Client" label while WC sites | |
| 40 | - // showed "Customer" for the same data. | |
| 41 | - add_action('init', [$this, 'registerClientRole'], 1); | |
| 33 | + // This provider is constructed from easy_invoice_init(), which | |
| 34 | + // itself runs on init:10 — so hooking `after_setup_theme` (the | |
| 35 | + // original code) or `init` at priority 1 (the first fix) both | |
| 36 | + // registered a callback for a point WordPress had already passed, | |
| 37 | + // and the role was never created. On sites without WooCommerce | |
| 38 | + // (which also registers `customer`) the role stayed unregistered: | |
| 39 | + // WP_User::roles filtered it out as unknown, the Clients page fell | |
| 40 | + // back to a "Client" label, and Pro's Client Portal — which | |
| 41 | + // recognises a client by `in_array('customer', $user->roles)` — | |
| 42 | + // could not see the client at all. Register it now when `init` | |
| 43 | + // is already in progress, otherwise on init:1 as before. | |
| 44 | + if (did_action('init')) { | |
| 45 | + $this->registerClientRole(); | |
| 46 | + } else { | |
| 47 | + add_action('init', [$this, 'registerClientRole'], 1); | |
| 48 | + } | |
| 42 | 49 | |
| 43 | 50 | // Register client repository |
| 44 | 51 | $this->registerClientRepository(); |
| 45 | 52 | } |