• Bug report:

    https://plugins.trac.wordpress.org/browser/ninja-forms/tags/3.8.20/ninja-forms.php#L541

    ^ This line attempts to set the ninja_forms_needs_updates option as integer 0. 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 when update_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:

    UPDATE wp_options
    SET option_value = '0'
    WHERE option_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.

    • This topic was modified 1 year, 4 months ago by David Sword.
    • This topic was modified 1 year, 4 months ago by David Sword.

    The page I need help with: [log in to see the link]

The topic ‘Fix type juggling error’ is closed to new replies.