| @@ -9,59 +9,45 @@ | ||
| 9 | 9 | |
| 10 | 10 | // register services |
| 11 | 11 | $provider = new BoxzillaServiceProvider(); |
| 12 | 12 | $provider->register( $boxzilla ); |
| 13 | +$provider = new Licensing\LicenseServiceProvider(); | |
| 14 | +$provider->register( $boxzilla ); | |
| 13 | 15 | |
| 14 | -// load default filters | |
| 15 | -require __DIR__ . '/src/default-filters.php'; | |
| 16 | 16 | |
| 17 | -add_action( 'init', function() use( $boxzilla ){ | |
| 18 | - // Register custom post type | |
| 19 | - $args = array( | |
| 20 | - 'public' => false, | |
| 21 | - 'labels' => array( | |
| 22 | - 'name' => __( 'Boxzilla', 'boxzilla' ), | |
| 23 | - 'singular_name' => __( 'Box', 'boxzilla' ), | |
| 24 | - 'add_new' => __( 'Add New', 'boxzilla' ), | |
| 25 | - 'add_new_item' => __( 'Add New Box', 'boxzilla' ), | |
| 26 | - 'edit_item' => __( 'Edit Box', 'boxzilla' ), | |
| 27 | - 'new_item' => __( 'New Box', 'boxzilla' ), | |
| 28 | - 'all_items' => __( 'All Boxes', 'boxzilla' ), | |
| 29 | - 'view_item' => __( 'View Box', 'boxzilla' ), | |
| 30 | - 'search_items' => __( 'Search Boxes', 'boxzilla' ), | |
| 31 | - 'not_found' => __( 'No Boxes found', 'boxzilla' ), | |
| 32 | - 'not_found_in_trash' => __( 'No Boxes found in Trash', 'boxzilla' ), | |
| 33 | - 'parent_item_colon' => '', | |
| 34 | - 'menu_name' => __( 'Boxzilla', 'boxzilla' ) | |
| 35 | - ), | |
| 36 | - 'show_ui' => true, | |
| 37 | - 'menu_position' => '108.1337133', | |
| 38 | - 'menu_icon' => $boxzilla->plugin->url( '/assets/img/menu-icon.png' ), | |
| 39 | - 'query_var' => false | |
| 40 | - ); | |
| 41 | 17 | |
| 42 | - register_post_type( 'boxzilla-box', $args ); | |
| 43 | -}); | |
| 18 | +// Rest of bootstrapping runs at plugins_loaded:90 | |
| 19 | +add_action( 'plugins_loaded', function() use( $boxzilla ) { | |
| 44 | 20 | |
| 45 | -if( ! is_admin() ) { | |
| 21 | + // load default filters | |
| 22 | + require __DIR__ . '/src/default-filters.php'; | |
| 23 | + require __DIR__ . '/src/default-actions.php'; | |
| 46 | 24 | |
| 47 | - // PUBLIC | |
| 48 | - add_action( 'template_redirect', function() use( $boxzilla ) { | |
| 49 | - $boxzilla['box_loader']->init(); | |
| 25 | + $bootstrapper = $boxzilla->bootstrapper; | |
| 26 | + | |
| 27 | + $bootstrapper->admin(function() use( $boxzilla ){ | |
| 28 | + $boxzilla['admin']->init(); | |
| 50 | 29 | }); |
| 51 | 30 | |
| 52 | -} else { | |
| 31 | + $bootstrapper->ajax(function() use( $boxzilla ) { | |
| 32 | + $boxzilla['filter.autocomplete']->add_hooks(); | |
| 33 | + }); | |
| 53 | 34 | |
| 54 | - // ADMIN (and AJAX) | |
| 55 | - $provider = new Licensing\LicenseServiceProvider(); | |
| 56 | - $provider->register( $boxzilla ); | |
| 35 | + $bootstrapper->front(function() use( $boxzilla ) { | |
| 36 | + add_action( 'template_redirect', function() use( $boxzilla ) { | |
| 37 | + $boxzilla['box_loader']->init(); | |
| 38 | + }); | |
| 39 | + }); | |
| 57 | 40 | |
| 58 | - if( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { | |
| 59 | - add_action('init', function() use( $boxzilla ) { | |
| 60 | - $boxzilla['admin']->init(); | |
| 61 | - }); | |
| 62 | - } else { | |
| 63 | - $boxzilla['filter.autocomplete']->add_hooks(); | |
| 41 | + $bootstrapper->cron(function() use( $boxzilla ) { | |
| 42 | + $boxzilla['license_poller']->hook(); | |
| 43 | + }); | |
| 44 | + | |
| 45 | + if( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) { | |
| 46 | + if( count( $boxzilla->plugins ) > 0 ) { | |
| 47 | + $boxzilla['license_manager']->hook(); | |
| 48 | + $boxzilla['update_manager']->hook(); | |
| 49 | + } | |
| 64 | 50 | } |
| 65 | - | |
| 66 | -} | |
| 67 | 51 | |
| 52 | + $bootstrapper->run(); | |
| 53 | +}, 90 ); | |