function translated_attribute_label($label, $name)
 {
     global $sitepress;
     if (is_admin() && !wpml_is_ajax()) {
         global $wpdb, $sitepress_settings;
         $string_id = icl_get_string_id('taxonomy singular name: ' . $label, 'WordPress');
         if (defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
             $strings_language = icl_st_get_string_language($string_id);
         } else {
             $strings_language = $sitepress_settings['st']['strings_language'];
         }
         if ($string_id && $sitepress_settings['admin_default_language'] != $strings_language) {
             $string = $wpdb->get_var($wpdb->prepare("SELECT value FROM {$wpdb->prefix}icl_string_translations WHERE string_id = %s and language = %s", $string_id, $sitepress_settings['admin_default_language']));
             if ($string) {
                 return $string;
             }
         } else {
             return $label;
         }
     }
     $name = sanitize_title($name);
     $lang = $sitepress->get_current_language();
     $trnsl_labels = get_option('wcml_custom_attr_translations');
     if (isset($trnsl_labels[$lang][$name])) {
         return $trnsl_labels[$lang][$name];
     }
     return icl_t('WordPress', 'taxonomy singular name: ' . $label, $label);
 }
 function translated_attribute_label($label, $name)
 {
     global $sitepress;
     if (is_admin() && !wpml_is_ajax()) {
         global $wpdb, $sitepress_settings;
         if ($sitepress_settings['admin_default_language'] == $sitepress_settings['st']['strings_language']) {
             return $label;
         } else {
             $string_id = icl_get_string_id('taxonomy singular name: ' . $label, 'WordPress');
             if ($string_id) {
                 $string = $wpdb->get_var($wpdb->prepare("SELECT value FROM {$wpdb->prefix}icl_string_translations WHERE string_id = %s and language = %s", $string_id, $sitepress_settings['admin_default_language']));
                 if ($string) {
                     return $string;
                 }
             }
         }
     }
     $name = woocommerce_sanitize_taxonomy_name($name);
     $lang = $sitepress->get_current_language();
     $trnsl_labels = get_option('wcml_custom_attr_translations');
     if (isset($trnsl_labels[$lang][$name])) {
         return $trnsl_labels[$lang][$name];
     }
     return icl_t('WordPress', 'taxonomy singular name: ' . $label, $label);
 }
Ejemplo n.º 3
0
 public function locale()
 {
     global $locale, $sitepress;
     add_filter('language_attributes', array($this, '_language_attributes'));
     if (wpml_is_ajax() && isset($_REQUEST['action']) && isset($_REQUEST['lang'])) {
         $locale_lang_code = $_REQUEST['lang'];
     } elseif (is_admin() && (!wpml_is_ajax() || isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], '/wp-admin/') !== false)) {
         $locale_lang_code = $sitepress->user_lang_by_authcookie();
     } else {
         $locale_lang_code = $sitepress->get_current_language();
     }
     $locale = $this->get_locale($locale_lang_code);
     // theme localization
     remove_filter('locale', array($sitepress, 'locale'));
     //avoid infinite loop
     static $theme_locales_loaded = false;
     if (!$theme_locales_loaded && (bool) $sitepress->get_setting('theme_localization_load_textdomain') === true && (bool) $sitepress->get_setting('gettext_theme_domain_name') === true && (bool) $sitepress->get_setting('theme_language_folders') === true) {
         $theme_folder_settings = $sitepress->get_setting('theme_language_folders');
         foreach ($theme_folder_settings as $folder) {
             load_textdomain($sitepress->get_setting('gettext_theme_domain_name'), $folder . '/' . $locale . '.mo');
         }
         $theme_locales_loaded = true;
     }
     add_filter('locale', array($sitepress, 'locale'));
     return $locale;
 }
Ejemplo n.º 4
0
function wpml_st_setup_label_menu_hooks()
{
    if (is_admin()) {
        add_action('wpml_st_load_label_menu', 'wpml_st_load_label_menu');
    }
    if (wpml_is_ajax()) {
        wpml_st_load_label_menu();
    }
}
 function init()
 {
     if (wpml_is_ajax()) {
         do_action('localize_woocommerce_on_ajax');
     }
     add_filter('woocommerce_params', array($this, 'filter_woocommerce_ajax_params'));
     add_action('woocommerce_checkout_order_review', array($this, 'filter_woocommerce_order_review'), 9);
     add_action('woocommerce_checkout_update_order_review', array($this, 'filter_woocommerce_order_review'), 9);
 }
 function init()
 {
     if (wpml_is_ajax()) {
         do_action('localize_woocommerce_on_ajax');
     }
     add_filter('woocommerce_params', array($this, 'filter_woocommerce_ajax_params'));
     add_filter('wc_checkout_params', array($this, 'add_language_parameter_to_ajax_url'));
     add_filter('wc_cart', array($this, 'add_language_parameter_to_ajax_url'));
     add_filter('wc_cart_fragments_params', array($this, 'add_language_parameter_to_ajax_url'));
     add_filter('wc_add_to_cart_params', array($this, 'add_language_parameter_to_ajax_url'));
     add_action('woocommerce_checkout_order_review', array($this, 'filter_woocommerce_order_review'), 9);
     add_action('woocommerce_checkout_update_order_review', array($this, 'filter_woocommerce_order_review'), 9);
 }
Ejemplo n.º 7
0
 static function load_config()
 {
     global $pagenow, $sitepress;
     if (!is_admin() || wpml_is_ajax() || isset($_POST['action']) && $_POST['action'] === 'heartbeat' || !$sitepress || !$sitepress->get_default_language()) {
         return;
     }
     $white_list_pages = array('theme_options', 'plugins.php', 'themes.php', ICL_PLUGIN_FOLDER . '/menu/languages.php', ICL_PLUGIN_FOLDER . '/menu/theme-localization.php', ICL_PLUGIN_FOLDER . '/menu/translation-options.php');
     if (defined('WPML_ST_FOLDER')) {
         $white_list_pages[] = WPML_ST_FOLDER . '/menu/string-translation.php';
     }
     if (defined('WPML_TM_FOLDER')) {
         $white_list_pages[] = WPML_TM_FOLDER . '/menu/main.php';
     }
     //Runs the load config process only on specific pages
     $current_page = isset($_GET['page']) ? $_GET['page'] : null;
     if (isset($current_page) && in_array($current_page, $white_list_pages) || isset($pagenow) && in_array($pagenow, $white_list_pages)) {
         self::load_config_run();
     }
 }
Ejemplo n.º 8
0
 public static function check_settings_integrity()
 {
     if (wpml_is_ajax()) {
         return true;
     }
     if (isset($_GET['debug_action']) && $_GET['nonce'] == wp_create_nonce($_GET['debug_action'])) {
         if ($_GET['debug_action'] == 'reset_wpml_settings') {
             $referrer = isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : get_admin_url();
             $current_settings = get_option('icl_sitepress_settings');
             unset($current_settings['setup_complete']);
             unset($current_settings['setup_wizard_step']);
             unset($current_settings['existing_content_language_verified']);
             unset($current_settings['dont_show_help_admin_notice']);
             global $wpdb;
             $wpdb->query('TRUNCATE TABLE ' . $wpdb->prefix . 'icl_translations');
             update_option('icl_sitepress_settings', $current_settings);
             wp_redirect($referrer);
             exit;
         }
     }
     global $wpdb;
     static $result;
     if (isset($result)) {
         return $result;
     }
     $current_settings = get_option('icl_sitepress_settings');
     if (!$current_settings) {
         return true;
     }
     $setup_wizard_step = false;
     if (isset($current_settings['setup_wizard_step'])) {
         $setup_wizard_step = $current_settings['setup_wizard_step'];
     }
     $setup_complete = false;
     $setup_complete_missing = true;
     if (isset($current_settings['setup_complete'])) {
         $setup_complete = $current_settings['setup_complete'];
         $setup_complete_missing = false;
     }
     //Skip checks during first setup wizard
     if ($setup_wizard_step !== false && $setup_wizard_step < 4 || !$setup_complete_missing && $setup_complete === false && $setup_wizard_step == 4) {
         return true;
     }
     $default_language = false;
     $default_language_missing = true;
     if (isset($current_settings['default_language'])) {
         $default_language = $current_settings['default_language'];
         $default_language_missing = false;
     }
     $active_languages_sql = "SELECT * FROM " . $wpdb->prefix . 'icl_languages WHERE active=%d';
     $active_languages_prepared = $wpdb->prepare($active_languages_sql, array(1));
     $active_languages = $wpdb->get_results($active_languages_prepared);
     $existing_translations_sql = "SELECT count(*) FROM " . $wpdb->prefix . 'icl_translations';
     $existing_translations = $wpdb->get_var($existing_translations_sql);
     $show_notice = false;
     $message = '';
     if ((!$setup_complete || !$default_language) && $existing_translations) {
         $message .= '<p>';
         $message .= __('Your WPML settings seem to be corrupted. To avoid corrupting your existing data, we have hidden WPML from this site.', 'sitepress');
         $message .= '</p>';
         $message .= '<p>';
         $message .= __('If this is the first time you install WPML on this site, you may have faced a database or script connection drop, that caused settings to be not completely store.', 'sitepress');
         $message .= __('In this case, you can click on the <strong>Reset Settings</strong> button: this will reset WPML settings and any language translation information, allowing you to restart the wizard.', 'sitepress');
         $message .= '</p>';
         $message .= '<p>';
         $message .= sprintf(__('If you have just upgraded WPML or after starting over you keep getting this message, please contact the <a href="%s">support forum</a> as soon as possible, in order to provide you with a fix to this issue.', 'sitepress'), 'https://wpml.org/forums/');
         $message .= '</p>';
         $message .= '<p>';
         $confirm_message = _x('Are you sure you want to reset WPML Settings?', 'Reset WPML settings', 'sitepress');
         $confirm_message .= ' ';
         $confirm_message .= _x('This will also empty translation information (if any).', 'Reset WPML settings', 'sitepress');
         $message .= '<a href="?icl_reset_settings=1&debug_action=reset_wpml_settings&nonce=' . wp_create_nonce('reset_wpml_settings') . '" class="button" onclick="return window.confirm(\'' . $confirm_message . '\');" >' . __('Reset Settings', 'sitepress') . '</a>';
         $message .= '&nbsp;';
         $message .= '&nbsp;';
         $message .= '&nbsp;';
         $message .= '<a href="https://wpml.org/forums/" class="button">' . __('Contact Support', 'sitepress') . '</a>';
         $message .= '</p>';
         $message .= '<p>';
         $message .= __('Additional details for the support team (there is no need to copy it, as the support team will be able to see it once logged in):', 'sitepress');
         $message .= '</p>';
         $message .= '<p><textarea rows="10" style="width:100%;display:block;" onclick="this.focus();this.select();" readonly="readonly">';
         $message .= str_repeat('=', 50);
         $wpml_plugins_list = SitePress::get_installed_plugins();
         foreach ($wpml_plugins_list as $name => $plugin_data) {
             $plugin_name = $name;
             $file = $plugin_data['file'];
             $message .= PHP_EOL . $plugin_name;
             $message .= ' ' . (isset($plugin_data['plugin']['Version']) ? $plugin_data['plugin']['Version'] : __('Version n/a', 'sitepress'));
             $message .= ' => ';
             if (empty($plugin_data['plugin'])) {
                 $message .= 'Not installed';
             } else {
                 $message .= 'Installed';
             }
             $message .= '/';
             $message .= isset($file) && is_plugin_active($file) ? 'Active' : 'Not Active';
         }
         $message .= PHP_EOL . str_repeat('-', 50);
         $message .= PHP_EOL . 'icl_translations count: ' . ($existing_translations ? $existing_translations : '0');
         $message .= PHP_EOL . 'setup_complete: ' . ($setup_complete ? 'true' : 'false');
         $message .= PHP_EOL . 'setup_complete missing: ' . ($setup_complete_missing ? 'true' : 'false');
         $message .= PHP_EOL . 'default_language: ' . ($default_language ? $default_language : '""');
         $message .= PHP_EOL . 'default_language_missing: ' . ($default_language_missing ? 'true' : 'false');
         $message .= PHP_EOL . PHP_EOL . 'active_languages: ' . PHP_EOL . print_r($active_languages, true);
         $message .= PHP_EOL . PHP_EOL . 'icl_sitepress_settings (serialized): ' . PHP_EOL . serialize($current_settings);
         $message .= PHP_EOL . PHP_EOL . 'icl_sitepress_settings (unserialized): ' . PHP_EOL . print_r($current_settings, true);
         $message .= PHP_EOL . str_repeat('=', 50);
         $message .= '</textarea></p>';
         $show_notice = true;
     }
     //		ICL_AdminNotifier::removeMessage( 'check_settings_integrity' );
     ICL_AdminNotifier::removeMessage('check_settings_integrity_corrupted');
     if ($show_notice) {
         ICL_AdminNotifier::addMessage('check_settings_integrity_corrupted', $message, 'error', false, false, false, 'check_settings_integrity', true);
         ICL_AdminNotifier::displayMessages('check_settings_integrity');
     }
     $result = !$show_notice;
     return $result;
 }
 protected function get_cookie_name()
 {
     return wpml_is_ajax() && $this->check_if_admin_action_from_referer() === false ? '_icl_current_language' : '_icl_current_admin_language_' . md5($this->get_cookie_domain());
 }
Ejemplo n.º 10
0
 function translate_attribute_taxonomies_labels($attribute_taxonomies)
 {
     global $sitepress;
     if (is_admin() && !wpml_is_ajax()) {
         foreach ($attribute_taxonomies as $key => $attribute_taxonomy) {
             $string_language = $this->get_string_language($attribute_taxonomy->attribute_name, 'WordPress', 'taxonomy singular name: ' . $attribute_taxonomy->attribute_name);
             if ($sitepress->get_current_language() == $string_language) {
                 continue;
             }
             $string_id = icl_get_string_id($attribute_taxonomy->attribute_name, 'WordPress', 'taxonomy singular name: ' . $attribute_taxonomy->attribute_name);
             $strings = icl_get_string_translations_by_id($string_id);
             if ($strings && isset($strings[$sitepress->get_current_language()])) {
                 $attribute_taxonomies[$key]->attribute_label = $strings[$sitepress->get_current_language()]['value'];
             }
         }
     }
     return $attribute_taxonomies;
 }
Ejemplo n.º 11
0
 function init()
 {
     global $wpml_post_translations;
     $this->post_translation =& $wpml_post_translations;
     do_action('wpml_before_init');
     $this->locale_utils->init();
     $this->maybe_set_this_lang();
     if (function_exists('w3tc_add_action')) {
         w3tc_add_action('w3tc_object_cache_key', 'w3tc_translate_cache_key_filter');
     }
     $this->get_user_preferences();
     $this->set_admin_language();
     // default value for theme_localization_type OR
     // reset theme_localization_type if string translation was on (theme_localization_type was set to 2) and then it was deactivated
     if (!isset($this->settings['theme_localization_type']) || $this->settings['theme_localization_type'] == 1 && !defined('WPML_ST_VERSION') && !defined('WPML_DOING_UPGRADE')) {
         global $sitepress_settings;
         $this->settings['theme_localization_type'] = $sitepress_settings['theme_localization_type'] = 2;
     }
     //configure callbacks for plugin menu pages
     if (defined('WP_ADMIN') && isset($_GET['page']) && 0 === strpos($_GET['page'], basename(ICL_PLUGIN_PATH) . '/')) {
         add_action('icl_menu_footer', array($this, 'menu_footer'));
     }
     //Run only if existing content language has been verified, and is front-end or settings are not corrupted
     if (!empty($this->settings['existing_content_language_verified'])) {
         add_action('wpml_verify_post_translations', array($this, 'verify_post_translations_action'), 10, 1);
         if ($this->settings['language_negotiation_type'] == 2) {
             add_filter('allowed_redirect_hosts', array($this, 'allowed_redirect_hosts'));
         }
         //reorder active language to put 'this_lang' in front
         $active_languages = $this->get_active_languages();
         foreach ($active_languages as $k => $active_lang) {
             if ($k === $this->this_lang) {
                 unset($this->active_languages[$k]);
                 $this->active_languages = array_merge(array($k => $active_lang), $this->active_languages);
             }
         }
         add_filter('mod_rewrite_rules', array($this, 'rewrite_rules_filter'), 10, 1);
         if (is_admin() && $this->get_setting('setup_complete') && (!isset($_GET['page']) || !defined('WPML_ST_FOLDER') || $_GET['page'] != WPML_ST_FOLDER . '/menu/string-translation.php') && (!isset($_GET['page']) || !defined('WPML_TM_FOLDER') || $_GET['page'] != WPML_TM_FOLDER . '/menu/translations-queue.php')) {
             // Admin language switcher goes to the WP admin bar
             if (apply_filters('wpml_show_admin_language_switcher', true)) {
                 add_action('wp_before_admin_bar_render', array($this, 'admin_language_switcher'));
             } else {
                 $this->this_lang = 'all';
             }
         }
         if (!is_admin() && defined('DISQUS_VERSION')) {
             include ICL_PLUGIN_PATH . '/modules/disqus.php';
         }
     }
     if ($this->is_rtl()) {
         $GLOBALS['text_direction'] = 'rtl';
     }
     if (!wpml_is_ajax() && is_admin() && empty($this->settings['dont_show_help_admin_notice'])) {
         WPML_Troubleshooting_Terms_Menu::display_terms_with_suffix_admin_notice();
         if (!$this->get_setting('setup_wizard_step') && strpos(filter_input(INPUT_GET, 'page', FILTER_SANITIZE_URL), 'menu/languages.php') === false) {
             add_action('admin_notices', array($this, 'help_admin_notice'));
         }
     }
     $short_v = implode('.', array_slice(explode('.', ICL_SITEPRESS_VERSION), 0, 3));
     if (is_admin() && (!isset($this->settings['hide_upgrade_notice']) || $this->settings['hide_upgrade_notice'] != $short_v)) {
         add_action('admin_notices', array($this, 'upgrade_notice'));
     }
     require ICL_PLUGIN_PATH . '/inc/template-constants.php';
     if (defined('WPML_LOAD_API_SUPPORT')) {
         require ICL_PLUGIN_PATH . '/inc/wpml-api.php';
     }
     add_action('wp_footer', array($this, 'display_wpml_footer'), 20);
     if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
         add_action('xmlrpc_call', array($this, 'xmlrpc_call_actions'));
         add_filter('xmlrpc_methods', array($this, 'xmlrpc_methods'));
     }
     if (defined('WPML_TM_VERSION') && is_admin()) {
         require ICL_PLUGIN_PATH . '/inc/quote.php';
     }
     add_action('init', array($this, 'set_up_language_selector'));
     global $pagenow;
     // set language to default and remove language switcher when in Taxonomy Translation page
     // If the page uses AJAX and the language must be forced to default, please use the
     // if ( $pagenow == 'admin-ajax.php' )above
     if (is_admin() && (isset($_GET['page']) && ($_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/taxonomy-translation.php' || $_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/menu-sync/menus-sync.php' || $_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/term-taxonomy-menus/taxonomy-translation-display.class.php') || $pagenow == 'admin-ajax.php' && isset($_POST['action']) && $_POST['action'] == 'wpml_tt_save_labels_translation')) {
         $default_language = $this->get_admin_language();
         $this->switch_lang($default_language, true);
         add_action('init', array($this, 'remove_admin_language_switcher'));
     }
     /* Posts and new inline created terms, can only be saved in an active language.
      * Also the content of the post-new.php should always be filtered for one specific
      * active language, so to display the correct taxonomy terms for selection.
      */
     if ($pagenow == 'post-new.php') {
         if (!$this->is_active_language($this->get_current_language())) {
             $default_language = $this->get_admin_language();
             $this->switch_lang($default_language, true);
         }
     }
     //Code to run when reactivating the plugin
     $recently_activated = $this->get_setting('just_reactivated');
     if ($recently_activated) {
         add_action('init', array($this, 'rebuild_language_information'), 1000);
     }
     if (is_admin()) {
         $this->post_edit_metabox = new WPML_Meta_Boxes_Post_Edit_HTML($this, $this->post_translation);
     }
     do_action('wpml_after_init');
     do_action('wpml_loaded');
 }
 function translate_attribute_taxonomies_labels($attribute_taxonomies)
 {
     if (is_admin() && !wpml_is_ajax()) {
         global $wpdb, $sitepress;
         foreach ($attribute_taxonomies as $key => $attribute_taxonomy) {
             $string = $wpdb->get_var($wpdb->prepare("SELECT st.value FROM {$wpdb->prefix}icl_string_translations AS st JOIN {$wpdb->prefix}icl_strings AS s ON s.id = st.string_id WHERE s.context = %s AND s.name = %s AND st.language = %s", 'WordPress', 'taxonomy singular name: ' . $attribute_taxonomy->attribute_name, $sitepress->get_current_language()));
             if ($string) {
                 $attribute_taxonomies[$key]->attribute_label = $string;
             }
         }
     }
     return $attribute_taxonomies;
 }
 public function is_ajax()
 {
     return defined('DOING_AJAX') && DOING_AJAX || wpml_is_ajax();
 }
 function create_booking_page_client_currency($currency)
 {
     global $pagenow;
     if (wpml_is_ajax() && isset($_POST['form'])) {
         parse_str($_POST['form'], $posted);
     }
     if ($pagenow == 'edit.php' && isset($_GET['page']) && $_GET['page'] == 'create_booking' || isset($posted['_wp_http_referer']) && strpos($posted['_wp_http_referer'], 'page=create_booking') !== false) {
         $currency = $this->get_cookie_booking_currency();
     }
     return $currency;
 }