WordPress / WordPress/WordPress-Coding-Standards

Namespaced cron_schedules callbacks not detected

Open
#1,865 4 comments 0 reactions 0 assignees View on GitHub

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 develop branch of WPCS.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.