Monday 4 January 2016

WordPress Hosting Tips: How to Serialized data fix in WordPress?

Leave a Comment
There is many solutions for Serialized data fix in WordPress problem over the internet, but none of them are solving the problem automatically or without editing the WordPress core. Now, i came up with the solution for this problem for Ether Builder plugin.

So, write the following code :
add_filter('get_post_metadata', 'ether_serialize_fix', 10, 4);
function meta_serialize_fix($null, $object_id, $meta_key, $single)
{
$meta_type = 'post';

if ($meta_key == 'YOUR_META_KEY')
{
$meta_cache = wp_cache_get($object_id, $meta_type.'_meta');

if ( ! $meta_cache)
{
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}

if (isset($meta_cache[$meta_key]))

{
if ($single)
{
    if (is_serialized($meta_cache[$meta_key][0]) AND ! maybe_unserialize($meta_cache[$meta_key][0]))
    {
        return array(maybe_unserialize_fixed($meta_cache[$meta_key][0]));
    }
} else
{
    foreach ($meta_cache[$meta_key] as $k => $v)
    {
        if (is_serialized($v) AND ! maybe_unserialize($v))
        {
            return array_map('maybe_unserialize_fixed', $meta_cache[$meta_key]);
        }
    }
}
}
}
}

add_filter('option_OPTION_NAME', 'option_serialize_fix', 10, 1);

function option_serialize_fix($option, $value)
{
if (is_serialized($value) AND ! maybe_unserialize($value))
{
return maybe_unserialize_fix($value);
}
}

function maybe_unserialize_fixed($data)
{
return maybe_unserialize(preg_replace('!s:(\d+):"(.*?)";!e',"'s:'.strlen('$2').':\"$2\";'", $data));
}


Keep in mind that using this for every meta key / option name is not a good idea. Use conditional tag instead.

Best WordPress Hosting Recommendation

One of the most important things when choosing a good WordPress hosting is the feature and reliability. HostForLIFE is the leading provider of Windows hosting and affordable WordPress, their servers are optimized for PHP web applications such as the latest WordPress version. The performance and the uptime of the hosting service are excellent and the features of the web hosting plan are even greater than what many hosting providers ask you to pay for. 

At HostForLIFE.eu, customers can also experience fast WordPress hosting. The company invested a lot of money to ensure the best and fastest performance of the datacenters, servers, network and other facilities. Its datacenters are equipped with the top equipments like cooling system, fire detection, high speed Internet connection, and so on. That is why HostForLIFE.eu guarantees 99.9% uptime for WordPress. And the engineers do regular maintenance and monitoring works to assure its WordPress hosting are security and always up. 

http://hostforlifeasp.net

0 comments:

Post a Comment