register( eucheck_fs() ); add_action( 'before_woocommerce_init', array( Compat::class, 'declare_compatibility' ) ); add_action( 'plugins_loaded', array( $this, 'init' ), 20 ); add_filter( 'lang_dir_for_domain', array( $this, 'translations_dir' ), 10, 3 ); add_action( 'init', array( $this, 'load_translations_before_6_6' ), 0 ); } /** * Lets WordPress load the bundled translations just in time when no * language pack from translate.wordpress.org is installed. Packs in * wp-content/languages are found first, so they always win. * * @param string|false $path Directory WordPress found, or false. * @param string $domain Text domain. * @param string $locale Locale. * @return string|false */ public function translations_dir( $path, $domain, $locale ) { if ( 'eu-check' !== $domain || $path ) { return $path; } $dir = EUCHECK_DIR . 'languages/'; if ( is_readable( $dir . 'eu-check-' . $locale . '.l10n.php' ) || is_readable( $dir . 'eu-check-' . $locale . '.mo' ) ) { return $dir; } return $path; } /** * WordPress before 6.6 has no lang_dir_for_domain filter, so the bundled * translation is loaded here, unless a language pack is installed. */ public function load_translations_before_6_6() { if ( version_compare( (string) get_bloginfo( 'version' ), '6.6', '>=' ) ) { return; } $locale = determine_locale(); if ( is_readable( WP_LANG_DIR . '/plugins/eu-check-' . $locale . '.mo' ) ) { return; } $file = EUCHECK_DIR . 'languages/eu-check-' . $locale . '.mo'; if ( is_readable( $file ) ) { load_textdomain( 'eu-check', $file, $locale ); } } /** * Starts the plugin once WooCommerce is loaded. */ public function init() { if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'admin_notices', array( $this, 'missing_woocommerce_notice' ) ); return; } add_action( 'init', array( Install::class, 'maybe_upgrade' ), 5 ); add_action( 'init', array( Install::class, 'maybe_queue_snapshot' ), 20 ); $this->log = new PriceLog(); $this->recorder = new Recorder( $this->log ); $this->recorder->register(); $this->display = new Display( $this->log ); $this->display->register(); ( new Block() )->register(); ( new Sal() )->register(); if ( is_admin() ) { ( new Admin\SettingsPage( $this->log ) )->register(); } } /** * The price log. * * @return PriceLog */ public function log() { if ( null === $this->log ) { $this->log = new PriceLog(); } return $this->log; } /** * The recorder. * * @return Recorder */ public function recorder() { if ( null === $this->recorder ) { $this->recorder = new Recorder( $this->log() ); } return $this->recorder; } /** * The display. * * @return Display */ public function display() { if ( null === $this->display ) { $this->display = new Display( $this->log() ); } return $this->display; } /** * Shown on WordPress versions that do not enforce "Requires Plugins". */ public function missing_woocommerce_notice() { if ( ! current_user_can( 'activate_plugins' ) ) { return; } printf( '
%s