-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboostbox.php
354 lines (320 loc) · 11.7 KB
/
boostbox.php
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<?php
/**
* The plugin bootstrap file
*
* @package BoostBox
* @author Devio Digital <[email protected]>
* @license GPL-2.0+ https://www.gnu.org/licenses/gpl-2.0.txt
* @link https://deviodigital.com
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: BoostBox
* Plugin URI: https://robertdevore.com/boostbox-wordpress-popup-builder-for-the-core-editor/
* Description: Build popups for lead generation, content promotion and more using the core editor.
* Version: 2.2.0
* Author: Devio Digital
* Author URI: https://deviodigital.com
* License: GPL-2.0+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: boostbox
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
wp_die();
}
require 'plugin-update-checker/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/deviodigital/boostbox/',
__FILE__,
'boostbox'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch( 'main' );
// Current plugin version.
define( 'BOOSTBOX_VERSION', '2.2.0' );
// Plugin basename.
$plugin_name = plugin_basename( __FILE__ );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-boostbox-activator.php
*
* @return void
*/
function activate_boostbox() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-boostbox-activator.php';
BoostBox_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-boostbox-deactivator.php
*
* @return void
*/
function deactivate_boostbox() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-boostbox-deactivator.php';
BoostBox_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_boostbox' );
register_deactivation_hook( __FILE__, 'deactivate_boostbox' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*
* @return void
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-boostbox.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
* @return void
*/
function run_boostbox() {
$plugin = new BoostBox();
$plugin->run();
}
run_boostbox();
/**
* Add settings link on plugin page
*
* @param array $links an array of links related to the plugin.
*
* @since 1.0.0
* @return array updatead array of links related to the plugin.
*/
function boostbox_settings_link( $links ) {
$settings_link = '<a href="edit.php?post_type=boostbox_popups&page=settings">' . esc_html__( 'Settings', 'boostbox' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
add_filter( "plugin_action_links_$plugin_name", 'boostbox_settings_link' );
/**
* Redirect to the BoostBox Settings page on single plugin activation
*
* @since 1.0.0
* @return void
*/
function boostbox_redirect() {
if ( get_option( 'boostbox_do_activation_redirect', false ) ) {
delete_option( 'boostbox_do_activation_redirect' );
if ( ! isset( $_GET['activate-multi'] ) ) {
wp_redirect( 'edit.php?post_type=boostbox_popups&page=settings' );
}
}
}
add_action( 'admin_init', 'boostbox_redirect' );
/**
* Display a custom admin notice to inform users about plugin update issues.
*
* This function displays a dismissible admin notice warning users about
* restrictions imposed by WordPress® leadership that may impact automatic
* plugin updates. It provides a link to a resource where users can learn how
* to continue receiving updates.
*
* @since 2.0.1
* @return void
*/
function boostbox_custom_update_notice() {
// Check if the notice has been dismissed.
if ( get_option( 'boostbox_custom_update_notice_dismissed' ) ) {
return;
}
// Translating the notice text using WordPress® translation functions.
$notice_text = sprintf(
__( 'Important Notice: Due to recent changes initiated by WordPress® leadership, access to the plugin repository is being restricted for certain hosting providers and developers. This may impact automatic updates for your plugins. To ensure you continue receiving updates for BoostBox and to learn about the next steps, please visit %s.', 'boostbox' ),
'<a href="https://robertdevore.com/wordpress-plugin-updates/" target="_blank">this page</a>'
);
// Display the admin notice.
echo '<div class="notice notice-warning is-dismissible" id="custom-update-notice">
<p>' . $notice_text . '</p>
</div>';
}
add_action( 'admin_notices', 'boostbox_custom_update_notice' );
/**
* Enqueue the JavaScript to handle the dismissal of the notice.
*
* @since 2.0.1
* @return void
*/
function boostbox_custom_update_notice_scripts() {
wp_enqueue_script( 'boostbox-custom-notice-dismiss', plugin_dir_url( __FILE__ ) . 'public/js/custom-notice-dismiss.js', [ 'jquery' ], false, true );
wp_localize_script( 'boostbox-custom-notice-dismiss', 'custom_notice', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'boostbox_custom_notice_dismiss_nonce' ),
] );
}
add_action( 'admin_enqueue_scripts', 'boostbox_custom_update_notice_scripts' );
/**
* AJAX handler to mark the notice as dismissed.
*
* @since 2.0.1
* @return void
*/
function boostbox_custom_dismiss_update_notice() {
check_ajax_referer( 'boostbox_custom_notice_dismiss_nonce', 'nonce' );
update_option( 'boostbox_custom_update_notice_dismissed', 1 );
wp_send_json_success();
}
add_action( 'wp_ajax_boostbox_custom_dismiss_update_notice', 'boostbox_custom_dismiss_update_notice' );
/**
* Add Go Pro link on plugin page
*
* @param array $links an array of links related to the plugin.
*
* @since 2.1.1
* @return array updatead array of links related to the plugin.
*/
function boostbox_go_pro_link( $links ) {
// Pro link.
$pro_link = '<a href="https://deviodigital.com/product/boostbox-pro" target="_blank" style="font-weight:700;">' . esc_attr__( 'Go Pro', 'boostbox' ) . '</a>';
if ( ! function_exists( 'run_boostbox_pro' ) ) {
array_unshift( $links, $pro_link );
}
return $links;
}
add_filter( "plugin_action_links_$plugin_name", 'boostbox_go_pro_link' );
/**
* Check BoostBox Pro version number.
*
* If the BoostBox Pro version number is less than what's defined below, there will
* be a notice added to the admin screen letting the user know there's a new
* version of the BoostBox Pro plugin available.
*
* @since 2.1.1
* @return void
*/
function boostbox_check_pro_version() {
// Only run if BoostBox Pro is active.
if ( function_exists( 'run_boostbox_pro' ) ) {
// Check if BoostBox Pro version is defined.
if ( ! defined( 'BOOSTBOX_PRO_VERSION' ) ) {
define( 'BOOSTBOX_PRO_VERSION', 0 ); // default to zero.
}
// Set pro version number.
$pro_version = BOOSTBOX_PRO_VERSION;
if ( '0' == $pro_version || $pro_version < '1.0.0' ) {
add_action( 'admin_notices', 'boostbox_update_boostbox_pro_notice' );
}
}
}
add_action( 'admin_init', 'boostbox_check_pro_version' );
/**
* Error notice - Runs if BoostBox Pro is out of date.
*
* @see boostbox_check_pro_version()
* @since 2.1.1
* @return void
*/
function boostbox_update_boostbox_pro_notice() {
$boostbox_orders = '<a href="https://www.deviodigital.com/my-account/orders/" target="_blank">' . esc_attr__( 'Orders', 'boostbox' ) . '</a>';
$error = sprintf( esc_html__( 'There is a new version of BoostBox Pro available. Download your copy from the %1$s page on Devio Digital.', 'boostbox' ), $boostbox_orders );
echo '<div class="notice notice-info"><p>' . $error . '</p></div>';
}
/**
* Helper function to handle WordPress.com environment checks.
*
* @param string $plugin_slug The plugin slug.
* @param string $learn_more_link The link to more information.
*
* @since 2.2.0
* @return bool
*/
function wp_com_plugin_check( $plugin_slug, $learn_more_link ) {
// Check if the site is hosted on WordPress.com.
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
// Ensure the deactivate_plugins function is available.
if ( ! function_exists( 'deactivate_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Deactivate the plugin if in the admin area.
if ( is_admin() ) {
deactivate_plugins( $plugin_slug );
// Add a deactivation notice for later display.
add_option( 'wpcom_deactivation_notice', $learn_more_link );
// Prevent further execution.
return true;
}
}
return false;
}
/**
* Auto-deactivate the plugin if running in an unsupported environment.
*
* @since 2.2.0
* @return void
*/
function wpcom_auto_deactivation() {
if ( wp_com_plugin_check( plugin_basename( __FILE__ ), 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' ) ) {
return; // Stop execution if deactivated.
}
}
add_action( 'plugins_loaded', 'wpcom_auto_deactivation' );
/**
* Display an admin notice if the plugin was deactivated due to hosting restrictions.
*
* @since 2.2.0
* @return void
*/
function wpcom_admin_notice() {
$notice_link = get_option( 'wpcom_deactivation_notice' );
if ( $notice_link ) {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
__( 'My Plugin has been deactivated because it cannot be used on WordPress.com-hosted websites. %s', 'boostbox' ),
'<a href="' . esc_url( $notice_link ) . '" target="_blank" rel="noopener">' . __( 'Learn more', 'boostbox' ) . '</a>'
)
);
?>
</p>
</div>
<?php
delete_option( 'wpcom_deactivation_notice' );
}
}
add_action( 'admin_notices', 'wpcom_admin_notice' );
/**
* Prevent plugin activation on WordPress.com-hosted sites.
*
* @since 2.2.0
* @return void
*/
function wpcom_activation_check() {
if ( wp_com_plugin_check( plugin_basename( __FILE__ ), 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' ) ) {
// Display an error message and stop activation.
wp_die(
wp_kses_post(
sprintf(
'<h1>%s</h1><p>%s</p><p><a href="%s" target="_blank" rel="noopener">%s</a></p>',
__( 'Plugin Activation Blocked', 'boostbox' ),
__( 'This plugin cannot be activated on WordPress.com-hosted websites. It is restricted due to concerns about WordPress.com policies impacting the community.', 'boostbox' ),
esc_url( 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' ),
__( 'Learn more', 'boostbox' )
)
),
esc_html__( 'Plugin Activation Blocked', 'boostbox' ),
[ 'back_link' => true ]
);
}
}
register_activation_hook( __FILE__, 'wpcom_activation_check' );
/**
* Add a deactivation flag when the plugin is deactivated.
*
* @since 2.2.0
* @return void
*/
function wpcom_deactivation_flag() {
add_option( 'wpcom_deactivation_notice', 'https://robertdevore.com/why-this-plugin-doesnt-support-wordpress-com-hosting/' );
}
register_deactivation_hook( __FILE__, 'wpcom_deactivation_flag' );