Fix type juggling error
-
Bug report:
^ This line attempts to set the
ninja_forms_needs_updatesoption as integer0. There’s no code checking for the value before updating, so I believe the assumption is that this option will only actually update if the new value differs – however whenupdate_option()does its old isn’t new check here https://github.com/WordPress/WordPress/blob/c08c2e28cc77324f17f23ac0fcbfc786fd98524a/wp-includes/option.php#L906-L917 the old value is a string ('0'), and the new value an int (0), so the db write continues and occurs on every wp-admin request.Type juggling example:
wp> update_option('testing', 0); // int
=> bool(true)
wp> get_option('testing');
=> string(1) "0"This leads to the update option write being done on every wp-admin request:
UPDATEwp_options
SEToption_value= '0'
WHEREoption_name= 'ninja_forms_needs_updates'^ this db write can be seen in wp-admin requests with a tool like query monitor.
This can be patched in current and old versions by fixing the type juggling:
add_filter('pre_update_option_ninja_forms_needs_updates', function( $value, $old_value ) {
return ( $value === 0 && $old_value === '0') ? '0' : $value;
}, 10, 2 );But the type juggling should be fixed in the plugin, by either checking the value before updating, or using a string value zero
'0'instead.The page I need help with: [log in to see the link]
The topic ‘Fix type juggling error’ is closed to new replies.