: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
include_once WPML_PLUGIN_PATH . '/inc/functions-troubleshooting.php';
function get_term_taxonomy_id_from_term_object($term_object)
return $term_object->term_taxonomy_id;
$action = filter_input(INPUT_GET, 'debug_action', FILTER_SANITIZE_STRING);
$nonce = filter_input(INPUT_GET, 'nonce', FILTER_SANITIZE_STRING);
$action = filter_input( INPUT_POST, 'debug_action', FILTER_SANITIZE_STRING );
$nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_STRING );
$otgs_twig_cache_disable_key = '_otgs_twig_cache_disabled';
if ( defined( 'WPML_Templates_Factory::OTGS_TWIG_CACHE_DISABLED_KEY' ) ) {
$otgs_twig_cache_disable_key = WPML_Templates_Factory::OTGS_TWIG_CACHE_DISABLED_KEY;
if ( isset( $action ) && wp_verify_nonce( $nonce, $action ) ) {
case 'otgs_twig_cache_enable':
if ( array_key_exists( 'new_value', $_POST ) ) {
$new_value = (bool) $_POST['new_value'];
update_option( $otgs_twig_cache_disable_key, $new_value, 'no' );
SitePress_Setup::fill_languages();
SitePress_Setup::fill_languages_translations();
case 'icl_fix_collation':
repair_el_type_collate();
$cache_directory = new WPML_Cache_Directory( new WPML_WP_API() );
$cache_directory->remove();
// clean the icl_translations table
$orphans = $wpdb->get_col( "
SELECT t.translation_id, t.element_type
FROM {$wpdb->prefix}icl_translations t
LEFT JOIN {$wpdb->posts} p ON t.element_id = p.ID
WHERE t.element_id IS NOT NULL AND t.element_type LIKE 'post\\_%' AND p.ID IS NULL
if ( !empty( $orphans ) ) {
$upgrade_args_set = array();
foreach( $orphans as $orphan ) {
'translation_id' => $orphan,
$upgrade_args_set[] = $upgrade_args;
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'before_delete' ) ) );
$wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translations
WHERE translation_id IN (" . wpml_prepare_in( $orphans, '%d' ) . ")" );
foreach( $upgrade_args_set as $upgrade_args ) {
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'after_delete' ) ) );
$orphans = $wpdb->get_col( "
FROM {$wpdb->prefix}icl_translations t
LEFT JOIN {$wpdb->comments} c ON t.element_id = c.comment_ID
WHERE t.element_type = 'comment' AND c.comment_ID IS NULL " );
if ( false === $orphans ) {
if ( !empty( $orphans ) ) {
$upgrade_args_set = array();
foreach( $orphans as $orphan ) {
'translation_id' => $orphan,
$upgrade_args_set[] = $upgrade_args;
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'before_delete' ) ) );
$wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translations
WHERE translation_id IN (" . wpml_prepare_in( $orphans, '%d' ) . ")" );
foreach( $upgrade_args_set as $upgrade_args ) {
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'after_delete' ) ) );
$orphans = $wpdb->get_col( "
FROM {$wpdb->prefix}icl_translations t
LEFT JOIN {$wpdb->term_taxonomy} p ON t.element_id = p.term_taxonomy_id
WHERE t.element_id IS NOT NULL AND t.element_type LIKE 'tax\\_%' AND p.term_taxonomy_id IS NULL" );
if ( !empty( $orphans ) ) {
$upgrade_args_set = array();
foreach( $orphans as $orphan ) {
'translation_id' => $orphan,
$upgrade_args_set[] = $upgrade_args;
do_action( 'wpml_translation_update', $upgrade_args );
$wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translations
WHERE translation_id IN (" . wpml_prepare_in( $orphans, '%d' ) . ")" );
foreach( $upgrade_args_set as $upgrade_args ) {
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'after_delete' ) ) );
if ( is_array( $wp_taxonomies ) ) {
foreach ( $wp_taxonomies as $t => $v ) {
$orphans = $wpdb->get_col( "
FROM {$wpdb->prefix}icl_translations t
LEFT JOIN {$wpdb->term_taxonomy} p
ON t.element_id = p.term_taxonomy_id
WHERE t.element_type = 'tax_{$t}'
if ( !empty( $orphans ) ) {
$upgrade_args_set = array();
foreach( $orphans as $orphan ) {
'translation_id' => $orphan,
$upgrade_args_set[] = $upgrade_args;
do_action( 'wpml_translation_update', $upgrade_args );
$wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translations
WHERE translation_id IN (" . wpml_prepare_in( $orphans, '%d' ) . ")" );
foreach( $upgrade_args_set as $upgrade_args ) {
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'after_delete' ) ) );
// remove ghost translations
$rids = $wpdb->get_col( "SELECT rid FROM {$wpdb->prefix}icl_translation_status WHERE translation_id NOT IN (SELECT translation_id FROM {$wpdb->prefix}icl_translations)" );
$jids = $wpdb->get_col( "SELECT job_id FROM {$wpdb->prefix}icl_translate_job WHERE rid IN (" . wpml_prepare_in( $rids, '%d' ) . ")" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translate WHERE job_id IN (" . wpml_prepare_in( $jids, '%d' ) . ")" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translate_job WHERE job_id IN (" . wpml_prepare_in( $jids, '%d' ) . ")" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translation_status WHERE rid IN (" . wpml_prepare_in( $rids, '%d' ) . ")" );
// remove any duplicates in icl_translations
$trs = $wpdb->get_results( "SELECT element_id, GROUP_CONCAT(translation_id) AS tids FROM {$wpdb->prefix}icl_translations
WHERE element_id > 0 AND element_type LIKE 'post\\_%' GROUP BY element_id" );
$exp = explode( ',', $r->tids );
if ( count( $exp ) > 1 ) {
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'before_delete' ) ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $e ) );
do_action( 'wpml_translation_update', array_merge( $upgrade_args, array( 'type' => 'after_delete' ) ) );
case 'assign_translation_status_to_duplicates':
$updated_items = WPML\Troubleshooting\AssignTranslationStatusToDuplicates::run();
echo json_encode( array( 'updated' => $updated_items ) );
case 'icl_ts_add_missing_language':
global $iclTranslationManagement;
$iclTranslationManagement->add_missing_language_information();
$old_el_type = 'post_' . sanitize_key ( filter_input ( INPUT_GET, 'old_value' ) );
$new_el_type = 'post_' . sanitize_key ( filter_input ( INPUT_GET, 'new_value' ) );
$wpdb->prefix . 'icl_translations',
array( 'element_type' => $new_el_type ),
array( 'element_type' => $old_el_type )
'wpml_translation_update',
'type' => 'element_type_update',
'element_type' => $new_el_type,
$new_el_type = 'tax_' . $_GET[ 'new_value' ];
$old_el_type = 'tax_' . $_GET[ 'old_value' ];
$wpdb->prefix . 'icl_translations',
array( 'element_type' => $new_el_type ),
array( 'element_type' => $old_el_type ) );
'wpml_translation_update',
'type' => 'element_type_update',
'element_type' => $new_el_type,
case 'icl_fix_terms_count':
$has_get_terms_args_filter = remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ) );
$has_get_term_filter = remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1 );
$has_terms_clauses_filter = remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
foreach ( get_taxonomies( array(), 'names' ) as $taxonomy ) {
$terms_objects = get_terms( $taxonomy, 'hide_empty=0' );
$term_taxonomy_ids = array_map( 'get_term_taxonomy_id_from_term_object', $terms_objects );
wp_update_term_count( $term_taxonomy_ids, $taxonomy, true );
if ( $has_terms_clauses_filter) {
add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 3 );
if ( $has_get_term_filter ) {
add_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1, 1 );
if ( $has_get_terms_args_filter ) {
add_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 );
case 'icl_remove_st_db_cache_logs' :
delete_option( 'wpml-st-persist-errors' );
(string)filter_input( INPUT_POST, 'icl_reset_allnonce' ),
if ( $_POST[ 'icl-reset-all' ] == 'on' ) {
echo '<script type="text/javascript">location.href=\'' . admin_url(
'plugins.php?deactivate=true'
<h2><?php echo __( 'Troubleshooting', 'sitepress' ) ?></h2>
<?php if ( isset( $_GET[ 'message' ] ) ){ ?>
<div class="updated message fade"><p>
<?php echo esc_html( $_GET[ 'message' ] ); ?>
echo '<a href="#wpml-settings">' . __( 'WPML Settings', 'sitepress' ) . '</a>';
echo '<br /><hr /><h3 id="wpml-settings"> ' . __( 'WPML settings', 'sitepress' ) . '</h3>';
echo '<textarea style="font-size:10px;width:100%" wrap="off" rows="16" readonly="readonly">';
print_r( $sitepress->get_settings() );
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#icl_troubleshooting_more_options').submit(iclSaveForm);
<script type="text/javascript">
function wpml_ts_link_post_type(select, old_value) {
if (!select.val()) return;
select.attr('disabled', 'disabled');
select.after(icl_ajxloaderimg);
jQuery.post(location.href + '&debug_action=link_post_type&nonce=<?php echo wp_create_nonce('link_post_type'); ?>&new_value=' + select.val() + '&old_value=' + old_value, function () {
alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
function wpml_ts_link_taxonomy(select, old_value) {
if (!select.val()) return;
select.attr('disabled', 'disabled');
select.after(icl_ajxloaderimg);
jQuery.post(location.href + '&debug_action=link_taxonomy&nonce=<?php echo wp_create_nonce('link_taxonomy'); ?>&new_value=' + select.val() + '&old_value=' + old_value, function () {
alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
function parse_xhr_error(xhr, status, error) {
return xhr.statusText || status || error;
jQuery(document).ready(function ($) {
$('#otgs_twig_cache_enable').find('.button-secondary').on('click', function () {
jQuery(this).attr('disabled', 'disabled');
jQuery(this).after(icl_ajxloaderimg);
var value = jQuery(this).parent().find('.otgs_twig_cache_new_value').val();
var key = '<?php echo $otgs_twig_cache_disable_key ?>';
'debug_action': 'otgs_twig_cache_enable',
'nonce': '<?php echo wp_create_nonce( 'otgs_twig_cache_enable' ); ?>',
alert('<?php echo esc_js( __( 'Done', 'sitepress' ) ) ?>');
jQuery('#icl_fix_languages').click(function () {
jQuery(this).attr('disabled', 'disabled');
jQuery(this).after(icl_ajxloaderimg);
var icl_fix_languages = jQuery('#icl_fix_languages');
contentType: "application/json; charset=utf-8",
url: location.href + '&debug_action=fix_languages&nonce=<?php echo wp_create_nonce('fix_languages'); ?>',
icl_fix_languages.removeAttr('disabled');
alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
icl_fix_languages.next().fadeOut();
error: function (jqXHR, status, error) {
var parsed_response = parse_xhr_error(jqXHR, status, error);
$timeout_message = 'The operation timed out, but languages may still get fixed in the background.\n';
$timeout_message .= 'Please wait 5-10 minutes, then refresh or come back to this page.\n';
$timeout_message .= 'If languages are still not fixed, please retry or contact the WPML support.'
if(parsed_response=='timeout') {
alert('<?php echo __($timeout_message, 'sitepress');?>');
icl_fix_languages.next().fadeOut();
jQuery('#icl_remove_ghost').click(function () {
self.attr('disabled', 'disabled');
self.after(icl_ajxloaderimg);
jQuery.post(location.href + '&debug_action=ghost_clean&nonce=<?php echo wp_create_nonce('ghost_clean'); ?>', function () {
self.removeAttr('disabled');
alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
// #assign_translation_status_to_duplicates_resp: BEGIN
var assign_translation_status_to_duplicates_loader = jQuery(icl_ajxloaderimg);
var assign_translation_status_to_duplicates_cycles = 0;
var assign_translation_status_to_duplicates_updated = 0;
var response_element = jQuery('#assign_translation_status_to_duplicates_resp');
var assign_translation_status_to_duplicates_element = jQuery('#assign_translation_status_to_duplicates');
assign_translation_status_to_duplicates_element.click(function () {
assign_translation_status_to_duplicates();
function assign_translation_status_to_duplicates() {
if (assign_translation_status_to_duplicates_cycles == 0) {
assign_translation_status_to_duplicates_element.attr('disabled', 'disabled');
response_element.text('');
assign_translation_status_to_duplicates_element.after(assign_translation_status_to_duplicates_loader);
assign_translation_status_to_duplicates_cycles++;
contentType: "application/json; charset=utf-8",
url: location.href + '&debug_action=assign_translation_status_to_duplicates&nonce=<?php echo wp_create_nonce('assign_translation_status_to_duplicates'); ?>',
success: function (msg) {
assign_translation_status_to_duplicates_updated += msg.updated;
response_message = assign_translation_status_to_duplicates_updated + ' <?php echo esc_js(_x('translation jobs updated', 'Sets the translation status to DUPLICATE in the icl_translation_status table, for posts that are marked as duplicated', 'sitepress')); ?>';
if (assign_translation_status_to_duplicates_cycles >= 50) {
response_message += '. <?php echo esc_js(_x('Partially done.', 'Sets the translation status to DUPLICATE in the icl_translation_status table, for posts that are marked as duplicated','sitepress')) ?>';
response_message += '. <?php echo esc_js(_x('There might be more content to fix: please repeat the process.', 'Sets the translation status to DUPLICATE in the icl_translation_status table, for posts that are marked as duplicated','sitepress')) ?>';
response_element.text(response_message);
alert('<?php echo esc_js(_x('Partially done', 'Sets the translation status to DUPLICATE in the icl_translation_status table, for posts that are marked as duplicated', 'sitepress')) ?>');
response_element.fadeOut();
assign_translation_status_to_duplicates_loader.fadeOut(function() {
assign_translation_status_to_duplicates_element.remove(assign_translation_status_to_duplicates_loader);
assign_translation_status_to_duplicates_element.removeAttr('disabled');
assign_translation_status_to_duplicates_cycles = 0;
assign_translation_status_to_duplicates_updated = 0;
response_message += ' ...';
response_element.text(response_message);
assign_translation_status_to_duplicates();
if (assign_translation_status_to_duplicates_updated != 0) {
response_message += assign_translation_status_to_duplicates_updated + '.';
response_message += '<?php echo esc_js(__('Done', 'sitepress')) ?>';
response_element.text(response_message);