Language code => brand text. */ /** * File name of a front-end asset: the minified build (name.min.js / name.min.css, created by * the release workflow) unless SCRIPT_DEBUG is on or no build exists (development checkout). * * @param string $file File name in public/js or public/css, e.g. 'welcoma-widget.js'. * @param string $base Plugin directory that contains public/ (defaults to this plugin). * @return string */ function welcoma_widget_asset( $file, $base = '' ) { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { return $file; } $base = $base ? $base : plugin_dir_path( __FILE__ ); $dir = '.css' === substr( $file, -4 ) ? 'public/css/' : 'public/js/'; $min = preg_replace( '/\.(js|css)$/', '.min.$1', $file ); return is_readable( trailingslashit( $base ) . $dir . $min ) ? $min : $file; } function welcoma_widget_footer_brand_defaults() { return array( 'en' => 'Web Accessibility by Welcoma', 'de' => 'Web-Barrierefreiheit von Welcoma', 'es' => 'Accesibilidad web por Welcoma', 'fr' => 'Accessibilité Web par Welcoma', 'it' => 'Accessibilità web di Welcoma', 'pt' => 'Acessibilidade Web por Welcoma', 'pt-br' => 'Acessibilidade Web por Welcoma', 'nl' => 'Webtoegankelijkheid door Welcoma', 'pl' => 'Dostępność internetowa od Welcoma', 'cs' => 'Webová přístupnost od Welcoma', 'hu' => 'Webes akadálymentesítés: Welcoma', 'ro' => 'Accesibilitate web de la Welcoma', 'tr' => 'Welcoma ile Web Erişilebilirliği', 'ru' => 'Веб-доступность от Welcoma', 'uk' => 'Веб-доступність від Welcoma', 'ar' => 'إمكانية الوصول إلى الويب بواسطة Welcoma', 'he' => 'נגישות אינטרנט מבית Welcoma', 'hi' => 'Welcoma द्वारा वेब एक्सेसिबिलिटी', 'id' => 'Aksesibilitas Web oleh Welcoma', 'th' => 'การเข้าถึงเว็บโดย Welcoma', 'vi' => 'Khả năng truy cập web bởi Welcoma', 'ja' => 'Welcoma によるウェブアクセシビリティ', 'ko' => 'Welcoma의 웹 접근성', 'zh-CN' => 'Welcoma 提供的网页无障碍服务', 'sv' => 'Webbtillgänglighet av Welcoma', 'fi' => 'Web-saavutettavuus: Welcoma', ); } /** * Add or update the footer brand option so it always matches the bundled * strings. Runs on activation and on every load (cheap no-op when unchanged), * which also covers plugin updates. */ function welcoma_widget_sync_footer_brand() { $texts = welcoma_widget_footer_brand_defaults(); if ( false === get_option( WELCOMA_WIDGET_FOOTER_BRAND_OPTION ) ) { add_option( WELCOMA_WIDGET_FOOTER_BRAND_OPTION, $texts ); } elseif ( get_option( WELCOMA_WIDGET_FOOTER_BRAND_OPTION ) !== $texts ) { update_option( WELCOMA_WIDGET_FOOTER_BRAND_OPTION, $texts ); } } add_action( 'plugins_loaded', 'welcoma_widget_sync_footer_brand' ); /** * Runs on activation: seed default settings. */ function welcoma_widget_activate() { welcoma_widget_sync_footer_brand(); $is_first_install = false; if ( false === get_option( WELCOMA_WIDGET_OPTION ) ) { $settings = Welcoma_Settings::default_settings(); // Detect WordPress site language and apply to widget default. $settings['default_language'] = welcoma_widget_locale_to_lang( determine_locale() ); add_option( WELCOMA_WIDGET_OPTION, $settings ); $is_first_install = true; } if ( false === get_option( WELCOMA_WIDGET_STATEMENT_OPTION ) ) { add_option( WELCOMA_WIDGET_STATEMENT_OPTION, array( 'company_name' => '', 'email' => '', 'website_url' => '', 'content' => '', ) ); } if ( $is_first_install ) { welcoma_widget_seed_default_translations(); } } /** * Seeds the translation cache from the bundled default-translations.php file * so the widget has translations available immediately after first activation, * without needing to run the translation chain. */ function welcoma_widget_seed_default_translations() { $file = WELCOMA_WIDGET_PATH . 'includes/default-translations.php'; if ( ! file_exists( $file ) ) { return; } $translations = require $file; $modules = welcoma_widget_get_modules(); $en_strings = array( 'accessibility_title' => 'Accessibility', ); foreach ( $modules as $module ) { $safe_id = str_replace( '-', '_', $module['id'] ); $en_strings[ 'mod__' . $safe_id . '__name' ] = $module['name']; $en_strings[ 'mod__' . $safe_id . '__desc' ] = $module['desc'] ?? ''; } $static_strings = Welcoma_Translator::static_ui_strings(); $en_strings = array_merge( $en_strings, $static_strings ); $cache = array(); foreach ( $translations as $key => $langs ) { foreach ( $langs as $lang => $value ) { $cache[ $key ][ $lang ] = $value; } } update_option( Welcoma_Translator::CACHE_OPTION, $cache, false ); // Seed the snapshot as English-authored so future edits in other // locales are correctly detected as "locale changed" on first save. $welcoma_seed_lang = Welcoma_Translator::current_source_lang(); $welcoma_locale_strs = array(); foreach ( array_keys( $en_strings ) as $welcoma_seed_key ) { if ( ! empty( $cache[ $welcoma_seed_key ][ $welcoma_seed_lang ] ) ) { $welcoma_locale_strs[ $welcoma_seed_key ] = $cache[ $welcoma_seed_key ][ $welcoma_seed_lang ]; } } update_option( Welcoma_Translator::SNAPSHOT_OPTION, array( 'locale' => 'en', 'values' => $en_strings, 'locales' => array_filter( array( 'en' => $en_strings, $welcoma_seed_lang => $welcoma_locale_strs, ) ), ), false ); // Bundled translations are local data; Core schedules no translation jobs. } register_activation_hook( __FILE__, 'welcoma_widget_activate' ); /** * Runs on deactivation. (Settings are kept; full cleanup happens in uninstall.php.) */ function welcoma_widget_deactivate() { // No background analytics or automatic translation jobs are scheduled by Core. } register_deactivation_hook( __FILE__, 'welcoma_widget_deactivate' ); /** * Boot the plugin once all plugins are loaded. */ function welcoma_widget() { return Welcoma_Widget::instance(); } add_action( 'plugins_loaded', 'welcoma_widget' );