| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPSpeedo_Team; |
| 4 |
|
| 5 |
if ( !defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
class Initialize { |
| 9 |
public function __construct() { |
| 10 |
if ( !version_compare( PHP_VERSION, '7.0', '>=' ) ) { |
| 11 |
return add_action( 'admin_notices', array($this, 'fail_php_version') ); |
| 12 |
} |
| 13 |
if ( !version_compare( get_bloginfo( 'version' ), '5.9', '>=' ) ) { |
| 14 |
return add_action( 'admin_notices', array($this, 'fail_wp_version') ); |
| 15 |
} |
| 16 |
add_action( 'plugins_loaded', array($this, 'load_freemius'), 5 ); |
| 17 |
add_action( 'plugins_loaded', array($this, 'load_textdomain') ); |
| 18 |
add_action( 'plugins_loaded', array($this, 'save_install_time') ); |
| 19 |
add_action( 'plugins_loaded', array($this, 'initialize') ); |
| 20 |
add_action( 'admin_head', [$this, 'load_admin_icon_css'] ); |
| 21 |
} |
| 22 |
|
| 23 |
function load_freemius() { |
| 24 |
require_once WPS_TEAM_PATH . 'freemius.php'; |
| 25 |
} |
| 26 |
|
| 27 |
function load_admin_icon_css() { |
| 28 |
echo "<style>#adminmenu .menu-icon-wps-team-members .wp-menu-image img{padding-top:8px;width:22px;opacity:.8;height:auto;}</style>"; |
| 29 |
} |
| 30 |
|
| 31 |
public function load_textdomain() { |
| 32 |
} |
| 33 |
|
| 34 |
public function save_install_time() { |
| 35 |
$installed_time = get_option( '_wps_team_installed_time' ); |
| 36 |
if ( !$installed_time ) { |
| 37 |
update_option( '_wps_team_installed_time', time() ); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public function fail_php_version() { |
| 42 |
$message = '<strong>WPS Team</strong> ' . sprintf( |
| 43 |
/* translators: %s: Required PHP version */ |
| 44 |
esc_html_x( 'plugin requires PHP version %s+, plugin is currently NOT RUNNING.', 'Dashboard', 'wps-team' ), |
| 45 |
'5.6' |
| 46 |
); |
| 47 |
echo wp_kses_post( sprintf( '<div class="error">%s</div>', wpautop( $message ) ) ); |
| 48 |
} |
| 49 |
|
| 50 |
public function fail_wp_version() { |
| 51 |
$message = '<strong>WPS Team</strong> ' . sprintf( |
| 52 |
/* translators: %s: Required WordPress version */ |
| 53 |
esc_html_x( 'plugin requires WordPress version %s+. Because you are using an earlier version, the plugin is currently NOT RUNNING.', 'Dashboard', 'wps-team' ), |
| 54 |
'5.0' |
| 55 |
); |
| 56 |
echo wp_kses_post( sprintf( '<div class="error">%s</div>', wpautop( $message ) ) ); |
| 57 |
} |
| 58 |
|
| 59 |
function maybe_update_version() { |
| 60 |
if ( WPS_TEAM_VERSION === get_option( 'wps_team_version' ) ) { |
| 61 |
return false; |
| 62 |
} |
| 63 |
Upgrader::instance( get_option( 'wps_team_version' ), WPS_TEAM_VERSION ); |
| 64 |
update_option( 'wps_team_version', WPS_TEAM_VERSION ); |
| 65 |
plugin()->assets->assets_purge_all(); |
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
function maybe_update_pro_status() { |
| 70 |
$is_pro_active = get_option( 'wps_team_is_pro_active' ); |
| 71 |
$current_pro_status = ( wps_team_fs()->can_use_premium_code() ? 'yes' : 'no' ); |
| 72 |
if ( $is_pro_active === $current_pro_status ) { |
| 73 |
return; |
| 74 |
} |
| 75 |
update_option( 'wps_team_is_pro_active', $current_pro_status ); |
| 76 |
plugin()->assets->assets_purge_all(); |
| 77 |
} |
| 78 |
|
| 79 |
public function initialize() { |
| 80 |
require_once WPS_TEAM_INC_PATH . 'autoloader.php'; |
| 81 |
require_once WPS_TEAM_INC_PATH . 'thumbly.php'; |
| 82 |
Autoloader::run(); |
| 83 |
Plugin::instance(); |
| 84 |
$this->maybe_update_pro_status(); |
| 85 |
$this->maybe_update_version(); |
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
new Initialize(); |
| 91 |
function plugin() { |
| 92 |
return Plugin::instance(); |
| 93 |
} |
| 94 |
|