define_constants(); register_activation_hook( __FILE__, array( $this, 'activate' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); } /** * Initializes the Base_Plugin() class * * Checks for an existing Base_Plugin() instance * and if it doesn't find one, creates it. */ public static function init() { static $instance = false; if ( ! $instance ) { $instance = new Video_Content(); } return $instance; } /** * Magic getter to bypass referencing plugin. * * @param $prop * * @return mixed */ public function __get( $prop ) { if ( array_key_exists( $prop, $this->container ) ) { return $this->container[ $prop ]; } return $this->{$prop}; } /** * Magic isset to bypass referencing plugin. * * @param $prop * * @return mixed */ public function __isset( $prop ) { return isset( $this->{$prop} ) || isset( $this->container[ $prop ] ); } /** * Define the constants * * @return void */ public function define_constants() { define( 'P123ON_VERSION', $this->version ); define( 'P123ON_FILE', __FILE__ ); define( 'P123ON_PATH', dirname( P123ON_FILE ) ); define( 'P123ON_INCLUDES', P123ON_PATH . '/includes' ); define( 'P123ON_URL', plugins_url( '', P123ON_FILE ) ); define( 'P123ON_ASSETS', P123ON_URL . '/assets' ); } /** * Load the plugin after all plugis are loaded * * @return void */ public function init_plugin() { $this->includes(); $this->init_hooks(); } /** * Placeholder for activation function * * Nothing being called here yet. */ public function activate() { $installed = get_option( 'P123ON_installed' ); if ( ! $installed ) { update_option( 'P123ON_installed', time() ); } update_option( 'P123ON_version', P123ON_VERSION ); } /** * Placeholder for deactivation function * * Nothing being called here yet. */ public function deactivate() { } /** * Include the required files * * @return void */ public function includes() { require_once P123ON_INCLUDES . '/Assets.php'; if ( $this->is_request( 'admin' ) ) { require_once P123ON_INCLUDES . '/Admin.php'; } if ( $this->is_request( 'frontend' ) ) { require_once P123ON_INCLUDES . '/Frontend.php'; } if ( $this->is_request( 'ajax' ) ) { // require_once P123ON_INCLUDES . '/class-ajax.php'; } require_once P123ON_INCLUDES . '/Api.php'; } /** * Initialize the hooks * * @return void */ public function init_hooks() { add_action( 'init', array( $this, 'init_classes' ) ); // Localize our plugin add_action( 'init', array( $this, 'localization_setup' ) ); } /** * Instantiate the required classes * * @return void */ public function init_classes() { if ( $this->is_request( 'admin' ) ) { $this->container['admin'] = new p123on\Admin(); } if ( $this->is_request( 'frontend' ) ) { $this->container['frontend'] = new p123on\Frontend(); } if ( $this->is_request( 'ajax' ) ) { // $this->container['ajax'] = new p123on\Ajax(); } $this->container['api'] = new p123on\Api(); $this->container['assets'] = new p123on\Assets(); } /** * Initialize plugin for localization * * @uses load_plugin_textdomain() */ public function localization_setup() { load_plugin_textdomain( 'P123ON', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * What type of request is this? * * @param string $type admin, ajax, cron or frontend. * * @return bool */ private function is_request( $type ) { switch ( $type ) { case 'admin' : return is_admin(); case 'ajax' : return defined( 'DOING_AJAX' ); case 'rest' : return defined( 'REST_REQUEST' ); case 'cron' : return defined( 'DOING_CRON' ); case 'frontend' : return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); } } } // Base_Plugin // Register Custom Post Type $P123ON = Video_Content::init();