RegisterSiteRoutes.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * WordPress init action that boots the SiteRouter for all site routes. |
| 5 | * Registers rewrite rules, query vars, and dispatch hooks for front-end routes. |
| 6 | * |
| 7 | * @package Framework |
| 8 | * @subpackage Wordpress\Hooks\Actions |
| 9 | * @since 1.0.0 |
| 10 | */ |
| 11 | namespace Kirki\Framework\Wordpress\Hooks\Actions; |
| 12 | |
| 13 | \defined('ABSPATH') || exit; |
| 14 | use Kirki\Framework\Route; |
| 15 | use Kirki\Framework\Routing\SiteRouter; |
| 16 | use Kirki\Framework\Wordpress\BaseHook; |
| 17 | use Kirki\Framework\Wordpress\Constants\HookNames; |
| 18 | use Kirki\Framework\Wordpress\Constants\HookTypes; |
| 19 | class RegisterSiteRoutes extends BaseHook |
| 20 | { |
| 21 | /** |
| 22 | * Get the name. |
| 23 | * |
| 24 | * @return mixed |
| 25 | * |
| 26 | * @since 1.0.0 |
| 27 | */ |
| 28 | public function get_name() |
| 29 | { |
| 30 | return HookNames::INIT; |
| 31 | } |
| 32 | /** |
| 33 | * Get the type. |
| 34 | * |
| 35 | * @return mixed |
| 36 | * |
| 37 | * @since 1.0.0 |
| 38 | */ |
| 39 | public function get_type() |
| 40 | { |
| 41 | return HookTypes::ACTION; |
| 42 | } |
| 43 | /** |
| 44 | * Handle. |
| 45 | * |
| 46 | * @param mixed $args The positional arguments. |
| 47 | * |
| 48 | * @return void |
| 49 | * |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | public function handle(...$args) |
| 53 | { |
| 54 | $site_routes = Route::get_site_routes(); |
| 55 | if (empty($site_routes)) { |
| 56 | return; |
| 57 | } |
| 58 | $router = new SiteRouter(Route::get_site_namespace(), Route::get_routing_method()); |
| 59 | $router->boot($site_routes); |
| 60 | Route::set_site_router($router); |
| 61 | } |
| 62 | } |
| 63 |