define_constants(); $this->set_global_settings(); $this->load_dependency(); register_activation_hook( __FILE__, [ $this, 'activate' ] ); register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] ); add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ] ); add_action( 'trueplayer_loaded', [ $this, 'init_plugin' ] ); } public static function init() { static $instance = false; if ( ! $instance ) { $instance = new self(); } return $instance; } public function define_constants() { define( 'TRUEPLAYER_VERSION', '1.7.4' ); define( 'TRUEPLAYER_SETTINGS_NAME', 'trueplayer_settings' ); define( 'TRUEPLAYER_PLUGIN_FILE', __FILE__ ); define( 'TRUEPLAYER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'TRUEPLAYER_PLUGIN_SLUG', 'trueplayer' ); define( 'TRUEPLAYER_DB_PREFIX', 'tp' ); define( 'TRUEPLAYER_PREFIX', TRUEPLAYER_DB_PREFIX ); // Public identifiers that collide with other plugins when they're only 2–3 // characters. The DB-table prefix stays short to keep index-key budgets // usable; registered post types/taxonomies use the full plugin slug. define( 'TRUEPLAYER_VIDEO_POST_TYPE', 'truepl_video' ); define( 'TRUEPLAYER_PRESET_POST_TYPE', 'truepl_preset' ); define( 'TRUEPLAYER_PLUGIN_ROOT_URI', plugins_url( '/', __FILE__ ) ); define( 'TRUEPLAYER_ROOT_DIR_PATH', plugin_dir_path( __FILE__ ) ); define( 'TRUEPLAYER_INCLUDES_DIR_PATH', TRUEPLAYER_ROOT_DIR_PATH . 'includes/' ); define( 'TRUEPLAYER_ASSETS_DIR_PATH', TRUEPLAYER_ROOT_DIR_PATH . 'assets/' ); define( 'TRUEPLAYER_ASSETS_URI', TRUEPLAYER_PLUGIN_ROOT_URI . 'assets/' ); define( 'TRUEPLAYER_ADDONS_SETTINGS', 'trueplayer_addons' ); } /** * When WP has loaded all plugins, trigger the `trueplayer_loaded` hook so * add-ons that registered their loader filter at plugin * construction time are in place before our addon loader runs. */ public function on_plugins_loaded() { do_action( 'trueplayer_loaded' ); } public function init_plugin() { do_action( 'trueplayer_before_init' ); $this->dispatch_hooks(); $this->load_addons(); do_action( 'trueplayer_init' ); } public function dispatch_hooks() { add_action( 'init', [ 'TruePlayer\\Helper', 'maybe_flush_rewrite_rules' ], 999 ); if ( is_admin() ) { TruePlayer\Admin::init(); } TruePlayer\Assets::init(); TruePlayer\Api::init(); TruePlayer\Database::init(); TruePlayer\Shortcode::init(); TruePlayer\Playlist::init(); TruePlayer\Block::init(); TruePlayer\Events::init(); TruePlayer\Integrations::init(); TruePlayer\Migrator::init(); if ( defined( 'WP_CLI' ) && WP_CLI ) { \WP_CLI::add_command( 'trueplayer', 'TruePlayer\\CLI' ); } } public function load_addons() { TruePlayer\Addons::init(); } public function set_global_settings() { $GLOBALS['trueplayer_settings'] = json_decode( get_option( TRUEPLAYER_SETTINGS_NAME, '{}' ) ); $GLOBALS['trueplayer_addons'] = json_decode( get_option( TRUEPLAYER_ADDONS_SETTINGS, '{}' ) ); } public function load_dependency() { if ( file_exists( TRUEPLAYER_ROOT_DIR_PATH . 'vendor/autoload.php' ) ) { require_once TRUEPLAYER_ROOT_DIR_PATH . 'vendor/autoload.php'; } require_once TRUEPLAYER_INCLUDES_DIR_PATH . 'autoload.php'; require_once TRUEPLAYER_INCLUDES_DIR_PATH . 'functions.php'; // StoreEngine license SDK (bundled, not composer-autoloaded). Its init.php // registers a plugins_loaded:0 version loader that defines se_license_init() // and the SE_License_SDK_* classes. Guarded so multiple Kodezen plugins // bundling the SDK don't double-register. $sdk_init = TRUEPLAYER_ROOT_DIR_PATH . 'vendor/storeengine/wordpress-sdk/init.php'; if ( ! function_exists( 'se_license_init' ) && file_exists( $sdk_init ) ) { require_once $sdk_init; } // Configure the SDK (free product 430 — insights only). TruePlayer\StoreLicense::init(); } public function activate() { TruePlayer\Installer::init(); } public function deactivate() { // Nothing to unschedule yet. } } /** * Initializes the main plugin. * * @return \TruePlayer */ function trueplayer_start() { return TruePlayer::init(); } // Plugin Start. trueplayer_start();