Skip to content

Instantly share code, notes, and snippets.

@pbogdan
Created October 21, 2015 15:48
Show Gist options
  • Save pbogdan/9827a8f2358cf9e8ca71 to your computer and use it in GitHub Desktop.
Save pbogdan/9827a8f2358cf9e8ca71 to your computer and use it in GitHub Desktop.
<?php
define('DISABLE_WP_CRON', true);
require_once "wp-load.php";
add_filter("pre_get_table_charset", "fail_in_get_table_charset", 10);
/*
simulate possible failure in
https://github.com/WordPress/WordPress/blob/4.3.1/wp-includes/wp-db.php#L2306-L2308,
but only when invoked from sanitize_option()
*/
function fail_in_get_table_charset()
{
$trace = debug_backtrace();
foreach ($trace as $call) {
if ($call["function"] == "sanitize_option") {
return new WP_Error( 'wpdb_get_table_charset_failure' );
}
}
return null;
}
$opt = get_option("siteurl");
echo "- Original siteurl value: \n\n";
var_dump($opt);
echo "\n";
update_option("siteurl", $opt);
echo "- After updating with a failure in get_table_charset: \n\n";
var_dump(get_option("siteurl"));
echo "\n";
remove_filter("pre_get_table_charset", "fail_in_get_table_charset", 10);
// revert things back to allow for easy re-running
update_option("siteurl", $opt);
echo "- After updating with without failure in get_table_charset: \n\n";
var_dump(get_option("siteurl"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment