*/ class Plugin { /** * Marketing site for this plugin, used as the base for outbound links. * * @since 1.5.0 */ const WEBSITE_URL = 'https://kaizencoders.com/update-urls/'; /** * @var Plugin $instance */ static $instance = null; /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. * * @since 1.2 * @access protected * @var Loader $loader Maintains and registers all hooks for the plugin. */ protected $loader; /** * The unique identifier of this plugin. * * @since 1.2 * @access protected * @var string $UpdateURLS The string used to uniquely identify this plugin. */ protected $plugin_name = 'update-urls'; /** * The current version of the plugin. * * @since 1.2 * @access protected * @var string $version The current version of the plugin. */ protected $version = '1.2'; /** * Define the core functionality of the plugin. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.2 */ public function __construct( $version = '' ) { $this->version = $version; $this->loader = new Loader(); } /** * Define the locale for this plugin for internationalization. * * Uses the I18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.2 * @access private */ private function set_locale() { $plugin_i18n = new I18n(); $plugin_i18n->set_domain( $this->get_plugin_name() ); $plugin_i18n->load_plugin_textdomain(); } public function is_pro() { if ( defined( 'KC_UU_DEV_MODE' ) && KC_UU_DEV_MODE ) { return true; } if ( function_exists( 'kc_uu_fs' ) ) { return kc_uu_fs()->can_use_premium_code(); } return false; } /** * Define constant * * @since 1.0.0 */ public function define_constants() { $upload_dir = wp_upload_dir( null, false ); if ( ! defined( 'KC_UU_LOG_DIR' ) ) { define( 'KC_UU_LOG_DIR', $upload_dir['basedir'] . '/kaizencoders_uploads/update-urls/logs/' ); } if ( ! defined( 'KC_UU_UPLOADS_DIR' ) ) { define( 'KC_UU_UPLOADS_DIR', $upload_dir['basedir'] . '/kaizencoders_uploads/update-urls/uploads/' ); } if ( ! defined( 'KC_UU_AJAX_SECURITY' ) ) { define( 'KC_UU_AJAX_SECURITY', 'UpdateURLS_ajax_request' ); } if ( ! defined( 'KC_UU_ADMIN_TEMPLATES_DIR' ) ) { /* @const KC_UU_ADMIN_TEMPLATES_DIR */ define( 'KC_UU_ADMIN_TEMPLATES_DIR', KC_UU_PLUGIN_DIR . 'lite/includes/Admin/Templates' ); } } /** * Register all the hooks related to the dashboard functionality * of the plugin. * * @since 1.2 * @access private */ private function define_admin_hooks() { $plugin_admin = new Admin( $this ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_admin_menu' ); // Utilities. $this->loader->add_action( 'admin_print_scripts', $plugin_admin, 'handle_admin_notices' ); // The footer is now Admin\Footer's, which empties core's two lines and // renders one row in their place. See lite/includes/Admin/Footer.php. $this->loader->add_action( 'in_plugin_update_message-update-urls/update-urls.php', $plugin_admin, 'in_plugin_update_message', 10, 2 ); } /** * Register all the hooks related to the public-facing functionality * of the plugin. * * @since 1.2 * @access private */ private function define_frontend_hooks() { $plugin_frontend = new Frontend( $this ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_frontend, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_frontend, 'enqueue_scripts' ); } /** * Run the loader to execute all the hooks with WordPress. * * Load the dependencies, define the locale, and set the hooks for the Dashboard and * the public-facing side of the site. * * @since 1.2 */ public function run() { $this->loader->run(); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @return string The name of the plugin. * @since 1.2 */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @return Loader Orchestrates the hooks of the plugin. * @since 1.2 */ public function get_loader() { return $this->loader; } public function get_pricing_url( $billing_cycle = 'annual' ) { return admin_url( 'admin.php?page=update-urls-pricing&billing_cycle=' . $billing_cycle ); } /** * Should premium promotions be shown at all? * * Covers both "already on PRO" and a site that has turned promotions off. * * @param bool $force_display Bypass the checks, for previewing. * * @return bool * * @since 1.5.0 */ public function can_show_premium_promotion( $force_display = false ) { if ( $force_display ) { return true; } if ( $this->is_pro() ) { return false; } /** * Filter to switch off all premium promotions. * * @param bool $disable Whether to suppress promotions. * * @since 1.5.0 */ return ! apply_filters( 'kc_uu_disable_promotion', false ); } /** * Build a link to the marketing site, tagged for attribution. * * @param string $path Path or fragment appended to the website URL. * @param array $utm UTM parameters, see Helper::get_utm_url(). * * @return string * * @since 1.5.0 */ public function get_website_url( $path = '', $utm = [] ) { return Helper::get_utm_url( self::WEBSITE_URL . ltrim( $path, '/' ), $utm ); } /** * Retrieve the version number of the plugin. * * @return string The version number of the plugin. * @since 1.2 */ public function get_version() { return $this->version; } /** * Init Classes * * @since 1.2 */ public function init_classes() { $classes = array( 'KaizenCoders\UpdateURLS\Install', 'KaizenCoders\UpdateURLS\Uninstall', 'KaizenCoders\UpdateURLS\Feedback', 'KaizenCoders\UpdateURLS\Promo', 'KaizenCoders\UpdateURLS\Admin\Promotions\PromoBanner', 'KaizenCoders\UpdateURLS\Admin\Footer', 'KaizenCoders\UpdateURLS\Ajax', 'KaizenCoders\UpdateURLS\EmailReports\Init', ); if ( $this->is_pro() ) { $classes[] = 'KaizenCoders\UpdateURLS\PRO\Pro'; } foreach ( $classes as $class ) { $this->loader->add_class( $class ); } } public static function instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Plugin ) ) { self::$instance = new Plugin( KC_UU_PLUGIN_VERSION ); self::$instance->define_constants(); // self::$instance->load_dependencies(); self::$instance->set_locale(); self::$instance->define_admin_hooks(); self::$instance->define_frontend_hooks(); self::$instance->init_classes(); } return self::$instance; } }