<?php


//var_dump($_POST);

    if(isset($_POST['changeNDD']) && !empty($_POST['changeNDD'])
        && isset($_POST['hiddenScript']) && !empty($_POST['hiddenScript'])){

       /* $tabPostTpyesToRemove = array('attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block');

        $tabPostTpyes = get_post_types();

        foreach($tabPostTpyesToRemove as $postType){
            unset($tabPostTpyes[$postType]);
        }*/

        global $wpdb;

        $wpdb->query(" UPDATE {$wpdb->prefix}posts SET post_content = replace(post_content, '".$_POST['oldNDD']."', '".$_POST['newNDD']."')");
        $wpdb->query(" UPDATE {$wpdb->prefix}posts SET guid = replace(guid, '".$_POST['oldNDD']."', '".$_POST['newNDD']."')");
        var_dump('Requete executee:');
        var_dump($wpdb->last_query);
        var_dump('Booleen Erreur:');
        var_dump($wpdb->show_errors);
        var_dump('Derniere erreur:');
        var_dump($wpdb->last_error);


    }

?>


<form method="post" action="">
    <input type="hidden" name="hiddenScript" value="changementNDD" />
    <label for="oldNDD">Chercher dans le contenu:</label>
    <input type="text" size="32" name="oldNDD" id="oldNDD" placeholder="Ancien NDD" required />
    <label for="newNDD">Remplacer par: </label>
    <input type="text" size="32" name="newNDD" id="newNDD" placeholder="Nouveau NDD" required />
    <br />
    <button type="submit" class="btn btn-primary" value="changeNDD" name="changeNDD" onclick="return confirm('Etes-vous sûr des valeurs?\r Une erreur pourrait compromettre le contenu du site');">Changer le nom de domaine</button>
</form>
