function icl_register_string($context, $name, $value, $allow_empty_value = false) { global $wpdb, $sitepress, $sitepress_settings, $ICL_Pro_Translation; // if the default language is not set up return without doing anything if (!isset($sitepress_settings['existing_content_language_verified']) || !$sitepress_settings['existing_content_language_verified']) { return; } // Check if cached (so exists) $cached = icl_t_cache_lookup($context, $name); if ($cached && isset($cached['original']) && $cached['original'] == $value) { return; } $language = $sitepress->get_default_language(); $res = $wpdb->get_row("SELECT id, value, status, language FROM {$wpdb->prefix}icl_strings WHERE context='" . $wpdb->escape($context) . "' AND name='" . $wpdb->escape($name) . "'"); if ($res) { $string_id = $res->id; $update_string = array(); if ($value != $res->value) { $update_string['value'] = $value; } if ($language != $res->language) { $update_string['language'] = $language; } if (!empty($update_string)) { $wpdb->update($wpdb->prefix . 'icl_strings', $update_string, array('id' => $string_id)); $wpdb->update($wpdb->prefix . 'icl_string_translations', array('status' => ICL_STRING_TRANSLATION_NEEDS_UPDATE), array('string_id' => $string_id)); icl_update_string_status($string_id); } } else { if (!empty($value) && is_scalar($value) && trim($value) || $allow_empty_value) { $string = array('language' => $language, 'context' => $context, 'name' => $name, 'value' => $value, 'status' => ICL_STRING_TRANSLATION_NOT_TRANSLATED); $wpdb->insert($wpdb->prefix . 'icl_strings', $string); $string_id = $wpdb->insert_id; } else { $string_id = 0; } } global $WPML_Sticky_Links; if (!empty($WPML_Sticky_Links) && $WPML_Sticky_Links->settings['sticky_links_strings']) { require_once ICL_PLUGIN_PATH . '/inc/translation-management/pro-translation.class.php'; ICL_Pro_Translation::_content_make_links_sticky($string_id, 'string', false); } return $string_id; }
function icl_register_string($context, $name, $value, $allow_empty_value = false) { global $wpdb, $sitepress_settings; /* cpt slugs - do not register them when scanning themes and plugins * if name starting from 'URL slug: ' * and context is different from 'WordPress' */ if (substr($name, 0, 10) === 'URL slug: ' && 'WordPress' !== $context) { return false; } // if the default language is not set up return without doing anything if (!isset($sitepress_settings['existing_content_language_verified']) || !$sitepress_settings['existing_content_language_verified']) { return false; } // Check if cached (so exists) $cached = icl_t_cache_lookup($context, $name); if ($cached && isset($cached['original']) && $cached['original'] == $value) { return false; } $language = isset($sitepress_settings['st']['strings_language']) ? $sitepress_settings['st']['strings_language'] : 'en'; $res = $wpdb->get_row("SELECT id, value, status, language FROM {$wpdb->prefix}icl_strings WHERE context='" . esc_sql($context) . "' AND name='" . esc_sql($name) . "'"); if ($res) { $string_id = $res->id; $update_string = array(); /* * If Sticky Links plugin is active and set to change links in Strings, * we need to process $value and change links into sticky before comparing * with saved in DB $res->value. * Otherwise after every String Translation screen refresh status of this string * will be changed into 'needs update' */ $alp_settings = get_option('alp_settings'); if (!empty($alp_settings['sticky_links_strings']) && $alp_settings['sticky_links_strings'] && defined('WPML_STICKY_LINKS_VERSION')) { // sticky links plugin is active? require_once ICL_PLUGIN_PATH . '/inc/absolute-links/absolute-links.class.php'; $absolute_links_object = new AbsoluteLinks(); $alp_broken_links = array(); $value = $absolute_links_object->_process_generic_text($value, $alp_broken_links); } if ($value != $res->value) { $update_string['value'] = $value; } if ($language != $res->language) { $update_string['language'] = $language; } if (!empty($update_string)) { $wpdb->update($wpdb->prefix . 'icl_strings', $update_string, array('id' => $string_id)); $wpdb->update($wpdb->prefix . 'icl_string_translations', array('status' => ICL_STRING_TRANSLATION_NEEDS_UPDATE), array('string_id' => $string_id)); icl_update_string_status($string_id); } } else { if (!empty($value) && is_scalar($value) && trim($value) || $allow_empty_value) { $string = array('language' => $language, 'context' => $context, 'name' => $name, 'value' => $value, 'status' => ICL_STRING_TRANSLATION_NOT_TRANSLATED); $wpdb->insert($wpdb->prefix . 'icl_strings', $string); $string_id = $wpdb->insert_id; } else { $string_id = 0; } } global $WPML_Sticky_Links; if (!empty($WPML_Sticky_Links) && $WPML_Sticky_Links->settings['sticky_links_strings']) { require_once ICL_PLUGIN_PATH . '/inc/translation-management/pro-translation.class.php'; ICL_Pro_Translation::_content_make_links_sticky($string_id, 'string', false); } return $string_id; }