WordPress.org

Make WordPress Core

Opened 7 years ago

Last modified 18 months ago

#27804 new defect (bug)

bug when updating after domain change settings

Reported by: robomotic Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.2
Component: Administration Keywords: dev-feedback
Focuses: Cc:

Description

I have found the following bug that affects for sure wordpress 3.8.2 and the latest 3.8.3.
I have noticed this bug when I changed my domain settings:
WordPress Address (URL) and Site Address (URL) from a domain say www.mydomain.org to www.mydomain.com.
In the admin panel, when I get notified of new updates to be installed, installation of wordprewss, plugins and themes seems successful but is not performed.
After a bit of banging my head on the problem, for curiosity decided to switch back to www.mydomain.org and all updates were installed!
It's a bit annoying doing this procedure for every new updates.

Can anybody reproduce this?

Change History (2)

#1 @Denis-de-Bernardy
7 years ago

  • Keywords reporter-feedback added

It's not very clear what you're meaning or highlighting in the ticket.

To be very honest though, WordPress isn't really designed to allow to change the site and WP URLs. There admittedly is UI (and even two defines) to do so but, frankly, changing either or both has been a can of worms for as long as I can remember. Key problems:

  • Changing the WP URL is likely to log you out
  • URLs in existing posts don't change when the site URL is updated
  • Using www. in one URL but not the other can lock you out of the admin area due to infinite redirects

And don't even get me started on multisite-related problems, WP in its subfolder-related problems, and yada yada.

Below is a quick and dirty script I recently used to migrate a client's site from using www3 to www, to give you an idea of the kind of mess it can be. And it only began to scratch the surface, as I didn't want to clean up the other tables.

#!/usr/bin/env php
<?php
function override_plugins($plugins) {
    return array();
}
function override_theme($theme) {
    return 'notheme';
}
$wp_filter = array();
$wp_filter['option_active_plugins'][PHP_INT_MAX]['override_plugins'] = array(
    'function'      => 'override_plugins',
    'accepted_args' => 1,
);
$wp_filter['template'][PHP_INT_MAX]['override_theme'] = array(
    'function'      => 'override_theme',
    'accepted_args' => 1,
);
$wp_filter['stylesheet'][PHP_INT_MAX]['override_theme'] = array(
    'function'      => 'override_theme',
    'accepted_args' => 1,
);
require_once __DIR__.'/../www/wp-load.php';
require_once __DIR__.'/../www/wp-admin/includes/post.php';


#
# Catch all errors
#
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");


#
# www3 converter
#
function convert_www3_to_www($value) {
    if (is_string($value)) {
        $value = str_replace('www3.example.com', 'www.example.com', $value);
    }
    elseif (is_array($value)) {
        foreach ($value as $key => $val) {
            $value[$key] = convert_www3_to_www($val);
        }
    }
    elseif (is_object($value)) {
        foreach (get_object_vars($value) as $key) {
            $value->$key = convert_www3_to_www($value->$key);
        }
    }
    return $value;
}

#
# Clean up Lee's garbage
#
$query = <<<EOS
SELECT  option_name
FROM    $wpdb->options
WHERE   option_value LIKE '%Users/lee/Sites%'
OR      option_value LIKE '%local.example.com%'
EOS;
$refs = $wpdb->get_col($query);

foreach ($refs as $name) {
    echo "delete option $name\n";
    delete_option($name);
}


#
# Convert www3 to www in options
#
$query = <<<EOS
SELECT  option_name
FROM    $wpdb->options
WHERE   option_value LIKE '%www3.example.com%'
EOS;
$refs = $wpdb->get_col($query);

foreach ($refs as $name) {
    $value = get_option($name);
    $value = convert_www3_to_www($value);
    echo "update option $name\n";
    update_option($name, $value);
}


#
# Convert www3 to www in posts
#
$query = <<<EOS
SELECT  ID
FROM    $wpdb->posts
WHERE   post_content LIKE '%www3.example.com%'
OR      post_excerpt LIKE '%www3.example.com%'
OR      post_title   LIKE '%www3.example.com%'
EOS;
$refs = $wpdb->get_col($query);

foreach($refs as $id) {
    $post = get_post($id);
    $post->post_title   = convert_www3_to_www($post->post_title);
    $post->post_content = convert_www3_to_www($post->post_content);
    $post->post_excerpt = convert_www3_to_www($post->post_excerpt);
    echo "update post $id\n";
    wp_update_post($post);
}


#
# Convert www3 to www in postmeta
#
$query = <<<EOS
SELECT  post_id, meta_key, count(distinct post_id) = 1 as single
FROM    $wpdb->postmeta
WHERE   meta_value LIKE '%www3.example.com%'
GROUP BY meta_key
EOS;
$refs = $wpdb->get_results($query);

foreach ($refs as $ref) {
    $value = get_post_meta($ref->post_id, $ref->meta_key, (bool) $ref->single);
    $value = convert_www3_to_www($value);
    echo "update post meta $ref->post_id $ref->meta_key\n";
    update_post_meta($ref->post_id, $ref->meta_key, $value);
}
Last edited 7 years ago by Denis-de-Bernardy (previous) (diff)

#2 @chriscct7
5 years ago

  • Keywords dev-feedback added; reporter-feedback removed
Note: See TracTickets for help on using tickets.