| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: SchedulePress |
| 4 |
* 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. |
| 5 |
* Version: 5.3.3 |
| 6 |
* Author: WPDeveloper |
| 7 |
* Author URI: https://wpdeveloper.com |
| 8 |
* Text Domain: wp-scheduled-posts |
| 9 |
*/ |
| 10 |
|
| 11 |
if (!defined('ABSPATH')) exit; |
| 12 |
|
| 13 |
if ( ! version_compare( PHP_VERSION, '7.2', '>=' ) ) { |
| 14 |
add_action( 'admin_notices', 'wpsp_fail_php_version', 51 ); |
| 15 |
return; |
| 16 |
} |
| 17 |
else { |
| 18 |
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) { |
| 19 |
require_once dirname(__FILE__) . '/vendor/autoload.php'; |
| 20 |
} |
| 21 |
// Plugin Start |
| 22 |
WPSP_Start(); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
final class WPSP |
| 27 |
{ |
| 28 |
private $installer; |
| 29 |
private $assets; |
| 30 |
private $admin; |
| 31 |
private $email; |
| 32 |
private $social; |
| 33 |
private $api; |
| 34 |
private $basename = 'wp-scheduled-posts-pro/wp-scheduled-posts-pro.php'; |
| 35 |
|
| 36 |
private function __construct() |
| 37 |
{ |
| 38 |
$this->define_constants(); |
| 39 |
add_action('admin_init', function () { |
| 40 |
if ($this->check_pro_compatibility()) { |
| 41 |
add_action('admin_notices', [$this, 'wpsp_fail_pro_version'], 52); |
| 42 |
|
| 43 |
if (!is_plugin_active($this->basename) && $this->check_pro_compatibility('4.3.3', '=')) { |
| 44 |
if (!get_option('wpsp_activated_pro_once')) { |
| 45 |
activate_plugins($this->basename); |
| 46 |
add_option('wpsp_activated_pro_once', true, false); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
$this->set_global_settings(); |
| 51 |
}); |
| 52 |
|
| 53 |
if(version_compare(get_option('wpsp_version'), WPSP_VERSION, '!=')){ |
| 54 |
$this->delete_plugin_update_transient(); |
| 55 |
} |
| 56 |
add_action( 'upgrader_process_complete', [$this, 'upgrade_completed'], 10, 2 ); |
| 57 |
register_activation_hook(__FILE__, [$this, 'activate']); |
| 58 |
register_deactivation_hook(__FILE__, [$this, 'deactivate']); |
| 59 |
$this->installer = new WPSP\Installer(); |
| 60 |
add_action('init', [$this, 'init_plugin']); |
| 61 |
add_action('wp_loaded', [$this, 'run_migrator']); |
| 62 |
add_action('init', [$this, 'load_calendar']); |
| 63 |
add_filter('jwt_auth_whitelist', array($this, 'whitelist_API')); |
| 64 |
|
| 65 |
// init plugin updater with version check |
| 66 |
if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '5.1.3', '>=' ) && version_compare( WPSP_PRO_VERSION, '5.2.0', '<=' ) ) { |
| 67 |
add_action( 'init', [ $this, 'wpsp_init_plugin_updater' ], 99 ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Initialize plugin updater |
| 73 |
* |
| 74 |
* @since 5.2.9 |
| 75 |
*/ |
| 76 |
function wpsp_init_plugin_updater() { |
| 77 |
if ( is_admin() ) { |
| 78 |
$license_manager = \WPSP_PRO\Dependencies\WPDeveloper\Licensing\LicenseManager::get_instance( [] ); |
| 79 |
$license_manager->plugin_updater(); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
public static function init() |
| 84 |
{ |
| 85 |
static $instance = false; |
| 86 |
|
| 87 |
if (!$instance) { |
| 88 |
$instance = new self(); |
| 89 |
} |
| 90 |
|
| 91 |
return $instance; |
| 92 |
} |
| 93 |
public function define_constants() |
| 94 |
{ |
| 95 |
/** |
| 96 |
* Defines CONSTANTS for Whole plugins. |
| 97 |
*/ |
| 98 |
define('WPSP_VERSION', '5.3.3'); |
| 99 |
define('WPSP_SETTINGS_NAME_OLD', 'wpsp_settings'); |
| 100 |
define('WPSP_SETTINGS_NAME', 'wpsp_settings_v5'); |
| 101 |
define('WPSP_PLUGIN_FILE', __FILE__); |
| 102 |
define('WPSP_PLUGIN_BASENAME', plugin_basename(__FILE__)); |
| 103 |
define('WPSP_PLUGIN_SLUG', 'wp-scheduled-posts'); |
| 104 |
define('WPSP_SETTINGS_SLUG', 'schedulepress'); |
| 105 |
define('WPSP_PLUGIN_ROOT_URI', plugins_url("/", __FILE__)); |
| 106 |
define('WPSP_PLUGIN_ROOT_PATH', plugin_basename(dirname(__FILE__))); |
| 107 |
define('WPSP_ADMIN_URL', WPSP_PLUGIN_ROOT_URI . 'includes/Admin/'); |
| 108 |
define('WPSP_ROOT_DIR_PATH', plugin_dir_path(__FILE__)); |
| 109 |
define('WPSP_INCLUDES_DIR_PATH', WPSP_ROOT_DIR_PATH . 'includes/'); |
| 110 |
define('WPSP_VIEW_DIR_PATH', WPSP_ROOT_DIR_PATH . 'views/'); |
| 111 |
define('WPSP_ASSETS_DIR_PATH', WPSP_ROOT_DIR_PATH . 'assets/'); |
| 112 |
define('WPSP_ASSETS_URI', WPSP_PLUGIN_ROOT_URI . 'assets/'); |
| 113 |
define('WPSCP_ADMIN_DIR_PATH', WPSP_ROOT_DIR_PATH . '/includes/Admin/'); |
| 114 |
// Midleware |
| 115 |
define('WPSP_SOCIAL_OAUTH2_TOKEN_MIDDLEWARE', 'https://api.schedulepress.com.test/callback.php'); |
| 116 |
define('WPSP_SOCIAL_OAUTH2_TOKEN_MIDDLEWARE_DEV', 'https://devapi.schedulepress.com/v2/callback.php'); |
| 117 |
define('WPSP_SOCIAL_OAUTH2_PINTEREST_APP_ID', '1478596'); |
| 118 |
define('WPSP_SOCIAL_OAUTH2_LINKEDIN_APP_ID', '77nbfvpkganvt6'); |
| 119 |
define('WPSP_SOCIAL_OAUTH2_GOOGLE_BUSINESS_APP_ID', '235972035985-30gv7k0vgo7j8gv69ppdphpt3n9fc9hp.apps.googleusercontent.com'); |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
public function check_pro_compatibility($version2 = '5.0.0', $operator = '<'){ |
| 124 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 125 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 126 |
} |
| 127 |
|
| 128 |
$abs_path = WP_PLUGIN_DIR . '/' . $this->basename; |
| 129 |
|
| 130 |
if ( |
| 131 |
$this->is_plugin_installed( $this->basename ) && |
| 132 |
version_compare( get_plugin_data( $abs_path )['Version'], $version2, $operator ) |
| 133 |
) { |
| 134 |
return true; |
| 135 |
} |
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Check if a plugin is installed |
| 141 |
* |
| 142 |
* @since 2.0.0 |
| 143 |
*/ |
| 144 |
public function is_plugin_installed($basename) |
| 145 |
{ |
| 146 |
$plugins = get_plugins(); |
| 147 |
return isset($plugins[$basename]); |
| 148 |
} |
| 149 |
|
| 150 |
public function wpsp_fail_pro_version() { |
| 151 |
?> |
| 152 |
<div class="notice notice-error"> |
| 153 |
<p> |
| 154 |
<?php |
| 155 |
printf( |
| 156 |
/* translators: %1$s: URL to the SchedulePress support page */ |
| 157 |
__( 'SchedulePress Free v5.0 needs SchedulePress Pro v5.0 for better performance. Please update SchedulePress Pro plugin to v5.0. Contact our <a href="%1$s" target="_blank">Support</a> if you need any assistance.', 'wp-scheduled-posts' ), |
| 158 |
'https://wpdeveloper.com/support/' |
| 159 |
); |
| 160 |
?> |
| 161 |
</p> |
| 162 |
</div> |
| 163 |
<?php |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Initialize the plugin |
| 168 |
* |
| 169 |
* @return void |
| 170 |
*/ |
| 171 |
public function init_plugin() |
| 172 |
{ |
| 173 |
$this->getAssets(); |
| 174 |
$this->getEmail(); |
| 175 |
$this->getSocial(); |
| 176 |
$this->getAPI(); |
| 177 |
|
| 178 |
if (is_admin()) { |
| 179 |
$this->getAdmin(); |
| 180 |
// Your admin code here |
| 181 |
} |
| 182 |
|
| 183 |
$this->load_textdomain(); |
| 184 |
} |
| 185 |
|
| 186 |
public function getAssets() { |
| 187 |
if (!$this->assets) { |
| 188 |
$this->assets = new WPSP\Assets(); |
| 189 |
} |
| 190 |
return $this->assets; |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Undocumented function |
| 195 |
* |
| 196 |
* @return WPSP\Admin |
| 197 |
*/ |
| 198 |
public function getAdmin() { |
| 199 |
if (!$this->admin) { |
| 200 |
$this->admin = new WPSP\Admin(); |
| 201 |
} |
| 202 |
return $this->admin; |
| 203 |
} |
| 204 |
|
| 205 |
public function getEmail() { |
| 206 |
if (!$this->email) { |
| 207 |
$this->email = new WPSP\Email(); |
| 208 |
} |
| 209 |
return $this->email; |
| 210 |
} |
| 211 |
|
| 212 |
public function getSocial() { |
| 213 |
if (!$this->social) { |
| 214 |
$this->social = new WPSP\Social(); |
| 215 |
} |
| 216 |
return $this->social; |
| 217 |
} |
| 218 |
|
| 219 |
public function getAPI() { |
| 220 |
if (!$this->api) { |
| 221 |
$this->api = new WPSP\API(); |
| 222 |
} |
| 223 |
return $this->api; |
| 224 |
} |
| 225 |
|
| 226 |
public function load_textdomain() |
| 227 |
{ |
| 228 |
|
| 229 |
load_plugin_textdomain( |
| 230 |
'wp-scheduled-posts', |
| 231 |
false, |
| 232 |
dirname(dirname(plugin_basename(__FILE__))) . '/languages/' |
| 233 |
); |
| 234 |
} |
| 235 |
|
| 236 |
public function set_global_settings() |
| 237 |
{ |
| 238 |
$this->social_profile_status_handler(); |
| 239 |
$GLOBALS['wpsp_settings_v5'] = json_decode(get_option(WPSP_SETTINGS_NAME)); |
| 240 |
if($this->check_pro_compatibility('5.0.0', '=')){ |
| 241 |
$GLOBALS['wpsp_settings'] = $GLOBALS['wpsp_settings_v5']; |
| 242 |
} |
| 243 |
else if($this->check_pro_compatibility('5.0.0', '<')){ |
| 244 |
$GLOBALS['wpsp_settings'] = json_decode(get_option(WPSP_SETTINGS_NAME_OLD)); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
public function social_profile_status_handler() |
| 249 |
{ |
| 250 |
$settings = json_decode(get_option(WPSP_SETTINGS_NAME), true); |
| 251 |
$is_pro = class_exists('WPSP_PRO'); |
| 252 |
if( !empty($settings) && (!isset( $settings['is_pro'] ) || ( $settings['is_pro'] !== $is_pro ) )) { |
| 253 |
$settings['is_pro'] = $is_pro; |
| 254 |
if( $is_pro ) { |
| 255 |
$this->installer->get_social_profile_status_modified_data( $settings, 'revert'); |
| 256 |
}else{ |
| 257 |
$this->installer->get_social_profile_status_modified_data( $settings, 'convert'); |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Do stuff upon plugin activation |
| 264 |
* |
| 265 |
* @return void |
| 266 |
*/ |
| 267 |
public function activate() |
| 268 |
{ |
| 269 |
$this->delete_plugin_update_transient(); |
| 270 |
update_option('wpsp_do_activation_redirect', true); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* Do stuff upon plugin deactive |
| 275 |
* |
| 276 |
* @return void |
| 277 |
*/ |
| 278 |
public function deactivate() |
| 279 |
{ |
| 280 |
do_action('wpsp_run_deactivate_installer'); |
| 281 |
} |
| 282 |
|
| 283 |
/** |
| 284 |
* This method is called when a plugin upgrade is completed. |
| 285 |
* It checks if the upgraded plugin is WP Scheduled Posts and deletes the plugin update transient. |
| 286 |
* |
| 287 |
* @param object $upgrader_object The upgrader object. |
| 288 |
* @param array $options The upgrade options. |
| 289 |
* |
| 290 |
* @return void |
| 291 |
*/ |
| 292 |
public function upgrade_completed( $upgrader_object, $options){ |
| 293 |
if( isset( $options['plugins'] ) && is_array( $options['plugins'] ) && !empty( $options['action'] ) && !empty( $options['type'] ) ) { |
| 294 |
if ($options['action'] == 'update' && $options['type'] == 'plugin' && in_array(WPSP_PLUGIN_BASENAME, $options['plugins'])) { |
| 295 |
$this->delete_plugin_update_transient(); |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* This method deletes the plugin update transient and related options. |
| 302 |
* |
| 303 |
* @return void |
| 304 |
*/ |
| 305 |
private function delete_plugin_update_transient() { |
| 306 |
$license = get_option('wp-scheduled-posts-pro-license-key'); |
| 307 |
$string = "wp-scheduled-posts-pro" . $license; |
| 308 |
delete_transient('update_plugins'); |
| 309 |
delete_option('_site_transient_update_plugins'); |
| 310 |
delete_option('edd_sl_' . md5( serialize( $string ) )); |
| 311 |
delete_option('edd_sl_failed_http_' . md5( 'http://api.wpdeveloper.com/' )); |
| 312 |
} |
| 313 |
|
| 314 |
public function run_migrator() |
| 315 |
{ |
| 316 |
$this->installer->migrate(); |
| 317 |
} |
| 318 |
public function load_calendar() |
| 319 |
{ |
| 320 |
new WPSP\Admin\Calendar(); |
| 321 |
} |
| 322 |
public function whitelist_API($endpoints) |
| 323 |
{ |
| 324 |
$endpoints[] = '/wp-json/wp-scheduled-posts/v1/*'; |
| 325 |
$endpoints[] = '/wp-json/wp-scheduled-posts-pro/v1/*'; |
| 326 |
$endpoints[] = '/wpscp/v1/*'; |
| 327 |
$endpoints[] = '/index.php?rest_route=/wp-scheduled-posts/v1/*'; |
| 328 |
return $endpoints; |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Initializes the main plugin |
| 334 |
* |
| 335 |
* @return \WPSP |
| 336 |
*/ |
| 337 |
function WPSP_Start() |
| 338 |
{ |
| 339 |
return WPSP::init(); |
| 340 |
} |
| 341 |
|
| 342 |
function wpsp_fail_php_version() { |
| 343 |
$message = sprintf( |
| 344 |
/* translators: 1: `<h3>` opening tag, 2: `</h3>` closing tag, 3: PHP version. 4: Link opening tag, 5: Link closing tag. */ |
| 345 |
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' ), |
| 346 |
'<h3>', |
| 347 |
'</h3>', |
| 348 |
'7.2' |
| 349 |
); |
| 350 |
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) ); |
| 351 |
echo wp_kses_post( $html_message ); |
| 352 |
} |