Unserialize() warning caused by make_link_local() in live-link-helper.php

Bug Summary

Local / MacBookPro / Life link on any browser

Steps to reproduce

nothing spécial

Environment Info

Last OS on macbook pro, WP 7 , Divi5,

Supporting info

Bug: unserialize() warning caused by make_link_local() in live-link-helper.php

When using Live Links, a PHP warning appears at the top of every page:

Warning: unserialize(): Error at offset 5489 of 5512 bytes in .../local-by-flywheel-live-link-helper.php on line 198

Root cause:
In the make_link_local() method, when the option is not a string, the code:

  1. Serializes the value with serialize()
  2. Replaces the URL via string replacement (which changes string lengths)
  3. Calls unserialize() on the result

Step 3 fails because PHP serialization uses byte-length prefixes (s:XX:) that are no longer correct after the URL replacement.

Fix:
Replace the serialize/unserialize cycle with a recursive traversal that replaces URLs directly in strings, without touching serialization:

public function make_link_local( $option ) {
    if ( gettype( $option ) !== 'string' ) {
        return $this->replace_host_in_value( $this->get_tunnel_host(), $this->home_domain, $option );
    }
    return $this->replace_host( $this->get_tunnel_host(), $this->home_domain, $option );
}

private function replace_host_in_value( $from, $to, $data ) {
    if ( is_array( $data ) ) {
        foreach ( $data as $key => $value ) {
            $data[ $key ] = $this->replace_host_in_value( $from, $to, $value );
        }
    } elseif ( is_object( $data ) ) {
        foreach ( get_object_vars( $data ) as $key => $value ) {
            $data->$key = $this->replace_host_in_value( $from, $to, $value );
        }
    } elseif ( is_string( $data ) ) {
        $data = $this->replace_host( $from, $to, $data );
    }
    return $data;
}

This fix has been tested and resolves the warning completely.

Environment: macOS, Local 9.x, PHP 8.x, WordPress 7 with Divi theme + Complianz plugin.

Hi @ericFabre!

If you test using Live Links on a new, blank site in Local do you get the same error/warning? Or is it only replicable with the specific site configuration as you laid out? (Local 9.x, PHP 8.x, WordPress 7 with Divi theme + Complianz plugin).

Can you also try updating to the latest Local v10.1.0?

Hello. My Local is : Version 10.1.0+6912 The bug remain after install new version. My solution is ok but the new install delete it.

The bug is only in one web site… so .. no worries. I can give you the link in a PM if you need.

Thank you for confirming that it’s site specific @ericFabre! We don’t believe this is a bug in Live Links itself since the key indicator is that Live Links works fine on a blank site. It seems that Live Links is encountering serialized data in your options table that’s already malformed before it touches it. When it tries to do a URL replacement and then unserialize the result, the byte-length prefixes are out of sync and PHP throws the warning.

This kind of corruption could be due to the Complianz plugin or Divi theme options framework that stored data in a non-standard way at some point. If the warning isn’t causing any real functional issues for you, sticking with your manual workaround might be the way to go for now!