Skip to content

Instantly share code, notes, and snippets.

@kemenaran
Last active February 16, 2022 11:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kemenaran/a9a52d516ac556a57058fab7dcc8f92b to your computer and use it in GitHub Desktop.
Save kemenaran/a9a52d516ac556a57058fab7dcc8f92b to your computer and use it in GitHub Desktop.
Script to fix ColibriWP serialization errors
<?php
/**
* Plugin Name: ColibriWP Fix Options
*
* How to use:
*
* 1. Put this file inside the wp-content/plugins/ directory;
* 2. In the Wordpress Dashboard, navigate to the Extensions page;
* 3. Enable the "ColibriWP Fix Options" extension;
* 4. Load any page with a `colibriwp-try-fix-serialization` GET parameter.
* For instance, `https://www.your-wordpress-site.com/index.php?colibriwp-try-fix-serialization=true`
*/
function fix_str_length($matches) {
$string = $matches[2];
$right_length = strlen($string); // yes, strlen even for UTF-8 characters, PHP wants the mem size, not the char count
return 's:' . $right_length . ':"' . $string . '";';
}
function extendthemes_fix_serialized($string)
{
// securities
if (!preg_match('/^[aOs]:/', $string)) return $string;
if (@unserialize($string) !== false) return $string;
$string = preg_replace("%\n%", "", $string);
// doublequote exploding
$data = preg_replace('%";%', "µµµ", $string);
$tab = explode("µµµ", $data);
$new_data = '';
foreach ($tab as $line) {
$new_data .= preg_replace_callback('%\bs:(\d+):"(.*)%', 'fix_str_length', $line);
}
return $new_data;
}
function get_option_raw($option) {
global $wpdb;
$suppress = $wpdb->suppress_errors();
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
$wpdb->suppress_errors( $suppress );
return $row->option_value;
}
add_action('init', function () {
if (isset($_REQUEST['colibriwp-try-fix-serialization'])) {
$x = get_option_raw( 'extend_builder_theme');
if (is_string($x)) {
$x = preg_replace('#\r?\n#', " ", $x);
$x = extendthemes_fix_serialized($x);
$y = unserialize($x);
if(is_array($y)){
update_option('extend_builder_theme', $y);
var_dump($y);
} else {
wp_die( 'Au au' );
}
}
}
});
@douce2323
Copy link

Jai presque le même problème est je n'arrive pas a le résoudre je sais que c'est le plugin colibri que pose problème:
Fatal error: Uncaught TypeError: array_replace_recursive(): Argument #2 must be of type array, null given in C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\theme-data.php:213 Stack trace: #0 C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\theme-data.php(213): array_replace_recursive(Array, NULL) #1 C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\theme-data.php(143): ExtendBuilder\get_theme_data() #2 C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\theme-data.php(41): ExtendBuilder\get_plugin_option('css_by_partials...') #3 C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\data.php(254): ExtendBuilder\get_colibri_options() #4 C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\theme-data.php(199): ExtendBuilder\get_current_data(-1, true) #5 C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\theme-data.php(224): ExtendBuilder\get_theme_data('colors', true, Array) #6 C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\gutenberg.php(6): ExtendBuilder\get_current_theme_data('colors', Array) #7 C:\xampp\htdocs\medic\wp-includes\class-wp-hook.php(307): ExtendBuilder{closure}('') #8 C:\xampp\htdocs\medic\wp-includes\class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array) #9 C:\xampp\htdocs\medic\wp-includes\plugin.php(474): WP_Hook->do_action(Array) #10 C:\xampp\htdocs\medic\wp-settings.php(565): do_action('after_setup_the...') #11 C:\xampp\htdocs\medic\wp-config.php(98): require_once('C:\xampp\htdocs...') #12 C:\xampp\htdocs\medic\wp-load.php(50): require_once('C:\xampp\htdocs...') #13 C:\xampp\htdocs\medic\wp-admin\admin.php(34): require_once('C:\xampp\htdocs...') #14 C:\xampp\htdocs\medic\wp-admin\index.php(10): require_once('C:\xampp\htdocs...') #15 {main} thrown in C:\xampp\htdocs\medic\wp-content\plugins\colibri-page-builder\extend-builder\data\theme-data.php on line 213
si une personne aurais une idéé

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment