Use wp_get_ready_cron_jobs() for --due-now to apply core filter#89
Merged
danielbachhuber merged 3 commits intowp-cli:mainfrom Dec 13, 2022
Merged
Use wp_get_ready_cron_jobs() for --due-now to apply core filter#89danielbachhuber merged 3 commits intowp-cli:mainfrom
wp_get_ready_cron_jobs() for --due-now to apply core filter#89danielbachhuber merged 3 commits intowp-cli:mainfrom
Conversation
Member
danielbachhuber
left a comment
There was a problem hiding this comment.
Couple of small nits but looks good to me overall. Thanks for sticking with this!
Contributor
Author
|
I have made the changes with your suggestions and it looks much better. I upload new PR with that changes ! |
Contributor
|
@josedumas Please reopen this PR. |
wp_get_ready_cron_jobs() for --due-now to apply core filter
danielbachhuber
approved these changes
Dec 13, 2022
Member
danielbachhuber
left a comment
There was a problem hiding this comment.
Great work on this, @josedumas !
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is to resolve the enhancement so that wp_get_ready_cron_jobs() is used.
I have decided to add a control flag and not refactor two methods for not adding extra code, although it may be formally better to apply 2 different methods.
I have come across the problem that the get_cron_events method returns an error if the $crons array is empty, and this can happen just with wp_get_ready_cron_jobs. Therefore, in order to pass the functional tests, I have added the one that checks that the array is empty only when we are not in the "--due-now" situation.
I have performed the functional tests and they are correct. But I understand that it may be a bad practice to add a control flag. I have justified above the reason for the decision.
Another alternative that I have ruled out is to simply call the pre_get_ready_cron_jobs filter inside the get_cron_events method. This solution would have the advantage of not adding this flag, but we would still have the hidden problem that the result of the filter could return an empty array and therefore would not pass the functional tests (although in my tests it does). I will upload it in another branch in my repository (with_apply_filter)
Fixes #86