WordPress / WordPress/WordPress-Coding-Standards
Namespaced cron_schedules callbacks not detected
Open
Nobody has claimed this yet.
Type: Bug
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Bug Description
The WordPress.WP.CronInterval sniff is producing a warning when a namespaced callback is used: "Detected changing of cron_schedules, but could not detect the interval value."
Minimal Code Snippet
namespace Foo {
function my_add_every_hour( $schedules ) {
$schedules['every_hour'] = [
'interval' => HOUR_IN_SECONDS,
'display' => __( 'Once every hour' )
];
return $schedules;
}
add_filter( 'cron_schedules', __NAMESPACE__ . '\my_add_every_hour'); // OK: > 10 min.
}
Environment
| Question | Answer |
|---|---|
| PHP version | 7.2.23 |
| PHP_CodeSniffer version | 3.5.4 |
| WPCS version | 2.2.1 |
| WPCS install type | Composer global |
Tested Against develop branch?
- I have verified the issue still exists in the
developbranch of WPCS.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the WordPress.WP.CronInterval sniff and reproduce the warning using the namespaced PHP example from the issue. Trace how the cron_schedules callback and interval are detected, then verify that the namespaced callback no longer triggers the warning while the interval is recognized on the develop branch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100