[wp-hackers] [GSOC2010]WPmove [wpurl] tag replace

Otto otto at ottodestruct.com
Thu Apr 8 15:17:28 UTC 2010


On Thu, Apr 8, 2010 at 9:23 AM, Piyush Mishra <admin at oxymaniac.com> wrote:
> I beg to differ, I tried printing the array out to my local server

Huh. I'll be darned, you're right. I know it has worked for me before,
but with a simple test I can't make it work again.

Still, it's possible to add code to WP to fix that easily enough. If
you alter the maybe_unserialize function in wp-includes/functions.php
to the following, then the string lengths won't matter any more.


function maybe_unserialize( $original ) {
	if ( is_serialized( $original ) ) // don't attempt to unserialize
data that wasn't serialized going in
	{
		$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]); }


Test that shows it works:
$a ='a:2:{i:0;s:123:"Test";i:1;s:456:"Fake";}';

var_dump(maybe_unserialize($a));


-Otto


More information about the wp-hackers mailing list