You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this particular case, $schedule_number must be a number because in line 393 it is being multiplied. I'm not sure if it is a PHP8 thing, but you cannot multiple an int ($seconds) by a string (empty or otherwise). $schedule_number must be a positive int, just casting isn't enough, absint should cover it.
How do I test this Pull Request?
I only noticed this on a blank WP install, if you turn logging on it'll throw a fatal as no schedules have ever been set.
@federicojacobi thanks for the pull request. I'm happy to merge it when I get a bit of time to look over it (nobody is currently working on the plugin, but I try to keep an eye on it when I can).
If I'm reading it correctly, it should be possible to use $schedule_number = filter_var( get_option( $this->option_prefix . 'logs_how_often_number', '' ), FILTER_VALIDATE_INT ); instead of absint, right? I'm asking just because that is much more commonly what this codebase does, so it makes sense to me to try to keep it consistent if possible.
@jonathanstegall yes, it would almost be the same thing. filter_var in your example would allow negative numbers where absint wouldn't, but it would be difficult to get that option to be negative to begin with. So yeah, it is basically the same thing.
Personally, I find absint more readable, but if you are striving for consistency ... 👍🏽
jonathanstegall
changed the title
Prevent error on blank WordPress install caused by a string instead of an integer
Prevent error on blank WordPress install caused by a string instead of an integer. Thanks to GitHub user @federicojacobi for the pull request.
May 18, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bug fixPull request that fixes a bugpatchpull request that requires a patch release, ex v2.1.2. This is the default for new releases.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this Pull Request do?
In this particular case,
$schedule_numbermust be a number because in line 393 it is being multiplied. I'm not sure if it is a PHP8 thing, but you cannot multiple an int ($seconds) by a string (empty or otherwise).$schedule_numbermust be a positive int, just casting isn't enough,absintshould cover it.How do I test this Pull Request?
I only noticed this on a blank WP install, if you turn logging on it'll throw a fatal as no schedules have ever been set.