settings = new AooShop_Settings(); $this->api = new AooShop_Api_Client( $this->settings ); $this->cache = new AooShop_Cache( $this->settings, $this->api ); $this->template = new AooShop_Template_Page(); $this->templates = new AooShop_Templates( $this->template ); $this->router = new AooShop_Router( $this->settings, $this->template ); $this->renderer = new AooShop_Renderer( $this->settings, $this->cache, $this->router, $this->template ); $this->seo = new AooShop_Seo( $this->settings, $this->renderer ); $this->sitemap = new AooShop_Sitemap( $this->settings, $this->api, $this->router, $this->template ); $this->llms = new AooShop_Llms( $this->settings, $this->api, $this->renderer, $this->template ); $this->seo_check = new AooShop_Seo_Check( $this->settings, $this->router, $this->sitemap, $this->seo ); $this->assets = new AooShop_Assets( $this->settings, $this->renderer ); $this->cards = new AooShop_Cards( $this->settings, $this->api, $this->cache, $this->renderer, $this->assets ); $this->data_api = new AooShop_Data_Api( $this->settings, $this->cache, $this->renderer ); $this->browse = new AooShop_Browse( $this->settings, $this->data_api, $this->router, $this->cards ); $this->health = new AooShop_Health( $this->settings, $this->router, $this->data_api ); $this->shortcodes = new AooShop_Shortcodes( $this->cards, $this->assets, $this->browse ); $this->rest = new AooShop_Rest( $this->settings, $this->cache ); $this->cart = new AooShop_Cart( $this->settings, $this->api, $this->router, $this->renderer ); $this->redirects = new AooShop_Redirects( $this->settings, $this->api, $this->router ); $this->woo_import = new AooShop_Woo_Import( $this->redirects ); $this->host_cache = new AooShop_Host_Cache( $this->settings, $this->router ); $this->purge = new AooShop_Purge( $this->settings, $this->api, $this->cache, $this->router, $this->sitemap, $this->host_cache ); $this->roles = new AooShop_Roles( $this->settings ); $this->template->hooks(); $this->router->hooks(); $this->renderer->hooks(); $this->seo->hooks(); $this->sitemap->hooks(); $this->llms->hooks(); $this->seo_check->hooks(); $this->assets->hooks(); $this->cards->hooks(); $this->data_api->hooks(); $this->shortcodes->hooks(); $this->rest->hooks(); $this->cart->hooks(); $this->cache->hooks(); $this->redirects->hooks(); $this->woo_import->hooks(); $this->host_cache->hooks(); $this->purge->hooks(); $this->roles->hooks(); $this->health->hooks(); // Menu / content converters work outside wp-admin too (WP-CLI `wp aoo-shop menu-convert` · `content-convert`) — their // own hooks are admin-post only. $this->menu_convert = new AooShop_Menu_Convert( $this->settings, $this->redirects, $this->router ); $this->menu_convert->hooks(); $this->content_convert = new AooShop_Content_Convert( $this->settings, $this->redirects, $this->router ); $this->content_convert->hooks(); if ( defined( 'WP_CLI' ) && WP_CLI ) { AooShop_Cli::register(); } if ( is_admin() ) { $this->admin = new AooShop_Admin( $this->settings, $this->api, $this->cache, $this->router, $this->template, $this->seo, $this->sitemap ); $this->admin->hooks(); $this->admin_redirects = new AooShop_Admin_Redirects( $this->settings, $this->redirects, $this->router ); $this->admin_redirects->hooks(); $this->admin_storefront = new AooShop_Admin_Storefront( $this->templates, $this->template, $this->router ); $this->admin_storefront->hooks(); $this->woo_collections = new AooShop_Woo_Collections( $this->settings, $this->api, $this->redirects, $this->data_api ); $this->woo_collections->hooks(); } add_action( 'init', array( $this, 'load_textdomain' ) ); } /** * Admin screens follow the user's language (bundled Thai in languages/, or translate.wordpress.org). * * Storefront text (cart drawer, checkout hand-off, widgets) sits next to AooCommerce's shop HTML, which is * always Thai — so on the front end the bundled Thai translation is loaded whatever the site language is. * Filter `aooshop_frontend_locale`: return '' to follow the site language instead, or another locale whose * `aoo-shop-.mo` exists in languages/. */ public function load_textdomain() { // translate.wordpress.org packs (WP_LANG_DIR/plugins) load just-in-time — only fall back to the bundled copy. $user_locale = determine_locale(); $pack = WP_LANG_DIR . '/plugins/aoo-shop-' . $user_locale; if ( ! is_readable( $pack . '.mo' ) && ! is_readable( $pack . '.l10n.php' ) ) { $bundled = AOOSHOP_DIR . 'languages/aoo-shop-' . sanitize_file_name( $user_locale ) . '.mo'; if ( is_readable( $bundled ) ) { load_textdomain( 'aoo-shop', $bundled, $user_locale ); } } if ( is_admin() && ! wp_doing_ajax() ) { return; } $locale = (string) apply_filters( 'aooshop_frontend_locale', 'th' ); if ( '' === $locale || determine_locale() === $locale ) { return; } $mofile = AOOSHOP_DIR . 'languages/aoo-shop-' . sanitize_file_name( $locale ) . '.mo'; if ( is_readable( $mofile ) ) { unload_textdomain( 'aoo-shop' ); // Loaded as the current locale so lookups find it (WordPress 6.5+ keeps translations per locale). load_textdomain( 'aoo-shop', $mofile, determine_locale() ); } } public static function activate() { $plugin = self::instance(); $plugin->template->ensure(); AooShop_Redirects::install(); AooShop_Roles::install(); // Rules are (re)registered and flushed on the next `init` — see AooShop_Router::maybe_flush(). $plugin->router->request_flush(); } public static function deactivate() { $plugin = self::instance(); $plugin->router->remove_rules_and_flush(); // Hide the template page while inactive (no shortcode handler → raw "[aooshop_content]"). // activate() → ensure() publishes it again. $tpl = (int) get_option( AooShop_Template_Page::OPTION, 0 ); if ( $tpl && 'publish' === get_post_status( $tpl ) ) { wp_update_post( array( 'ID' => $tpl, 'post_status' => 'draft' ) ); } wp_clear_scheduled_hook( AooShop_Cache::REFRESH_HOOK ); wp_clear_scheduled_hook( AooShop_Purge::CRON_HOOK ); wp_clear_scheduled_hook( AooShop_Purge::STALE_HOOK ); wp_unschedule_hook( AooShop_Assets::CSS_CACHE_HOOK ); // Data (redirects, settings, cache) stays — only uninstall removes it. } } /** Shortcut for other components / theme code. */ function aooshop() { return AooShop_Plugin::instance(); }