-
Notifications
You must be signed in to change notification settings - Fork 2
/
wp-scheduled-posts.php
322 lines (288 loc) · 8.89 KB
/
wp-scheduled-posts.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
<?php
/*
* Plugin Name: SchedulePress
* Description: Automate your content workflow with SchedulePress. Take a quick glance at your content planning with Schedule Calendar, Dashboard widget & Sitewide admin bar. Instantly share your posts on social media platforms such as Facebook, Twitter & many more.
* Version: 5.2.0
* Author: WPDeveloper
* Author URI: https://wpdeveloper.com
* Text Domain: wp-scheduled-posts
*/
if (!defined('ABSPATH')) exit;
if ( ! version_compare( PHP_VERSION, '7.2', '>=' ) ) {
add_action( 'admin_notices', 'wpsp_fail_php_version', 51 );
return;
}
else {
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) {
require_once dirname(__FILE__) . '/vendor/autoload.php';
}
// Plugin Start
WPSP_Start();
}
final class WPSP
{
private $installer;
private $assets;
private $admin;
private $email;
private $social;
private $api;
private $basename = 'wp-scheduled-posts-pro/wp-scheduled-posts-pro.php';
private function __construct()
{
$this->define_constants();
if( $this->check_pro_compatibility() ) {
add_action( 'admin_notices', [$this, 'wpsp_fail_pro_version'], 52 );
if(!is_plugin_active( $this->basename ) && $this->check_pro_compatibility('4.3.3', '=')){
if( !get_option('wpsp_activated_pro_once')){
activate_plugins( $this->basename );
add_option('wpsp_activated_pro_once', true, false);
}
}
}
if(version_compare(get_option('wpsp_version'), WPSP_VERSION, '!=')){
$this->delete_plugin_update_transient();
}
add_action( 'upgrader_process_complete', [$this, 'upgrade_completed'], 10, 2 );
register_activation_hook(__FILE__, [$this, 'activate']);
register_deactivation_hook(__FILE__, [$this, 'deactivate']);
$this->installer = new WPSP\Installer();
add_action('plugins_loaded', [$this, 'init_plugin']);
add_action('wp_loaded', [$this, 'run_migrator']);
add_action('init', [$this, 'load_calendar']);
add_filter('jwt_auth_whitelist', array($this, 'whitelist_API'));
$this->set_global_settings();
}
public static function init()
{
static $instance = false;
if (!$instance) {
$instance = new self();
}
return $instance;
}
public function define_constants()
{
/**
* Defines CONSTANTS for Whole plugins.
*/
define('WPSP_VERSION', '5.2.0');
define('WPSP_SETTINGS_NAME_OLD', 'wpsp_settings');
define('WPSP_SETTINGS_NAME', 'wpsp_settings_v5');
define('WPSP_PLUGIN_FILE', __FILE__);
define('WPSP_PLUGIN_BASENAME', plugin_basename(__FILE__));
define('WPSP_PLUGIN_SLUG', 'wp-scheduled-posts');
define('WPSP_SETTINGS_SLUG', 'schedulepress');
define('WPSP_PLUGIN_ROOT_URI', plugins_url("/", __FILE__));
define('WPSP_PLUGIN_ROOT_PATH', plugin_basename(dirname(__FILE__)));
define('WPSP_ADMIN_URL', WPSP_PLUGIN_ROOT_URI . 'includes/Admin/');
define('WPSP_ROOT_DIR_PATH', plugin_dir_path(__FILE__));
define('WPSP_INCLUDES_DIR_PATH', WPSP_ROOT_DIR_PATH . 'includes/');
define('WPSP_VIEW_DIR_PATH', WPSP_ROOT_DIR_PATH . 'views/');
define('WPSP_ASSETS_DIR_PATH', WPSP_ROOT_DIR_PATH . 'assets/');
define('WPSP_ASSETS_URI', WPSP_PLUGIN_ROOT_URI . 'assets/');
define('WPSCP_ADMIN_DIR_PATH', WPSP_ROOT_DIR_PATH . '/includes/Admin/');
// Midleware
define('WPSP_SOCIAL_OAUTH2_TOKEN_MIDDLEWARE', 'https://api.schedulepress.com.test/callback.php');
define('WPSP_SOCIAL_OAUTH2_PINTEREST_APP_ID', '1477330');
define('WPSP_SOCIAL_OAUTH2_LINKEDIN_APP_ID', '77nbfvpkganvt6');
}
public function check_pro_compatibility($version2 = '5.0.0', $operator = '<'){
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$abs_path = WP_PLUGIN_DIR . '/' . $this->basename;
if (
$this->is_plugin_installed( $this->basename ) &&
version_compare( get_plugin_data( $abs_path )['Version'], $version2, $operator )
) {
return true;
}
return false;
}
/**
* Check if a plugin is installed
*
* @since 2.0.0
*/
public function is_plugin_installed($basename)
{
$plugins = get_plugins();
return isset($plugins[$basename]);
}
public function wpsp_fail_pro_version() {
?>
<div class="notice notice-error">
<p><?php printf(__( 'SchedulePress Free v5.0 needs SchedulePress Pro v5.0 for better performance. Please update SchedulePress Pro plugin to v5.0. Contact our <a href="%s" target="_blank">Support</a> if you need any assistance.', 'wp-scheduled-posts' ), 'https://wpdeveloper.com/support/'); ?></p>
</div>
<?php
}
/**
* Initialize the plugin
*
* @return void
*/
public function init_plugin()
{
$this->getAssets();
$this->getEmail();
$this->getSocial();
$this->getAPI();
if (is_admin()) {
$this->getAdmin();
// Your admin code here
}
$this->load_textdomain();
}
public function getAssets() {
if (!$this->assets) {
$this->assets = new WPSP\Assets();
}
return $this->assets;
}
/**
* Undocumented function
*
* @return WPSP\Admin
*/
public function getAdmin() {
if (!$this->admin) {
$this->admin = new WPSP\Admin();
}
return $this->admin;
}
public function getEmail() {
if (!$this->email) {
$this->email = new WPSP\Email();
}
return $this->email;
}
public function getSocial() {
if (!$this->social) {
$this->social = new WPSP\Social();
}
return $this->social;
}
public function getAPI() {
if (!$this->api) {
$this->api = new WPSP\API();
}
return $this->api;
}
public function load_textdomain()
{
load_plugin_textdomain(
'wp-scheduled-posts',
false,
dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
);
}
public function set_global_settings()
{
$this->social_profile_status_handler();
$GLOBALS['wpsp_settings_v5'] = json_decode(get_option(WPSP_SETTINGS_NAME));
if($this->check_pro_compatibility('5.0.0', '=')){
$GLOBALS['wpsp_settings'] = $GLOBALS['wpsp_settings_v5'];
}
else if($this->check_pro_compatibility('5.0.0', '<')){
$GLOBALS['wpsp_settings'] = json_decode(get_option(WPSP_SETTINGS_NAME_OLD));
}
}
public function social_profile_status_handler()
{
$settings = json_decode(get_option(WPSP_SETTINGS_NAME), true);
$is_pro = class_exists('WPSP_PRO');
if( !empty($settings) && (!isset( $settings['is_pro'] ) || ( $settings['is_pro'] !== $is_pro ) )) {
$settings['is_pro'] = $is_pro;
if( $is_pro ) {
$this->installer->get_social_profile_status_modified_data( $settings, 'revert');
}else{
$this->installer->get_social_profile_status_modified_data( $settings, 'convert');
}
}
}
/**
* Do stuff upon plugin activation
*
* @return void
*/
public function activate()
{
$this->delete_plugin_update_transient();
update_option('wpsp_do_activation_redirect', true);
}
/**
* Do stuff upon plugin deactive
*
* @return void
*/
public function deactivate()
{
do_action('wpsp_run_deactivate_installer');
}
/**
* This method is called when a plugin upgrade is completed.
* It checks if the upgraded plugin is WP Scheduled Posts and deletes the plugin update transient.
*
* @param object $upgrader_object The upgrader object.
* @param array $options The upgrade options.
*
* @return void
*/
public function upgrade_completed( $upgrader_object, $options){
if( isset( $options['plugins'] ) && is_array( $options['plugins'] ) && !empty( $options['action'] ) && !empty( $options['type'] ) ) {
if ($options['action'] == 'update' && $options['type'] == 'plugin' && in_array(WPSP_PLUGIN_BASENAME, $options['plugins'])) {
$this->delete_plugin_update_transient();
}
}
}
/**
* This method deletes the plugin update transient and related options.
*
* @return void
*/
private function delete_plugin_update_transient() {
$license = get_option('wp-scheduled-posts-pro-license-key');
$string = "wp-scheduled-posts-pro" . $license;
delete_transient('update_plugins');
delete_option('_site_transient_update_plugins');
delete_option('edd_sl_' . md5( serialize( $string ) ));
delete_option('edd_sl_failed_http_' . md5( 'http://api.wpdeveloper.com/' ));
}
public function run_migrator()
{
$this->installer->migrate();
}
public function load_calendar()
{
new WPSP\Admin\Calendar();
}
public function whitelist_API($endpoints)
{
$endpoints[] = '/wp-json/wp-scheduled-posts/v1/*';
$endpoints[] = '/wp-json/wp-scheduled-posts-pro/v1/*';
$endpoints[] = '/wpscp/v1/*';
$endpoints[] = '/index.php?rest_route=/wp-scheduled-posts/v1/*';
return $endpoints;
}
}
/**
* Initializes the main plugin
*
* @return \WPSP
*/
function WPSP_Start()
{
return WPSP::init();
}
function wpsp_fail_php_version() {
$message = sprintf(
/* translators: 1: `<h3>` opening tag, 2: `</h3>` closing tag, 3: PHP version. 4: Link opening tag, 5: Link closing tag. */
esc_html__( '%1$sSchedulePress isn’t running because PHP is outdated.%2$s Update to PHP version %3$s and get back to creating!', 'wp-scheduled-posts' ),
'<h3>',
'</h3>',
'7.2'
);
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
echo wp_kses_post( $html_message );
}