protected function cleanup_wrong_contexts() { global $wpdb; $old_context = $this->get_old_context(); $results = $wpdb->get_results($wpdb->prepare("\n\t SELECT id, name, value\n\t FROM {$wpdb->prefix}icl_strings\n\t WHERE context = %s", $old_context)); foreach ($results as $string) { // See if the string has no translations $old_translations = $wpdb->get_results($wpdb->prepare("\n\t\t\t\tSELECT id, language, status, value\n\t\t\t\tFROM {$wpdb->prefix}icl_string_translations\n\t\t\t\tWHERE string_id = %d", $string->id)); if (empty($old_translations)) { // We don't have any translations so we can delete the string. $wpdb->delete($wpdb->prefix . 'icl_strings', array('id' => $string->id), array('%d')); } else { // check if we have a new string in the right context $domains = $this->get_domains_found(); foreach ($domains as $domain => $count) { $new_string_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT id\n\t\t\t\t\t\tFROM {$wpdb->prefix}icl_strings\n\t\t\t\t\t\tWHERE context = %s AND name = %s AND value = %s", $domain, $string->name, $string->value)); if ($new_string_id) { // See if it has the same translations $new_translations = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT id, language, status, value\n\t\t\t\t\t\t\tFROM {$wpdb->prefix}icl_string_translations\n\t\t\t\t\t\t\tWHERE string_id = %d", $new_string_id)); foreach ($new_translations as $new_translation) { foreach ($old_translations as $index => $old_translation) { if ($new_translation->language == $old_translation->language && $new_translation->status == $old_translation->status && $new_translation->value == $old_translation->value) { unset($old_translations[$index]); } } } if (empty($old_translations)) { // We don't have any old translations that are not in the new strings so we can delete the string. $wpdb->delete($wpdb->prefix . 'icl_strings', array('id' => $string->id), array('%d')); break; } } } } } // Rename the context for any strings that are in the old context // This way the update message will no longer show. $obsolete_context = str_replace('plugin ', '', $old_context); $obsolete_context = str_replace('theme ', '', $obsolete_context); $obsolete_context = $obsolete_context . ' (obsolete)'; $wpdb->query($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t UPDATE {$wpdb->prefix}icl_strings\n\t\t\t\t\t\t\t\t\t SET context = %s\n\t\t\t\t\t\t\t\t\t WHERE context = %s\n\t\t\t\t\t\t\t\t\t ", $obsolete_context, $old_context)); WPML_String_Translation::clear_use_original_cache_setting(); }