Use wp_get_ready_cron_jobs() for --due-now to apply core filter
#89
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