| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The file that defines the core plugin class |
| 5 |
* |
| 6 |
* A class definition that includes attributes and functions used across both the |
| 7 |
* public-facing side of the site and the dashboard. |
| 8 |
* |
| 9 |
* @since 1.2 |
| 10 |
* |
| 11 |
* @package UpdateURLS |
| 12 |
* @subpackage UpdateURLS/includes |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace KaizenCoders\UpdateURLS; |
| 16 |
|
| 17 |
/** |
| 18 |
* The core plugin class. |
| 19 |
* |
| 20 |
* This is used to define internationalization, dashboard-specific hooks, and |
| 21 |
* public-facing site hooks. |
| 22 |
* |
| 23 |
* Also maintains the unique identifier of this plugin as well as the current |
| 24 |
* version of the plugin. |
| 25 |
* |
| 26 |
* @since 1.2 |
| 27 |
* @package UpdateURLS |
| 28 |
* @subpackage UpdateURLS/includes |
| 29 |
* @author KaizenCoders <hello@kaizencoders.com> |
| 30 |
*/ |
| 31 |
class Plugin { |
| 32 |
|
| 33 |
/** |
| 34 |
* Marketing site for this plugin, used as the base for outbound links. |
| 35 |
* |
| 36 |
* @since 1.5.0 |
| 37 |
*/ |
| 38 |
const WEBSITE_URL = 'https://kaizencoders.com/update-urls/'; |
| 39 |
|
| 40 |
/** |
| 41 |
* @var Plugin $instance |
| 42 |
*/ |
| 43 |
static $instance = null; |
| 44 |
|
| 45 |
/** |
| 46 |
* The loader that's responsible for maintaining and registering all hooks that power |
| 47 |
* the plugin. |
| 48 |
* |
| 49 |
* @since 1.2 |
| 50 |
* @access protected |
| 51 |
* @var Loader $loader Maintains and registers all hooks for the plugin. |
| 52 |
*/ |
| 53 |
protected $loader; |
| 54 |
|
| 55 |
/** |
| 56 |
* The unique identifier of this plugin. |
| 57 |
* |
| 58 |
* @since 1.2 |
| 59 |
* @access protected |
| 60 |
* @var string $UpdateURLS The string used to uniquely identify this plugin. |
| 61 |
*/ |
| 62 |
protected $plugin_name = 'update-urls'; |
| 63 |
|
| 64 |
/** |
| 65 |
* The current version of the plugin. |
| 66 |
* |
| 67 |
* @since 1.2 |
| 68 |
* @access protected |
| 69 |
* @var string $version The current version of the plugin. |
| 70 |
*/ |
| 71 |
protected $version = '1.2'; |
| 72 |
|
| 73 |
/** |
| 74 |
* Define the core functionality of the plugin. |
| 75 |
* |
| 76 |
* Create an instance of the loader which will be used to register the hooks |
| 77 |
* with WordPress. |
| 78 |
* |
| 79 |
* @since 1.2 |
| 80 |
*/ |
| 81 |
public function __construct( $version = '' ) { |
| 82 |
$this->version = $version; |
| 83 |
$this->loader = new Loader(); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Define the locale for this plugin for internationalization. |
| 88 |
* |
| 89 |
* Uses the I18n class in order to set the domain and to register the hook |
| 90 |
* with WordPress. |
| 91 |
* |
| 92 |
* @since 1.2 |
| 93 |
* @access private |
| 94 |
*/ |
| 95 |
private function set_locale() { |
| 96 |
$plugin_i18n = new I18n(); |
| 97 |
$plugin_i18n->set_domain( $this->get_plugin_name() ); |
| 98 |
$plugin_i18n->load_plugin_textdomain(); |
| 99 |
} |
| 100 |
|
| 101 |
public function is_pro() { |
| 102 |
if ( defined( 'KC_UU_DEV_MODE' ) && KC_UU_DEV_MODE ) { |
| 103 |
return true; |
| 104 |
} |
| 105 |
|
| 106 |
if ( function_exists( 'kc_uu_fs' ) ) { |
| 107 |
return kc_uu_fs()->can_use_premium_code(); |
| 108 |
} |
| 109 |
|
| 110 |
return false; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Define constant |
| 115 |
* |
| 116 |
* @since 1.0.0 |
| 117 |
*/ |
| 118 |
public function define_constants() { |
| 119 |
|
| 120 |
$upload_dir = wp_upload_dir( null, false ); |
| 121 |
|
| 122 |
if ( ! defined( 'KC_UU_LOG_DIR' ) ) { |
| 123 |
define( 'KC_UU_LOG_DIR', $upload_dir['basedir'] . '/kaizencoders_uploads/update-urls/logs/' ); |
| 124 |
} |
| 125 |
|
| 126 |
if ( ! defined( 'KC_UU_UPLOADS_DIR' ) ) { |
| 127 |
define( 'KC_UU_UPLOADS_DIR', $upload_dir['basedir'] . '/kaizencoders_uploads/update-urls/uploads/' ); |
| 128 |
} |
| 129 |
|
| 130 |
if ( ! defined( 'KC_UU_AJAX_SECURITY' ) ) { |
| 131 |
define( 'KC_UU_AJAX_SECURITY', 'UpdateURLS_ajax_request' ); |
| 132 |
} |
| 133 |
|
| 134 |
if ( ! defined( 'KC_UU_ADMIN_TEMPLATES_DIR' ) ) { |
| 135 |
/* @const KC_UU_ADMIN_TEMPLATES_DIR */ |
| 136 |
define( 'KC_UU_ADMIN_TEMPLATES_DIR', KC_UU_PLUGIN_DIR . 'lite/includes/Admin/Templates' ); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Register all the hooks related to the dashboard functionality |
| 142 |
* of the plugin. |
| 143 |
* |
| 144 |
* @since 1.2 |
| 145 |
* @access private |
| 146 |
*/ |
| 147 |
private function define_admin_hooks() { |
| 148 |
|
| 149 |
$plugin_admin = new Admin( $this ); |
| 150 |
|
| 151 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 152 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 153 |
|
| 154 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_admin_menu' ); |
| 155 |
|
| 156 |
// Utilities. |
| 157 |
$this->loader->add_action( 'admin_print_scripts', $plugin_admin, 'handle_admin_notices' ); |
| 158 |
// The footer is now Admin\Footer's, which empties core's two lines and |
| 159 |
// renders one row in their place. See lite/includes/Admin/Footer.php. |
| 160 |
$this->loader->add_action( 'in_plugin_update_message-update-urls/update-urls.php', $plugin_admin, 'in_plugin_update_message', 10, 2 ); |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Register all the hooks related to the public-facing functionality |
| 165 |
* of the plugin. |
| 166 |
* |
| 167 |
* @since 1.2 |
| 168 |
* @access private |
| 169 |
*/ |
| 170 |
private function define_frontend_hooks() { |
| 171 |
|
| 172 |
$plugin_frontend = new Frontend( $this ); |
| 173 |
|
| 174 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_frontend, 'enqueue_styles' ); |
| 175 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_frontend, 'enqueue_scripts' ); |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Run the loader to execute all the hooks with WordPress. |
| 181 |
* |
| 182 |
* Load the dependencies, define the locale, and set the hooks for the Dashboard and |
| 183 |
* the public-facing side of the site. |
| 184 |
* |
| 185 |
* @since 1.2 |
| 186 |
*/ |
| 187 |
public function run() { |
| 188 |
$this->loader->run(); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* The name of the plugin used to uniquely identify it within the context of |
| 193 |
* WordPress and to define internationalization functionality. |
| 194 |
* |
| 195 |
* @return string The name of the plugin. |
| 196 |
* @since 1.2 |
| 197 |
*/ |
| 198 |
public function get_plugin_name() { |
| 199 |
return $this->plugin_name; |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 204 |
* |
| 205 |
* @return Loader Orchestrates the hooks of the plugin. |
| 206 |
* @since 1.2 |
| 207 |
*/ |
| 208 |
public function get_loader() { |
| 209 |
return $this->loader; |
| 210 |
} |
| 211 |
|
| 212 |
public function get_pricing_url( $billing_cycle = 'annual' ) { |
| 213 |
return admin_url( 'admin.php?page=update-urls-pricing&billing_cycle=' . $billing_cycle ); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Should premium promotions be shown at all? |
| 218 |
* |
| 219 |
* Covers both "already on PRO" and a site that has turned promotions off. |
| 220 |
* |
| 221 |
* @param bool $force_display Bypass the checks, for previewing. |
| 222 |
* |
| 223 |
* @return bool |
| 224 |
* |
| 225 |
* @since 1.5.0 |
| 226 |
*/ |
| 227 |
public function can_show_premium_promotion( $force_display = false ) { |
| 228 |
if ( $force_display ) { |
| 229 |
return true; |
| 230 |
} |
| 231 |
|
| 232 |
if ( $this->is_pro() ) { |
| 233 |
return false; |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* Filter to switch off all premium promotions. |
| 238 |
* |
| 239 |
* @param bool $disable Whether to suppress promotions. |
| 240 |
* |
| 241 |
* @since 1.5.0 |
| 242 |
*/ |
| 243 |
return ! apply_filters( 'kc_uu_disable_promotion', false ); |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Build a link to the marketing site, tagged for attribution. |
| 248 |
* |
| 249 |
* @param string $path Path or fragment appended to the website URL. |
| 250 |
* @param array $utm UTM parameters, see Helper::get_utm_url(). |
| 251 |
* |
| 252 |
* @return string |
| 253 |
* |
| 254 |
* @since 1.5.0 |
| 255 |
*/ |
| 256 |
public function get_website_url( $path = '', $utm = [] ) { |
| 257 |
return Helper::get_utm_url( self::WEBSITE_URL . ltrim( $path, '/' ), $utm ); |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Retrieve the version number of the plugin. |
| 262 |
* |
| 263 |
* @return string The version number of the plugin. |
| 264 |
* @since 1.2 |
| 265 |
*/ |
| 266 |
public function get_version() { |
| 267 |
return $this->version; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Init Classes |
| 272 |
* |
| 273 |
* @since 1.2 |
| 274 |
*/ |
| 275 |
public function init_classes() { |
| 276 |
|
| 277 |
$classes = array( |
| 278 |
'KaizenCoders\UpdateURLS\Install', |
| 279 |
'KaizenCoders\UpdateURLS\Uninstall', |
| 280 |
'KaizenCoders\UpdateURLS\Feedback', |
| 281 |
'KaizenCoders\UpdateURLS\Promo', |
| 282 |
'KaizenCoders\UpdateURLS\Admin\Promotions\PromoBanner', |
| 283 |
'KaizenCoders\UpdateURLS\Admin\Footer', |
| 284 |
'KaizenCoders\UpdateURLS\Ajax', |
| 285 |
'KaizenCoders\UpdateURLS\EmailReports\Init', |
| 286 |
); |
| 287 |
|
| 288 |
if ( $this->is_pro() ) { |
| 289 |
$classes[] = 'KaizenCoders\UpdateURLS\PRO\Pro'; |
| 290 |
} |
| 291 |
|
| 292 |
foreach ( $classes as $class ) { |
| 293 |
$this->loader->add_class( $class ); |
| 294 |
} |
| 295 |
|
| 296 |
} |
| 297 |
|
| 298 |
public static function instance() { |
| 299 |
|
| 300 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Plugin ) ) { |
| 301 |
|
| 302 |
self::$instance = new Plugin( KC_UU_PLUGIN_VERSION ); |
| 303 |
|
| 304 |
self::$instance->define_constants(); |
| 305 |
// self::$instance->load_dependencies(); |
| 306 |
self::$instance->set_locale(); |
| 307 |
self::$instance->define_admin_hooks(); |
| 308 |
self::$instance->define_frontend_hooks(); |
| 309 |
self::$instance->init_classes(); |
| 310 |
|
| 311 |
} |
| 312 |
|
| 313 |
return self::$instance; |
| 314 |
} |
| 315 |
|
| 316 |
} |
| 317 |
|