[wp-hackers] Subject: change siteurl at DB level

Otto otto at ottodestruct.com
Wed Aug 25 00:15:40 UTC 2010


I once changed the maybe_unserialize function specifically to handle
this case. I know it's bad to modify core like that, but this was for
a one-off.

function maybe_unserialize( $original ) {
  if ( is_serialized( $original ) ) {
    $fixed = preg_replace_callback (
'!(?<=^|;)s:(\d+)(?=:"(.*?)";(?:}|a:|s:|b:|i:|o:|N;))!s',
'serialize_fix_callback', $original );
    return @unserialize( $fixed );
  }
  return $original;
}

function serialize_fix_callback($match) { return 's:' . strlen($match[2]); }

Worked for me then. Might be useful for somebody.

-Otto



On Tue, Aug 24, 2010 at 6:52 PM, David McDonald <info at davidmcdonald.org> wrote:
> Yes, serialised data needs to be taken into account when changing the
> site URL in a WP database.
> This most likely is the cause of missing widgets, as I have found some
> of the widget data to be serialised.
>
> This script enables a search & replace including serialised data:
>
>  http://spectacu.la/search-and-replace-for-wordpress-databases/
>
> I have used it numerous times and from my experience it works very well.


More information about the wp-hackers mailing list