WordPress / WordPress/WordPress-Coding-Standards

Extra: Sniff to check for overruling of WP included scripts

Open
#867 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Extra Focus: WP interoperability Type: Enhancement
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

WP ships with a number of scrips by default. If a theme or plugin wants to use one of those scripts they should use the version included with WP and not ship their own version.

Ref: https://developer.wordpress.org/reference/functions/wp_register_script/#core-registered-scripts

While this will never be something for which we can get a 100% detection - as people can rename the script files and use arbitrary handle names -, should we try to detect if a theme/plugin tries to enqueue their own script instead of the WP version ?

I imagine we could sniff the function parameters of the wp_enqueue_scripts function and:

  • throw an error if one of the reserved handles is used in combination with a value for the scr parameter
  • throw a warning if the filename in the scr parameter closely resembles the expected filename of one of the scripts WP ships with.

Additionally we could throw a warning if a deps parameter with one of the default values for a reserved handle is found as there is no need to register that dependency (already done by WP core).

Opinions ?

I imagine that the Theme Review theme and the VIP theme might be interested in including such a sniff as well ? /cc @grappler @sboisvert @david-binda

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

Review the WordPress core-registered-scripts reference and the wp_enqueue_scripts parameters described in the issue first. Define the detection scope and expected error or warning behavior for reserved handles, similar filenames, and redundant dependencies; done means the agreed sniff behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.