boot(); } return self::$instance; } /** * Boot services and modules. */ private function boot() { if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'admin_notices', array( $this, 'notice_woocommerce_missing' ) ); return; } $this->settings = new Dango_COF_Settings(); Dango_COF_Installer::maybe_upgrade(); Dango_COF_Order_Query::init(); Dango_COF_Forms::init(); Dango_COF_Events::init( $this ); Dango_COF_Stats::init(); Dango_COF_Tax::init(); Dango_COF_Terms::init(); Dango_COF_Privacy::init( $this ); Dango_COF_Rest::init( $this ); Dango_COF_Frontend::init( $this ); Dango_COF_TrackKaro::init( $this ); Dango_COF_Compat::init(); Dango_COF_Elementor::init(); Dango_COF_Cli::init(); $this->register_core_guards(); if ( is_admin() ) { Dango_COF_Admin::init( $this ); Dango_COF_Admin_Orders::init( $this ); Dango_COF_Admin_Products::init( $this ); } $this->boot_modules(); /** * Fires after the plugin and all modules are booted. * * @param Dango_COF_Plugin $plugin Plugin container. */ do_action( 'dango_cof_loaded', $this ); } /** * Free's own guards. Pro adds more through add_guard(). */ private function register_core_guards() { $this->add_guard( new Dango_COF_Guard_Honeypot( $this ) ); $this->add_guard( new Dango_COF_Guard_Time_Trap( $this ) ); $this->add_guard( new Dango_COF_Guard_Blocklist( $this ) ); $this->add_guard( new Dango_COF_Guard_Limits( $this ) ); $this->add_guard( new Dango_COF_Guard_Duplicate( $this ) ); $this->add_guard( new Dango_COF_Guard_Turnstile( $this ) ); } /** * Collect and boot modules. */ private function boot_modules() { $modules = array( new Dango_COF_Module_Pixels(), new Dango_COF_Module_Advance(), ); /** * Modules to boot. Pro appends its modules here. * * @param Dango_COF_Module[] $modules Module instances. * @param Dango_COF_Plugin $plugin Plugin container. */ $modules = (array) apply_filters( 'dango_cof_modules', $modules, $this ); foreach ( $modules as $module ) { if ( ! $module instanceof Dango_COF_Module ) { continue; } try { $module->boot( $this ); $this->modules[ $module->id() ] = $module; } catch ( \Throwable $e ) { Dango_COF_Log::error( 'Module ' . $module->id() . ' failed to boot: ' . $e->getMessage() ); } } } /** * Is a module booted? * * @param string $id Module id. * @return bool */ public function has_module( $id ) { return isset( $this->modules[ $id ] ); } /** * Register a guard. * * @param Dango_COF_Guard $guard Guard. */ public function add_guard( Dango_COF_Guard $guard ) { $this->guards[ $guard->id() ] = $guard; } /** * Guards sorted by priority. * * @return Dango_COF_Guard[] */ public function guards() { $guards = (array) apply_filters( 'dango_cof_guards', $this->guards, $this ); uasort( $guards, static function ( $a, $b ) { return $a->priority() <=> $b->priority(); } ); return $guards; } /** * Register a sink. * * @param Dango_COF_Sink $sink Sink. */ public function add_sink( Dango_COF_Sink $sink ) { $this->sinks[ $sink->id() ] = $sink; } /** * Registered sinks. * * @return Dango_COF_Sink[] */ public function sinks() { return (array) apply_filters( 'dango_cof_sinks', $this->sinks, $this ); } /** * Is the Pro add-on active and licensed? * * @return bool */ public function is_pro() { return (bool) apply_filters( 'dango_cof_is_pro', false ); } /** * Admin notice when WooCommerce is missing. */ public function notice_woocommerce_missing() { if ( ! current_user_can( 'activate_plugins' ) ) { return; } echo '

' . esc_html__( 'Dango COD Order Form needs WooCommerce. Please install and activate WooCommerce.', 'dango-cod-order-form' ) . '

'; } } /** * Shortcut to the plugin container. * * @return Dango_COF_Plugin */ function dango_cof() { return Dango_COF_Plugin::instance(); }