| 1 |
<?php |
| 2 |
|
| 3 |
if (class_exists('WP_Optimize_Host')) return; |
| 4 |
|
| 5 |
if (!defined('UPDRAFTCENTRAL_CLIENT_DIR')) define('UPDRAFTCENTRAL_CLIENT_DIR', dirname(__FILE__)); |
| 6 |
if (!defined('UPDRAFTCENTRAL_CLIENT_URL')) define('UPDRAFTCENTRAL_CLIENT_URL', plugins_url('', __FILE__)); |
| 7 |
if (!class_exists('UpdraftCentral_Host')) { |
| 8 |
include_once(UPDRAFTCENTRAL_CLIENT_DIR.'/host.php'); |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* This class is the basic bridge between UpdraftCentral and WP_Optimize. |
| 13 |
*/ |
| 14 |
class WP_Optimize_Host extends UpdraftCentral_Host { |
| 15 |
|
| 16 |
public $plugin_name = 'wp-optimize'; |
| 17 |
|
| 18 |
public $translations = array(); |
| 19 |
|
| 20 |
protected static $_instance = null; |
| 21 |
|
| 22 |
/** |
| 23 |
* Creates an instance of this class. Singleton Pattern |
| 24 |
* |
| 25 |
* @return object Instance of this class |
| 26 |
*/ |
| 27 |
public static function instance() { |
| 28 |
if (empty(self::$_instance)) { |
| 29 |
self::$_instance = new self(); |
| 30 |
} |
| 31 |
|
| 32 |
return self::$_instance; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Class constructor |
| 37 |
*/ |
| 38 |
public function __construct() { |
| 39 |
parent::__construct(); |
| 40 |
|
| 41 |
// Load wp-optimize translations |
| 42 |
if (defined('UPDRAFTCENTRAL_CLIENT_DIR') && file_exists(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php')) { |
| 43 |
$this->translations = include_once(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php'); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Whether the current user can perform key control AJAX actions |
| 49 |
* |
| 50 |
* @return Boolean |
| 51 |
*/ |
| 52 |
public function current_user_can_ajax() { |
| 53 |
return current_user_can(WP_Optimize()->capability_required()); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Loads the UpdraftCentral_Main instance |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public function load_updraftcentral() { |
| 62 |
$central_path = $this->is_host_dir_set() ? trailingslashit(WPO_PLUGIN_MAIN_PATH) : ''; |
| 63 |
|
| 64 |
if (!empty($central_path) && file_exists($central_path.'central/bootstrap.php')) { |
| 65 |
include_once($central_path.'central/bootstrap.php'); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Checks whether the plugin's DIR constant is currently define or not |
| 71 |
* |
| 72 |
* @return bool |
| 73 |
*/ |
| 74 |
public function is_host_dir_set() { |
| 75 |
return defined('WPO_PLUGIN_MAIN_PATH') ? true : false; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Get the host plugin's dir path |
| 80 |
* |
| 81 |
* @return string |
| 82 |
*/ |
| 83 |
public function get_host_dir() { |
| 84 |
return defined('WPO_PLUGIN_MAIN_PATH') ? WPO_PLUGIN_MAIN_PATH : dirname(dirname(__FILE__)); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Returns the current version of the host plugin |
| 89 |
* |
| 90 |
* @return string|bool |
| 91 |
*/ |
| 92 |
public function get_version() { |
| 93 |
return defined('WPO_VERSION') ? WPO_VERSION : false; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Returns the instance of the host plugin |
| 98 |
* |
| 99 |
* @return object|bool |
| 100 |
*/ |
| 101 |
public function get_instance() { |
| 102 |
global $wp_optimize; |
| 103 |
|
| 104 |
if ($wp_optimize) { |
| 105 |
return $wp_optimize; |
| 106 |
} |
| 107 |
|
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Checks whether debug mod is set |
| 113 |
* |
| 114 |
* @return bool |
| 115 |
*/ |
| 116 |
public function get_debug_mode() { |
| 117 |
return (defined('WP_OPTIMIZE_DEBUG_OPTIMIZATIONS') && WP_OPTIMIZE_DEBUG_OPTIMIZATIONS); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Logs the given line |
| 122 |
* |
| 123 |
* @param string $line The log line |
| 124 |
* @param string $level The log level: notice, warning, error, etc. |
| 125 |
* @param boolean|string $uniq_id Each of these will only be logged once |
| 126 |
* |
| 127 |
* @return void |
| 128 |
*/ |
| 129 |
public function log($line, $level = 'notice', $uniq_id = false) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused parameter is present because the the abstract UpdraftCentral_Host class uses 3 arguments. |
| 130 |
global $wp_optimize; |
| 131 |
|
| 132 |
if ($wp_optimize) { |
| 133 |
if (is_callable(array($wp_optimize, 'log'))) { |
| 134 |
call_user_func(array($wp_optimize, 'log'), $line); |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Developer Note: |
| 141 |
* |
| 142 |
* You can add your class methods below if ever you want to extend or modify |
| 143 |
* the module handlers of UpdraftCentral located at central/modules. Just be |
| 144 |
* sure to use this class to abstract any functionality that would link to the |
| 145 |
* wp-optimize plugin. |
| 146 |
* |
| 147 |
* N.B. All custom methods added here will then be available from the global |
| 148 |
* variable $updraftcentral_host_plugin (e.g. $updraftcentral_host_plugin->YOUR_METHOD) |
| 149 |
*/ |
| 150 |
} |
| 151 |
|