forked from afragen/wordpress-beta-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWPBT_Bootstrap.php
137 lines (126 loc) · 3.14 KB
/
WPBT_Bootstrap.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
<?php
/**
* WordPress Beta Tester
*
* @package WordPress_Beta_Tester
* @author Andy Fragen, original author Peter Westwood.
* @license GPLv2+
* @copyright 2009-2016 Peter Westwood (email : peter.westwood@ftwr.co.uk)
*/
/**
* WPBT_Bootstrap
*/
class WPBT_Bootstrap {
/**
* Holds main plugin file.
*
* @var string
*/
protected $file;
/**
* Holds plugin options.
*
* @var array
*/
protected static $options;
/**
* Constructor.
*
* @param string $file Main plugin file.
* @return void
*/
public function __construct( $file ) {
$this->file = $file;
}
/**
* Let's get started.
*
* @return void
*/
public function run() {
$this->deactivate_die_wordpress_develop();
$this->load_hooks();
self::$options = get_site_option(
'wp_beta_tester',
array(
'channel' => 'branch-development',
'stream-option' => '',
)
);
$this->v2_v3_settings_migrator();
( new WP_Beta_Tester( $this->file, self::$options ) )->run();
}
/**
* Gracefully transfer v2 settings to v4.
*
* @since 3.0.0
* @return void
*/
private function v2_v3_settings_migrator() {
if ( isset( self::$options['stream'] ) && ! isset( self::$options['channel'] ) ) {
switch ( self::$options['stream'] ) {
case 'point':
self::$options['channel'] = 'branch-development';
self::$options['stream-option'] = '';
break;
case 'beta-rc-point':
self::$options['channel'] = 'branch-development';
self::$options['stream-option'] = 'beta';
break;
case 'unstable':
self::$options['channel'] = 'development';
self::$options['stream-option'] = '';
break;
case 'beta-rc-unstable':
self::$options['channel'] = 'development';
self::$options['stream-option'] = 'beta';
break;
}
update_site_option( 'wp_beta_tester', (array) self::$options );
}
}
/**
* Deactivate and die if trying to use with `wordpress-develop`.
*
* @return void
*/
private function deactivate_die_wordpress_develop() {
$wp_version = get_bloginfo( 'version' );
$version_regex = '@(\d+\.\d+(\.\d+)?)-(alpha|beta|RC)(\d+)?-(\d+-src|\d{8}\.\d{6})@';
$is_wp_develop = preg_match( $version_regex, $wp_version );
if ( $is_wp_develop ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
deactivate_plugins( $this->file );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_die( new \WP_Error( 'deactivate', esc_html__( 'Cannot run WordPress Beta Tester plugin in `wordpress-develop`', 'wordpress-beta-tester' ) ) );
}
}
/**
* Load hooks.
*
* @return void
*/
public function load_hooks() {
add_action( 'init', array( $this, 'load_textdomain' ) );
register_activation_hook( $this->file, array( $this, 'de_activate' ) );
register_deactivation_hook( $this->file, array( $this, 'de_activate' ) );
}
/**
* Load textdomain.
*
* @return void
*/
public function load_textdomain() {
load_plugin_textdomain( 'wordpress-beta-tester' );
}
/**
* Run on plugin activation/deactivation.
*
* Delete 'update_core' transient.
*
* @return void
*/
public function de_activate() {
delete_site_transient( 'update_core' );
}
}