get_option()
always returns a string. That has nothing to do with whether setlocale()
has been used. Options are all stored in the option_value
column of wp_options
, which is a text column. Your float is likely being formatted for your locale when it tries to insert a float into the text column.
Your problem is that you’re treating version numbers as floats, which is incorrect. They might look like floats, but version numbers are strings. For example, a float 5.2
is higher than 5.15
, but 5.15
is a higher version number than 5.2
.
So you can’t compare version numbers by using <
or >
on floats. You need to use strings, and version_compare()
to compare them. So first make sure to set the value as a string:
update_option( 'my_db_version', '5.13' );
Also note that db_version
is an option already used by WordPress core, you need to prefix your options with something unique to your project.
Then you can compare the values like this:
$current_version = get_option( 'my_db_version' );
$new_version = '5.39'; // String
// If the current version is lower than the new version...
if ( version_compare( $current_version, $new_version ) < 0 ) {
// ...update to the new version.
update_option( 'my_db_version', $new_version );
}