i18n = new I18n(); $this->settings = new Settings(); $this->content = new Content(); $this->switcher = new Switcher(); $this->seo = new SEO(); ( new Elementor() )->hooks(); ( new Assignments() )->hooks(); ( new Menu_Switcher() )->hooks(); ( new Router() )->hooks(); add_action( 'admin_init', [ $this, 'maybe_flush_rewrites' ] ); // Translations hosted on WordPress.org are loaded automatically. register_activation_hook( ABDIEL_AMM_FILE, [ __CLASS__, 'activate' ] ); register_deactivation_hook( ABDIEL_AMM_FILE, [ __CLASS__, 'deactivate' ] ); $this->settings->hooks(); $this->content->hooks(); $this->switcher->hooks(); $this->seo->hooks(); add_filter( 'body_class', [ $this, 'body_class' ] ); } public static function activate() { // Seed default languages on first activation (English + Spanish). // Users can edit/delete/add languages as needed. $langs = get_option( 'abdiel_amm_languages', false ); $needs_seed = ( false === $langs ) || ( is_array( $langs ) && empty( $langs['items'] ) ); if ( $needs_seed ) { $locale = function_exists( 'determine_locale' ) ? determine_locale() : get_locale(); $locale = is_string( $locale ) ? strtolower( $locale ) : ''; $default_code = ''; if ( strpos( $locale, 'es' ) === 0 ) { $default_code = 'es'; } elseif ( strpos( $locale, 'en' ) === 0 ) { $default_code = 'en'; } $seed = [ 'default' => $default_code, 'items' => [ 'en' => [ 'name' => 'English', 'active' => 1, 'order' => 1, 'icon' => 0, ], 'es' => [ 'name' => 'EspaƱol', 'active' => 1, 'order' => 2, 'icon' => 0, ], ], ]; if ( false === $langs ) { add_option( 'abdiel_amm_languages', $seed ); } else { update_option( 'abdiel_amm_languages', $seed ); } } if ( false === get_option( 'abdiel_amm_settings', false ) ) { $settings = [ 'enabled_post_types' => [ 'page', 'post' ], 'switcher_mode' => 'shortcode', // shortcode|menu|floating 'switcher_show_name' => 1, 'switcher_show_icon' => 0, 'switcher_show_code' => 0, 'floating_position' => 'br', // tl|tr|bl|br 'delete_data_on_uninstall' => 0, 'url_mode' => 'prefix', ]; add_option( 'abdiel_amm_settings', $settings ); } } public static function deactivate() { // Intentionally empty. Keep data by default. } public function body_class( $classes ) { $lang = $this->content->get_current_language_code(); if ( $lang ) { $classes[] = 'abdiel-amm-lang-' . sanitize_html_class( $lang ); } return $classes; } public function maybe_flush_rewrites() { if ( ! current_user_can( 'manage_options' ) ) { return; } if ( get_transient( 'abdiel_amm_flush_rewrites' ) ) { delete_transient( 'abdiel_amm_flush_rewrites' ); flush_rewrite_rules(); } } }