classes
2 years ago
css
1 year ago
images
3 years ago
js
1 year ago
modules
1 year ago
bootstrap.php
1 year ago
commands.php
2 years ago
factory.php
3 years ago
host.php
1 year ago
listener.php
1 year ago
translations-central.php
2 years ago
updraftplus.php
1 year ago
wp-optimize.php
1 year ago
wp-optimize.php
157 lines
| 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 | add_action('updraftplus_load_translations_for_udcentral', array($this, 'load_updraftplus_translations')); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Whether the current user can perform key control AJAX actions |
| 45 | * |
| 46 | * @return Boolean |
| 47 | */ |
| 48 | public function current_user_can_ajax() { |
| 49 | return current_user_can(WP_Optimize()->capability_required()); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Loads the UpdraftCentral_Main instance |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | public function load_updraftcentral() { |
| 58 | $central_path = $this->is_host_dir_set() ? trailingslashit(WPO_PLUGIN_MAIN_PATH) : ''; |
| 59 | |
| 60 | if (!empty($central_path) && file_exists($central_path.'central/bootstrap.php')) { |
| 61 | include_once($central_path.'central/bootstrap.php'); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Checks whether the plugin's DIR constant is currently define or not |
| 67 | * |
| 68 | * @return bool |
| 69 | */ |
| 70 | public function is_host_dir_set() { |
| 71 | return defined('WPO_PLUGIN_MAIN_PATH') ? true : false; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Get the host plugin's dir path |
| 76 | * |
| 77 | * @return string |
| 78 | */ |
| 79 | public function get_host_dir() { |
| 80 | return defined('WPO_PLUGIN_MAIN_PATH') ? WPO_PLUGIN_MAIN_PATH : dirname(dirname(__FILE__)); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns the current version of the host plugin |
| 85 | * |
| 86 | * @return string|bool |
| 87 | */ |
| 88 | public function get_version() { |
| 89 | return defined('WPO_VERSION') ? WPO_VERSION : false; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns the instance of the host plugin |
| 94 | * |
| 95 | * @return object|bool |
| 96 | */ |
| 97 | public function get_instance() { |
| 98 | global $wp_optimize; |
| 99 | |
| 100 | if ($wp_optimize) { |
| 101 | return $wp_optimize; |
| 102 | } |
| 103 | |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Checks whether debug mod is set |
| 109 | * |
| 110 | * @return bool |
| 111 | */ |
| 112 | public function get_debug_mode() { |
| 113 | return (defined('WP_OPTIMIZE_DEBUG_OPTIMIZATIONS') && WP_OPTIMIZE_DEBUG_OPTIMIZATIONS); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Logs the given line |
| 118 | * |
| 119 | * @param string $line The log line |
| 120 | * @param string $level The log level: notice, warning, error, etc. |
| 121 | * @param boolean|string $uniq_id Each of these will only be logged once |
| 122 | * |
| 123 | * @return void |
| 124 | */ |
| 125 | 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. |
| 126 | global $wp_optimize; |
| 127 | |
| 128 | if ($wp_optimize) { |
| 129 | if (is_callable(array($wp_optimize, 'log'))) { |
| 130 | call_user_func(array($wp_optimize, 'log'), $line); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Load translations which are based on UpdraftPlus domain text |
| 137 | */ |
| 138 | public function load_updraftplus_translations() { |
| 139 | // Load wp-optimize translations |
| 140 | if (defined('UPDRAFTCENTRAL_CLIENT_DIR') && file_exists(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php')) { |
| 141 | $this->translations = include(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php'); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Developer Note: |
| 147 | * |
| 148 | * You can add your class methods below if ever you want to extend or modify |
| 149 | * the module handlers of UpdraftCentral located at central/modules. Just be |
| 150 | * sure to use this class to abstract any functionality that would link to the |
| 151 | * wp-optimize plugin. |
| 152 | * |
| 153 | * N.B. All custom methods added here will then be available from the global |
| 154 | * variable $updraftcentral_host_plugin (e.g. $updraftcentral_host_plugin->YOUR_METHOD) |
| 155 | */ |
| 156 | } |
| 157 |