/** * @param string $old_value * @param string $new_value * * @return mixed */ public function pre_update_filter($old_value, $new_value) { $wp_api = $this->sitepress->get_wp_api(); if ($wp_api->is_multisite() && $wp_api->ms_is_switched() && !$this->sitepress->get_setting('setup_complete')) { throw new RuntimeException('You cannot update blog option translations while switched to a blog on which the WPML setup is not complete! You are currently using blog ID:' . $this->sitepress->get_wp_api()->get_current_blog_id()); } WPML_Config::load_config_run(); return $this->admin_option->update_option('', $new_value, ICL_TM_COMPLETE) ? $old_value : $new_value; }
public function pre_update_option_settings_filter($old_value, $new_value) { // This is special handling for Blog Title and Tagline. global $switched; if (!$switched || $switched && wpml_get_setting_filter(false, 'setup_complete')) { $current_language = $this->st_instance->get_current_string_language($this->option_name); WPML_Config::load_config_run(); $result = $this->update_translation($this->option_name, $current_language, $new_value, ICL_TM_COMPLETE); if ($result) { return $old_value; } } return $new_value; }
public function init() { $this->init_comments_synchronization(); $this->init_default_settings(); WPML_Config::load_config(); if (is_admin()) { if ($GLOBALS['pagenow'] === 'edit.php') { // use standard WP admin notices add_action('admin_notices', array($this, 'show_messages')); } else { // use custom WP admin notices add_action('icl_tm_messages', array($this, 'show_messages')); } // Add duplicate identifier actions. $this->wpml_add_duplicate_check_actions(); // default settings if (empty($this->settings['doc_translation_method']) || !defined('WPML_TM_VERSION')) { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; } } }
private function duplicate_custom_fields($master_post_id, $lang) { $duplicate_post_id = false; $post_type = get_post_field('post_type', $master_post_id); $trid = $this->sitepress->get_element_trid($master_post_id, 'post_' . $post_type); if ($trid) { $translations = $this->sitepress->get_element_translations($trid, 'post_' . $post_type); if (isset($translations[$lang])) { $duplicate_post_id = $translations[$lang]->element_id; } else { return false; // translation not found! } } $default_exceptions = WPML_Config::get_custom_fields_translation_settings(); $exceptions = apply_filters('wpml_duplicate_custom_fields_exceptions', array()); $exceptions = array_merge($exceptions, $default_exceptions); $exceptions = array_unique($exceptions); $exceptions_in = !empty($exceptions) ? 'AND meta_key NOT IN ( ' . wpml_prepare_in($exceptions) . ') ' : ''; $from_where_string = "FROM {$this->wpdb->postmeta} WHERE post_id = %d " . $exceptions_in; $post_meta_master = $this->wpdb->get_results("SELECT meta_key, meta_value " . $this->wpdb->prepare($from_where_string, $master_post_id)); $this->wpdb->query("DELETE " . $this->wpdb->prepare($from_where_string, $duplicate_post_id)); foreach ($post_meta_master as $post_meta) { $is_serialized = is_serialized($post_meta->meta_value); $meta_data = array('context' => 'custom_field', 'attribute' => 'value', 'key' => $post_meta->meta_key, 'is_serialized' => $is_serialized, 'post_id' => $duplicate_post_id, 'master_post_id' => $master_post_id); /** * @deprecated use 'wpml_duplicate_generic_string' instead, with the same arguments */ $icl_duplicate_generic_string = apply_filters('icl_duplicate_generic_string', $post_meta->meta_value, $lang, $meta_data); $post_meta->meta_value = $icl_duplicate_generic_string; $wpml_duplicate_generic_string = apply_filters('wpml_duplicate_generic_string', $post_meta->meta_value, $lang, $meta_data); $post_meta->meta_value = $wpml_duplicate_generic_string; if (!is_serialized($post_meta->meta_value)) { $post_meta->meta_value = maybe_serialize($post_meta->meta_value); } $this->wpdb->insert($this->wpdb->postmeta, array('post_id' => $duplicate_post_id, 'meta_key' => $post_meta->meta_key, 'meta_value' => $post_meta->meta_value), array('%d', '%s', '%s')); } return true; }
function init() { $this->init_comments_synchronization(); $this->init_default_settings(); WPML_Config::load_config(); if (is_admin()) { if ($GLOBALS['pagenow'] == 'edit.php') { // use standard WP admin notices add_action('admin_notices', array($this, 'show_messages')); } else { // use custom WP admin notices add_action('icl_tm_messages', array($this, 'show_messages')); } if ($this->current_page_is('translations-queue.php') && isset($_GET['job_id'])) { add_filter('admin_head', array($this, '_show_tinyMCE')); } if (isset($this->settings['doc_translation_method']) && $this->settings['doc_translation_method'] < 0) { if ($this->current_subpage_is('mcsetup') && isset($_GET['src']) && $_GET['src'] == 'notice') { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; $this->save_settings(); } else { add_action('admin_notices', array($this, '_translation_method_notice')); } } // default settings if (empty($this->settings['doc_translation_method']) || !defined('WPML_TM_VERSION')) { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; } } }
} else { $languages = $sitepress->get_languages($sitepress->get_admin_language()); foreach ($active_languages as $lang) { if ($lang['code'] != $default_language) { $sample_lang = $lang; break; } } $default_language_details = $sitepress->get_language_details($default_language); $inactive_content = $sitepress->get_inactive_content(); } global $language_switcher_defaults, $language_switcher_defaults_alt; if (!class_exists('WPML_Config')) { require ICL_PLUGIN_PATH . '/inc/wpml-config/wpml-config.class.php'; } $theme_wpml_config_file = WPML_Config::get_theme_wpml_config_file(); $sitepress->noscript_notice(); ?> <?php if ($setup_complete || SitePress_Setup::languages_table_is_complete()) { ?> <div class="wrap <?php if (empty($setup_complete)) { ?> wpml-wizard<?php } ?> "> <div id="icon-wpml" class="icon32" ><br /></div> <h2><?php
function pre_update_option_settings($option, $value, $old_value) { global $sitepress, $sitepress_settings; $current_language = $sitepress->get_current_language(); $strings_language = $sitepress_settings['st']['strings_language']; if ($current_language == $strings_language) { return $value; } WPML_Config::load_config_run(); $result = icl_update_string_translation($option, $current_language, $value, ICL_STRING_TRANSLATION_COMPLETE); if ($result) { // returning old_value in place of value will stop update_option() processing. // do not remove it! return $old_value; } return $value; }
function init() { global $wpdb, $current_user, $sitepress_settings, $sitepress; $this->settings =& $sitepress_settings['translation-management']; //logic for syncing comments if ($sitepress->get_option('sync_comments_on_duplicates')) { add_action('delete_comment', array($this, 'duplication_delete_comment')); add_action('edit_comment', array($this, 'duplication_edit_comment')); add_action('wp_set_comment_status', array($this, 'duplication_status_comment'), 10, 2); add_action('wp_insert_comment', array($this, 'duplication_insert_comment'), 100); } $this->initial_custom_field_translate_states(); // defaults if (!isset($this->settings['notification']['new-job'])) { $this->settings['notification']['new-job'] = ICL_TM_NOTIFICATION_IMMEDIATELY; } if (!isset($this->settings['notification']['completed'])) { $this->settings['notification']['completed'] = ICL_TM_NOTIFICATION_IMMEDIATELY; } if (!isset($this->settings['notification']['resigned'])) { $this->settings['notification']['resigned'] = ICL_TM_NOTIFICATION_IMMEDIATELY; } if (!isset($this->settings['notification']['dashboard'])) { $this->settings['notification']['dashboard'] = true; } if (!isset($this->settings['notification']['purge-old'])) { $this->settings['notification']['purge-old'] = 7; } if (!isset($this->settings['custom_fields_translation'])) { $this->settings['custom_fields_translation'] = array(); } if (!isset($this->settings['doc_translation_method'])) { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; } get_currentuserinfo(); $user = false; if (isset($current_user->ID)) { $user = new WP_User($current_user->ID); } if (!$user || empty($user->data)) { return; } $ct['translator_id'] = $current_user->ID; $ct['display_name'] = isset($user->data->display_name) ? $user->data->display_name : $user->data->user_login; $ct['user_login'] = $user->data->user_login; $ct['language_pairs'] = get_user_meta($current_user->ID, $wpdb->prefix . 'language_pairs', true); if (empty($ct['language_pairs'])) { $ct['language_pairs'] = array(); } $this->current_translator = (object) $ct; WPML_Config::load_config(); if (isset($_POST['icl_tm_action'])) { $this->process_request($_POST['icl_tm_action'], $_POST); } elseif (isset($_GET['icl_tm_action'])) { $this->process_request($_GET['icl_tm_action'], $_GET); } if ($GLOBALS['pagenow'] == 'edit.php') { // use standard WP admin notices add_action('admin_notices', array($this, 'show_messages')); } else { // use custom WP admin notices add_action('icl_tm_messages', array($this, 'show_messages')); } if (isset($_GET['page']) && basename($_GET['page']) == 'translations-queue.php' && isset($_GET['job_id'])) { add_filter('admin_head', array($this, '_show_tinyMCE')); } //if(!isset($this->settings['doc_translation_method'])){ if (isset($this->settings['doc_translation_method']) && $this->settings['doc_translation_method'] < 0) { if (isset($_GET['sm']) && $_GET['sm'] == 'mcsetup' && isset($_GET['src']) && $_GET['src'] == 'notice') { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; $this->save_settings(); } else { add_action('admin_notices', array($this, '_translation_method_notice')); } } if (defined('WPML_TM_VERSION') && isset($_GET['page']) && $_GET['page'] == WPML_TM_FOLDER . '/menu/main.php' && isset($_GET['sm']) && $_GET['sm'] == 'translators') { $iclsettings =& $sitepress_settings; $sitepress->get_icl_translator_status($iclsettings); $sitepress->save_settings($iclsettings); } // default settings if (empty($this->settings['doc_translation_method']) || !defined('WPML_TM_VERSION')) { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; } }
static function check_on_config_file($name) { if (empty(self::$active_plugins)) { if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } self::$active_plugins = get_plugins(); } $config_index_file_data = maybe_unserialize(get_option('wpml_config_index')); $config_files_arr = maybe_unserialize(get_option('wpml_config_files_arr')); if (!$config_index_file_data || !$config_files_arr) { return true; } if (isset(self::$active_plugins[$name])) { $plugin_info = self::$active_plugins[$name]; $plugin_slug = dirname($name); $name = $plugin_info['Name']; $config_data = $config_index_file_data->plugins; $config_files_arr = $config_files_arr->plugins; $config_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/wpml-config.xml'; $type = 'plugin'; } else { $config_data = $config_index_file_data->themes; $config_files_arr = $config_files_arr->themes; $config_file = get_template_directory() . '/wpml-config.xml'; $type = 'theme'; } foreach ($config_data as $item) { if ($name == $item->name && isset($config_files_arr[$item->name])) { if ($item->override_local || !file_exists($config_file)) { end(self::$wpml_config_files); $key = key(self::$wpml_config_files) + 1; self::$wpml_config_files[$key] = new stdClass(); self::$wpml_config_files[$key]->config = icl_xml2array($config_files_arr[$item->name]); self::$wpml_config_files[$key]->type = $type; self::$wpml_config_files[$key]->admin_text_context = basename(dirname($config_file)); return false; } else { return true; } } } return true; }
function init() { global $sitepress; $this->init_comments_synchronization(); $this->init_default_settings(); $this->init_current_translator(); if (!$this->current_translator) { return; } WPML_Config::load_config(); if (isset($_POST['icl_tm_action'])) { $this->process_request($_POST); } elseif (isset($_GET['icl_tm_action'])) { $this->process_request($_GET); } if (is_admin()) { if ($GLOBALS['pagenow'] == 'edit.php') { // use standard WP admin notices add_action('admin_notices', array($this, 'show_messages')); } else { // use custom WP admin notices add_action('icl_tm_messages', array($this, 'show_messages')); } if ($this->current_page_is('translations-queue.php') && isset($_GET['job_id'])) { add_filter('admin_head', array($this, '_show_tinyMCE')); } if (isset($this->settings['doc_translation_method']) && $this->settings['doc_translation_method'] < 0) { if ($this->current_subpage_is('mcsetup') && isset($_GET['src']) && $_GET['src'] == 'notice') { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; $this->save_settings(); } else { add_action('admin_notices', array($this, '_translation_method_notice')); } } if (defined('WPML_TM_VERSION') && $this->current_page_is(WPML_TM_FOLDER . '/menu/main.php', 'translators')) { $lang_status = TranslationProxy_Translator::get_icl_translator_status(); if (!empty($lang_status)) { $sitepress->save_settings($lang_status); } } // default settings if (empty($this->settings['doc_translation_method']) || !defined('WPML_TM_VERSION')) { $this->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; } } }
function pre_update_option_settings($option, $value, $old_value) { global $sitepress, $sitepress_settings, $switched; if (!$switched || $switched && wpml_get_setting_filter(false, 'setup_complete')) { $current_language = $sitepress->get_current_language(); $strings_language = $sitepress_settings['st']['strings_language']; if ($current_language == $strings_language) { return $value; } WPML_Config::load_config_run(); $result = icl_update_string_translation($option, $current_language, $value, ICL_TM_COMPLETE); if ($result) { // returning old_value in place of value will stop update_option() processing. // do not remove it! return $old_value; } } return $value; }