Repository navigation
Expand file tree
/
Copy pathbootstrap.php
More file actions
152 lines (137 loc) · 5.48 KB
/
Copy pathbootstrap.php
File metadata and controls
152 lines (137 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* Onboarding module bootstrap.
*
* @package NewfoldLabs\WP\Module\Onboarding
*/
/*
* Eager-load Onboarding\Data\* before any autoloader can resolve them.
*
* wp-module-onboarding-data is still pulled in transitively by brand plugins
* (e.g. wp-plugin-bluehost) and ships classes under the same
* NewfoldLabs\WP\Module\Onboarding\Data\ namespace. Composer's PSR-4 routing
* picks the longest matching prefix, so onboarding-data's `Data\` prefix
* shadows our `Onboarding\` prefix for everything in this folder. Requiring
* our files here binds the class symbols first; PHP then skips autoload for
* them. Remove once brand plugins drop the onboarding-data dependency.
*/
foreach (
array(
'Brands',
'Plugins',
'Languages',
'Options',
'Config',
'Runtime',
'Events',
'BrandConfig',
) as $nfd_onboarding_data_class
) {
require_once __DIR__ . '/includes/Data/' . $nfd_onboarding_data_class . '.php';
}
unset( $nfd_onboarding_data_class );
use NewfoldLabs\WP\Module\Onboarding\Data\BrandConfig;
use NewfoldLabs\WP\Module\Onboarding\Data\Brands;
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\Onboarding\ModuleController;
use NewfoldLabs\WP\Module\Onboarding\Compatibility\Scan;
use NewfoldLabs\WP\Module\Onboarding\Compatibility\Safe_Mode;
use NewfoldLabs\WP\Module\Onboarding\Compatibility\Status;
use NewfoldLabs\WP\Module\Onboarding\TaskManagers\ImageSideloadTaskManager;
use NewfoldLabs\WP\Module\Onboarding\Services\MediaService;
use NewfoldLabs\WP\Module\Onboarding\Services\SiteGenImageService;
use NewfoldLabs\WP\Module\Onboarding\Application;
use function NewfoldLabs\WP\ModuleLoader\register;
/**
* Register Onboarding with Newfold Module Loader
*
* @return void
*/
function nfd_wp_module_onboarding_register() {
// wp-module-onboarding
register(
array(
'name' => 'onboarding',
'label' => __( 'Onboarding', 'wp-module-onboarding' ),
'callback' => function ( Container $container ) {
// Set Global Constants
if ( ! defined( 'NFD_ONBOARDING_VERSION' ) ) {
define( 'NFD_ONBOARDING_VERSION', '4.0.10' );
}
if ( ! defined( 'NFD_ONBOARDING_DIR' ) ) {
define( 'NFD_ONBOARDING_DIR', __DIR__ );
}
if ( ! defined( 'NFD_ONBOARDING_BUILD_DIR' ) && defined( 'NFD_ONBOARDING_VERSION' ) ) {
define( 'NFD_ONBOARDING_BUILD_DIR', __DIR__ . '/build/' . NFD_ONBOARDING_VERSION );
}
if ( ! defined( 'NFD_MODULE_DATA_EVENTS_API' ) ) {
define( 'NFD_MODULE_DATA_EVENTS_API', '/newfold-data/v1/events' );
}
if ( ! defined( 'NFD_ONBOARDING_BUILD_URL' ) && defined( 'NFD_ONBOARDING_VERSION' ) ) {
define( 'NFD_ONBOARDING_BUILD_URL', $container->plugin()->url . 'vendor/newfold-labs/wp-module-onboarding/build/' . NFD_ONBOARDING_VERSION );
}
if ( ! defined( 'NFD_ONBOARDING_PLUGIN_URL' ) ) {
define( 'NFD_ONBOARDING_PLUGIN_URL', $container->plugin()->url . 'vendor/newfold-labs/wp-module-onboarding' );
}
if ( ! defined( 'NFD_ONBOARDING_PLUGIN_DIRNAME' ) ) {
define( 'NFD_ONBOARDING_PLUGIN_DIRNAME', dirname( $container->plugin()->basename ) );
}
Brands::set_current_brand( $container );
/**
* Editor-chat and other modules read brand portal data from the container.
*
* @param array<string, string> $brand_payload Keys: id, name, accountUrl, emailUrl, billingUrl, adminUrl.
* @param Container $container Host plugin container.
*/
$editor_chat_brand = apply_filters(
'newfold/container/editor_chat_brand',
BrandConfig::get_brand_for_editor_chat_js(),
$container
);
$container->set( 'editor_chat_brand', $editor_chat_brand );
// Backward compatibility for integrations that read the raw container brand.
if ( ! defined( 'NFD_ONBOARDING_BLUEHOST_BRAND' ) ) {
define( 'NFD_ONBOARDING_BLUEHOST_BRAND', $container->plugin()->brand );
}
if ( 'compatible' !== Status::get() ) {
$compatibility_scan = new Scan();
Status::set( $compatibility_scan );
if ( 'compatible' !== $compatibility_scan->result ) {
return new Safe_Mode( $compatibility_scan );
}
}
// Instantiate Onboarding Module Application
new Application( $container );
},
'isActive' => true,
'isHidden' => true,
)
);
}
/**
* Tap WordPress Hooks to Instantiate Module Loader
*/
if ( is_callable( 'add_action' ) ) {
add_action(
'plugins_loaded',
'nfd_wp_module_onboarding_register'
);
// Handle Module Disable if Non-Ecommerce
ModuleController::init();
// Clear site capabilities transient after onboarding is completed so CTBs are accessible right away
add_action(
'newfold/onboarding/completed',
function () {
delete_transient( 'nfd_site_capabilities' );
}
);
// Queue content image sideloading for onboarding-generated pages when onboarding completes.
add_action( 'newfold/onboarding/completed', array( SiteGenImageService::class, 'schedule_after_onboarding' ) );
// Add action to process image sideload queue for onboarding-generated pages
add_action( SiteGenImageService::CRON_HOOK, array( ImageSideloadTaskManager::class, 'process_queue' ) );
// Process a batch of pending images on each cron run for onboarding-generated CPTs.
add_action( MediaService::CRON_HOOK, array( MediaService::class, 'sideload_pending_images' ) );
// Daily re-scan of onboarding pages to sideload images replaced after onboarding.
add_action( SiteGenImageService::DAILY_CRON_HOOK, array( SiteGenImageService::class, 'daily_sync' ) );
add_action( 'init', array( SiteGenImageService::class, 'schedule_daily_images_importer' ) );
}