*/ if ( ! defined( 'ABSPATH' ) ) { exit; } class Group107_AccessibleDocs_Options { /** * Get the value of the 'accessible_docs_enable_popup' option. * * @since 1.0.0 * * @return bool True if the popup is enabled, false otherwise. */ public static function accessible_docs_is_popup_enabled() { $option_name = Group107_AccessibleDocs_i18n::accessible_docs_get_popup_options_name(); $options = get_option($option_name); return isset($options['accessible_docs_enable_popup']) && $options['accessible_docs_enable_popup'] === '1'; } /** * Get the default value for a specific field based on the locale. * * @since 1.0.0 * * @param string $field The field name (key). * @param string $locale The current language locale. * * @return string The default value for the field. */ public static function accessible_docs_get_default_value($field, $locale) { // Default values for en and he languages $default_values = [ 'en' => [ 'accessible_docs_enable_popup' => 0, 'accessible_docs_popup_title' => 'Make Your PDF Accessible!', 'accessible_docs_popup_text' => 'If you want to get this file accessible, please leave your email, and we’ll send it to you within 24 hours.', 'accessible_docs_email_placeholder' => 'Enter your email address', 'accessible_docs_submit_button_text' => 'Submit Request', 'accessible_docs_processing_title' => 'Your Request is Being Processed', 'accessible_docs_processing_text' => 'Your accessible file is being processed. You will receive it soon via email.', 'accessible_docs_completed_title' => 'Your Accessible File is Ready', 'accessible_docs_completed_text' => 'Your accessible file has been sent to your email. If you haven’t received it, please contact the website administrator.', 'accessible_docs_download_non_accessible_link_text' => 'Download Non-Accessible File', ], 'he' => [ 'accessible_docs_enable_popup' => 0, 'accessible_docs_popup_title' => 'הפוך את ה-PDF שלך לנגיש!', 'accessible_docs_popup_text' => 'אם ברצונך להפוך קובץ זה לנגיש, אנא השאר את האימייל שלך, ואנו נשלח אותו אליך תוך 24 שעות.', 'accessible_docs_email_placeholder' => 'הזן את כתובת האימייל שלך', 'accessible_docs_submit_button_text' => 'שלח בקשה', 'accessible_docs_processing_title' => 'הבקשה שלך בעיבוד', 'accessible_docs_processing_text' => 'הקובץ הנגיש שלך בעיבוד. תקבל אותו בקרוב באימייל.', 'accessible_docs_completed_title' => 'הקובץ הנגיש שלך מוכן', 'accessible_docs_completed_text' => 'הקובץ הנגיש שלך נשלח לאימייל שלך. אם לא קיבלת אותו, אנא צור קשר עם מנהל האתר.', 'accessible_docs_download_non_accessible_link_text' => 'הורד קובץ לא נגיש', ] ]; // Return the default value based on locale, or fallback to 'en' return isset($default_values[$locale][$field]) ? $default_values[$locale][$field] : $default_values['en'][$field]; } /** * Get the current locale based on the active language in WPML or Polylang. * * @since 1.0.0 * * @return string The current language locale (e.g., 'en', 'he'). */ public static function accessible_docs_get_locale() { // Check if Polylang is active if (function_exists('pll_current_language')) { return pll_current_language(); // Return the current language from Polylang } // Check if WPML is active if (defined('ICL_SITEPRESS_VERSION')) { $current_lang = apply_filters('wpml_current_language', null); // Get the current language from WPML return $current_lang; } // Default to 'en' if no multilingual plugin is active return substr(get_locale(), 0, 2); } /** * Get all the popup options with default fallbacks if values are missing. * * This function retrieves the popup settings and returns default values * for any missing fields based on the current language (en or he). * * @since 1.0.0 * * @return array The popup options, with default values where necessary. */ public static function accessible_docs_get_popup_options() { $accessible_docs_option_name = Group107_AccessibleDocs_i18n::accessible_docs_get_popup_options_name(); $accessible_docs_options = get_option($accessible_docs_option_name); // If options doesn't exist reinitialize as empty array/ if(!$accessible_docs_options){ $accessible_docs_options = []; } // Get the current locale $locale = self::accessible_docs_get_locale(); // Check if any option is empty and return the default value $fields = [ 'accessible_docs_popup_title', 'accessible_docs_popup_text', 'accessible_docs_email_placeholder', 'accessible_docs_submit_button_text', 'accessible_docs_processing_title', 'accessible_docs_processing_text', 'accessible_docs_completed_title', 'accessible_docs_completed_text', 'accessible_docs_download_non_accessible_link_text' ]; // Iterate through each field and check if it's empty foreach ($fields as $field) { if (empty($accessible_docs_options[$field])) { // If empty, set the default value for this field $accessible_docs_options[$field] = self::accessible_docs_get_default_value($field, $locale); } } return $accessible_docs_options; } }