Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Application
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
72
1<?php
2namespace NewfoldLabs\WP\Module\Onboarding;
3
4use NewfoldLabs\WP\Module\Onboarding\Compatibility\Status;
5use NewfoldLabs\WP\Module\Onboarding\RestApi\RestApi;
6use NewfoldLabs\WP\Module\Onboarding\Services\PluginService;
7use NewfoldLabs\WP\ModuleLoader\Container;
8use NewfoldLabs\WP\Module\Onboarding\Data\Options;
9use NewfoldLabs\WP\Module\Onboarding\Services\StatusService;
10use NewfoldLabs\WP\Module\Onboarding\Services\EventService;
11
12use function NewfoldLabs\WP\ModuleLoader\container;
13
14/**
15 * Primary instantiation of Onboarding Application.
16 */
17final class Application {
18
19    /**
20     * The Plugin container.
21     *
22     * @var Container
23     */
24    protected $container;
25
26    /**
27     * Arguments for Onboarding.
28     *
29     * @var array
30     */
31    protected $args;
32
33    /**
34     * Setup module container and register functionality using WordPress Action Hooks.
35     *
36     * @param Container $container - Newfold Labs Module Container
37     */
38    public function __construct( Container $container ) {
39        $this->container = $container;
40
41        $defaults = array(
42            'option_name'     => 'nfd_onboarding',
43            'admin_screen_id' => container()->plugin()->id,
44            'admin_app_url'   => \admin_url( 'admin.php?page=nfd-onboarding' ),
45        );
46
47        $this->args = \wp_parse_args(
48            $container->has( 'onboarding' ) ? $container['onboarding'] : array(),
49            $defaults
50        );
51
52        if ( is_readable( NFD_ONBOARDING_DIR . '/vendor/autoload.php' ) ) {
53            require_once NFD_ONBOARDING_DIR . '/vendor/autoload.php';
54        }
55
56        \do_action( 'nfd_module_onboarding_pre_init' );
57
58        // Reset the stored Compatibility Status every time WP Core is updated.
59        \add_action( '_core_updated_successfully', array( Status::class, 'reset' ) );
60
61        \add_filter( 'login_redirect', array( LoginRedirect::class, 'wplogin' ), 10, 3 );
62        \add_filter( 'newfold_sso_success_url', array( LoginRedirect::class, 'sso' ), 10 );
63        \add_filter(
64            Options::get_option_name( 'redirect' ) . '_disable',
65            array( LoginRedirect::class, 'remove_handle_redirect_action' )
66        );
67
68        if ( defined( '\\WP_CLI' ) && \WP_CLI ) {
69            new WP_CLI();
70        }
71
72        if ( Permissions::is_authorized_admin() || Permissions::rest_is_authorized_admin() ) {
73            new RestApi();
74            new WP_Admin();
75            new ExternalRedirectInterceptor();
76        }
77
78        if ( Permissions::is_authorized_admin() ) {
79            StatusService::track();
80            // Initialize event tracking for database option changes
81            EventService::init();
82        }
83
84        \do_action( 'nfd_module_onboarding_post_init' );
85    }
86}