-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.php
More file actions
308 lines (273 loc) · 10.3 KB
/
Copy pathbootstrap.php
File metadata and controls
308 lines (273 loc) · 10.3 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
/**
* Plugin bootstrap file
*
* @package WPPluginWeb
*/
namespace Web;
use WP_Forge\WPUpdateHandler\PluginUpdater;
use WP_Forge\UpgradeHandler\UpgradeHandler;
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\ModuleLoader\Plugin;
use NewfoldLabs\WP\Module\Features\Features;
use function NewfoldLabs\WP\ModuleLoader\container as setContainer;
// Composer autoloader
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
} else {
if ( 'local' === wp_get_environment_type() ) {
wp_die( esc_html( __( 'Please install the Network Solutions Plugin dependencies.', 'wp-plugin-web' ) ) );
}
return;
}
/*
* Initialize coming soon module via container
*/
$web_module_container = new Container(
array(
'cache_types' => array( 'browser', 'file', 'skip404' ),
)
);
// Set plugin to container
$web_module_container->set(
'plugin',
$web_module_container->service(
function () {
return new Plugin(
array(
'id' => 'web',
'file' => WEB_PLUGIN_FILE,
'brand' => get_option( 'mm_brand', 'web' ),
'install_date' => get_option( 'web_plugin_install_date' ),
)
);
}
)
);
// Set coming soon values
add_filter(
'newfold/coming-soon/filter/args',
function ( $args, $default_args ) {
$args = wp_parse_args(
array(
'admin_app_url' => admin_url( 'admin.php?page=web#/home' ),
'template_h1' => __( 'Coming Soon!', 'wp-plugin-web' ),
'template_h2' => __( 'A New WordPress Site', 'wp-plugin-web' ),
'template_footer_t' => sprintf(
/* translators: %1$s is replaced with opening link tag taking you to web.com/wordpress, %2$s is replaced with closing link tag, %3$s is replaced with opening link tag taking you to login page, %4$s is replaced with closing link tag, %5$s is replaced with opening link tag taking you to my.web.com, %6$s is replaced with closing link tag */
esc_html__( 'A %1$sNetwork Solutions%2$s powered website. Is this your website? Log in to %3$sWordPress%4$s or %5$sNetwork Solutions%6$s.', 'wp-plugin-web' ) . ' ',
'<a href="' . esc_url( 'https://www.networksolutions.com/websites/wordpress' ) . '" target="_blank" rel="noopener noreferrer nofollow">',
'</a>',
'<a href="' . esc_url( wp_login_url() ) . '">',
'</a>',
'<a href="' . esc_url( 'https://www.networksolutions.com/my-account/account-center/login' ) . '" target="_blank" rel="noopener noreferrer nofollow">',
'</a>'
),
'template_page_title' => sprintf(
/* translators: %s: Blog name */
__( '%s — Coming Soon', 'wp-plugin-web' ),
esc_html( get_option( 'blogname' ) )
),
'admin_bar_text' => '<div style="background-color: #FEC101; color: #000; padding: 0 1rem;">' . __( 'Coming Soon Active', 'wp-plugin-web' ) . '</div>',
'admin_notice_text' => sprintf(
/* translators: %1$s is replaced with the opening link tag to preview the page, and %2$s is replaced with the closing link tag, %3$s is the opening link tag, %4$s is the closing link tag. */
__( 'Your site is currently displaying a %1$scoming soon page%2$s. Once you are ready, %3$slaunch your site%4$s.', 'wp-plugin-web' ),
'<a href="' . get_home_url() . '?preview=coming_soon" title="' . __( 'Preview the coming soon landing page', 'wp-plugin-web' ) . '">',
'</a>',
'<a href="' . esc_url( admin_url( 'admin.php?page=web#/home' ) ) . '">',
'</a>'
),
'template_styles' => esc_url( WEB_PLUGIN_URL . 'assets/styles/coming-soon.css' ),
),
$default_args
);
return $args;
},
10,
2
);
setContainer( $web_module_container );
// Load Data class for AI SiteGen brand mapping
require_once WEB_PLUGIN_DIR . '/inc/Data.php';
// Load AI Page Designer Configuration
require_once WEB_PLUGIN_DIR . '/inc/ai-page-designer-config.php';
/**
* Sub-brands like 'web', 'vodien', and 'crazy-domains' should use 'networksolutions'
* as the brand identifier when making AI SiteGen API calls.
*/
add_filter(
'newfold_ai_sitegen_brand',
function ( $brand ) {
// Check if this plugin's Data class has the get_ai_sitegen_brand method
if ( method_exists( \Web\Data::class, 'get_ai_sitegen_brand' ) ) {
return \Web\Data::get_ai_sitegen_brand();
}
return $brand;
}
);
// Load AI Page Designer module
$ai_page_designer_bootstrap = WEB_PLUGIN_DIR . '/vendor/newfold-labs/wp-module-ai-page-designer/bootstrap.php';
if ( file_exists( $ai_page_designer_bootstrap ) ) {
require_once $ai_page_designer_bootstrap;
}
// Set up the updater endpoint and map values
$updateurl = 'https://hiive.cloud/workers/release-api/plugins/newfold-labs/wp-plugin-web'; // Custom API GET endpoint
$pluginUpdater = new PluginUpdater( WEB_PLUGIN_FILE, $updateurl );
$pluginUpdater->setDataMap(
array(
'version' => 'version.latest',
'download_link' => 'download',
'last_updated' => 'updated',
'requires' => 'requires.wp',
'requires_php' => 'requires.php',
'tested' => 'tested.wp',
)
);
$pluginUpdater->setDataOverrides(
array(
'banners' => array(
'2x' => 'https://cdn.hiive.space/marketplace/vendors-assets/web-banner.svg',
'1x' => 'https://cdn.hiive.space/marketplace/vendors-assets/web-banner.svg',
),
'icons' => array(
'2x' => 'https://cdn.hiive.space/marketplace/vendors-assets/web-icon.svg',
'1x' => 'https://cdn.hiive.space/marketplace/vendors-assets/web-icon.svg',
),
)
);
// Handle any upgrade routines (only in the admin)
if ( is_admin() ) {
// Handle plugin upgrades
$upgrade_handler = new UpgradeHandler(
WEB_PLUGIN_DIR . '/inc/upgrades', // Directory where upgrade routines live
get_option( 'web_plugin_version', '0.9.0' ), // Old plugin version (from database)
WEB_PLUGIN_VERSION // New plugin version (from code)
);
// Returns true if the old version doesn't match the new version
$did_upgrade = $upgrade_handler->maybe_upgrade();
if ( $did_upgrade ) {
// If an upgrade occurred, update the new version in the database to prevent running the routine(s) again.
update_option( 'web_plugin_version', WEB_PLUGIN_VERSION, true );
}
}
// Required files
require WEB_PLUGIN_DIR . '/inc/Admin.php';
require WEB_PLUGIN_DIR . '/inc/AdminBar.php';
require WEB_PLUGIN_DIR . '/inc/base.php';
require WEB_PLUGIN_DIR . '/inc/jetpack.php';
require WEB_PLUGIN_DIR . '/inc/partners.php';
require WEB_PLUGIN_DIR . '/inc/RestApi/CachingController.php';
require WEB_PLUGIN_DIR . '/inc/RestApi/SettingsController.php';
require WEB_PLUGIN_DIR . '/inc/RestApi/rest-api.php';
require WEB_PLUGIN_DIR . '/inc/settings.php';
require WEB_PLUGIN_DIR . '/inc/updates.php';
require WEB_PLUGIN_DIR . '/inc/widgets/bootstrap.php';
/* WordPress Admin Page & Features */
if ( is_admin() ) {
new Admin();
}
AdminBar::init();
// Instantiate the Features singleton
Features::getInstance();
/**
* Filter to add applicable BN code to paypal requests
*
* https://github.com/newfold-labs/wp-module-ecommerce/blob/trunk/bootstrap.php#L62-L101
*/
if ( function_exists( 'add_filter' ) ) {
add_filter(
'http_request_args',
function ( $parsed_args, $url ) {
// Bail early if the request is not to PayPal's v2 checkout API
if ( false === stripos( wp_parse_url( $url, PHP_URL_HOST ), 'paypal.com' ) ) {
return $parsed_args;
}
// Check for an existing bn_code
$bn_code = isset( $parsed_args['headers']['PayPal-Partner-Attribution-Id'] ) ? $parsed_args['headers']['PayPal-Partner-Attribution-Id'] : null;
// Ensure we only set when blank, or when using one of our stale codes
if ( is_null( $bn_code ) || false !== stripos( $bn_code, 'yith' ) || false !== stripos( $bn_code, 'newfold' ) ) {
// The correct code is case-sensitive. YITH brand is uppercase, but the code is not.
$parsed_args['headers']['PayPal-Partner-Attribution-Id'] = 'Yith_PCP';
}
return $parsed_args;
},
10,
2
);
add_filter(
'script_loader_tag',
function ( $tag, $handle, $source ) {
if ( stripos( $source, 'paypal.com/sdk' ) !== false ) {
$replacement = ' data-partner-attribution-id="Yith_PCP"';
if ( stripos( $tag, 'partner-attribution-id' ) === false ) {
$tag = str_replace( ' src=', $replacement . ' src=', $tag );
} elseif ( stripos( $tag, 'NEWFOLD' ) || stripos( $tag, 'YITH' ) ) {
$tag = preg_replace( '/ data-partner-attribution-id="(.*?)"/', $replacement, $tag );
}
}
return $tag;
},
25,
3
);
}
/**
* Workaround for onboarding preview pages returning 404 on production.
*
* PreviewsService::publish_page() in wp-module-onboarding creates preview pages
* via wp_insert_post() but never calls flush_rewrite_rules() afterward. On production
* with pretty permalinks, newly created pages are not routable until the rewrite rules
* are flushed. We hook on wp_after_insert_post (which fires via direct function call
* inside wp_insert_post, so it is NOT removed by PreviewsService's remove_all_actions
* call) to flush rewrite rules whenever a new page is published during a REST request.
*/
add_action(
'wp_after_insert_post',
function ( $post_id, $post, $update ) {
if ( ! $update && 'page' === $post->post_type && 'publish' === $post->post_status && defined( 'REST_REQUEST' ) && REST_REQUEST ) {
flush_rewrite_rules();
}
},
10,
3
);
/**
* Handle plugin activation tasks.
*
* Runs on fresh plugin activation to set up the environment properly.
* This includes flushing rewrite rules and clearing stale transients.
*
* @return void
*/
function on_activate() {
// Clear transients that may contain stale data.
delete_transient( 'newfold_marketplace' );
delete_transient( 'newfold_notifications' );
delete_transient( 'newfold_solutions' );
delete_transient( 'nfd_site_capabilities' );
// Flush rewrite rules to ensure permalinks work correctly.
flush_rewrite_rules();
}
/**
* Check if the plugin was freshly activated and run activation tasks.
*
* This runs on admin_init to ensure WordPress is fully loaded before
* executing activation tasks like flushing rewrite rules.
*
* @return void
*/
function load_plugin() {
if ( is_admin() && WEB_PLUGIN_FILE === get_option( 'nfd_activated_fresh' ) ) {
delete_option( 'nfd_activated_fresh' );
on_activate();
}
}
// Check for plugin activation on admin_init.
add_action( 'admin_init', __NAMESPACE__ . '\\load_plugin' );
// Register activation hook to set the activation flag.
register_activation_hook(
WEB_PLUGIN_FILE,
function () {
add_option( 'nfd_activated_fresh', WEB_PLUGIN_FILE );
}
);