Opened 10 years ago
Last modified 6 years ago
#37635 new defect (bug)
BUG in get_option
| Reported by: | tazotodua | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Options, Meta APIs | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
in wp_options, i had saved this large serialized string:
http://pastebin.com/raw/hxwETuHX
however, when i run get_option("option_name") it returns false...
i have spent time and found out, that it's because that get_option tries to unserialize it and return the result, but it have problems while unserializing.
then i decided to manually grab the value and unserialize by hand.. and i succeeded!
$raw_data=$wpdb->get_var("Select option_value from wp_options Where option_name='option_name'"); unserialize(Serialized_Fixer($raw_data)); function Serialized_Fixer($serialized_string){ // securities if ( !preg_match('/^[aOs]:/', $serialized_string) ) return $serialized_string; if ( @unserialize($serialized_string) !== false ) return $serialized_string; return preg_replace_callback( '/s\:(\d+)\:\"(.*?)\";/s', function ($matches){ return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; }, $serialized_string ) ; }
and that worked!
this is seriously a bug of WP!
please fix it! thanks!
Change History (7)
#2
follow-up:
↓ 6
@
10 years ago
- Component General → Options, Meta APIs
Could not reproduce, this test script displays correct data on my install:
require 'wp-load.php'; $content = file_get_contents( 'http://pastebin.com/raw/hxwETuHX' ); $content = unserialize( $content ); add_option( 'get_option_unserialize_test', $content ); var_dump( get_option( 'get_option_unserialize_test' ) ); delete_option( 'get_option_unserialize_test' );
What is the DB_CHARSET value in your wp-config.php file and the actual DB charset?
This appears to be a misconfiguration issue like in #21109 or ticket:6784:3.
#5
@
10 years ago
@swissspidy well, actually I've made mistake while I gave the example data above. As it's english, it doesnt have problem, but here is actual example of get_option value (serialized, saved in phpmyadmin): http://pastebin.com/raw/i4YVxKpK
please, try your above method same this data.
p.s. what's interesting, the get_option for that data works on my Production website, but on localhost it doesnt work (returns false).
the DB are both InnoDB (latin1_swedish_ci) and tables are both utf8mb4_unicode_ci.
what's more, wp-config are same for both.
#6
in reply to: ↑ 2
@
9 years ago
Replying to SergeyBiryukov:
@swissspidy well,
please, try your above method this data - http://pastebin.com/raw/i4YVxKpK
p.s. what's interesting, the get_option for that data works on my Production website, but on localhost it doesnt work (returns false).
the DB are both InnoDB (latin1_swedish_ci) and tables are both utf8mb4_unicode_ci.
what's more, wp-config are same for both.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
sorry for bad formatting, but you will understand my explanation. You should
var_dumpthe unserialized result.