Skip to content

Commit e978707

Browse files
davidperezgardavidperezgarernilambarfrantorres
authored
Merge pull request #1250 from WordPress/961-check-wordpress-functions-are-compatible-with-wordpress-version
Add `wp_functions_compatibility` check with generated WordPress function `@since` dataset Co-authored-by: davidperezgar <davidperez@git.wordpress.org> Co-authored-by: ernilambar <nilambar@git.wordpress.org> Co-authored-by: frantorres <frantorres@git.wordpress.org>
2 parents 6e008c9 + 34355f4 commit e978707

15 files changed

Lines changed: 5411 additions & 1 deletion

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Generate WP Functions Since Data
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 5 * * 1'
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
generate:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout plugin-check
18+
uses: actions/checkout@v4
19+
20+
- name: Checkout WordPress core
21+
uses: actions/checkout@v4
22+
with:
23+
repository: WordPress/WordPress
24+
path: wordpress-core
25+
26+
- name: Set up PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: '8.2'
30+
31+
- name: Generate dataset
32+
run: |
33+
php tools/generate-wp-function-since-data.php \
34+
--wordpress-dir=wordpress-core \
35+
--output=includes/Vars/wp-functions-since.json
36+
37+
- name: Create pull request with updated dataset
38+
uses: peter-evans/create-pull-request@v7
39+
with:
40+
branch: codex/update-wp-functions-since-data
41+
commit-message: 'Update WordPress function since dataset'
42+
title: 'Update WordPress function since dataset'
43+
body: |
44+
Automated update for `includes/Vars/wp-functions-since.json`.
45+
add-paths: |
46+
includes/Vars/wp-functions-since.json

.typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extend-ignore-re = [
66
"setted_site_transient",
77
"setted_transient",
88
"stati",
9+
"url_is_accessable_via_ssl",
910
"wheres",
1011
]
1112

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"lint": "phpcs --standard=phpcs.xml.dist",
7575
"phpmd": "phpmd . text phpmd.xml",
7676
"phpstan": "phpstan analyse --memory-limit=2048M",
77+
"generate-wp-functions-since-data": "php tools/generate-wp-function-since-data.php --wordpress-dir=../../../ --output=includes/Vars/wp-functions-since.json",
7778
"prepare-behat-tests": "install-package-tests",
7879
"test": "phpunit"
7980
},
@@ -84,7 +85,8 @@
8485
"lint": "Detect coding standards issues",
8586
"phpmd": "Run PHP mess detector",
8687
"phpstan": "Run static analysis",
88+
"generate-wp-functions-since-data": "Generate the WordPress function @since dataset used by wp_functions_compatibility check",
8789
"prepare-behat-tests": "Prepare functional tests",
8890
"test": "Run unit tests"
8991
}
90-
}
92+
}

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [Creating a Static Check](creating-a-static-check.md)
55
* [Creating a Runtime Check](creating-a-runtime-check.md)
66
* [Available Checks](checks.md)
7+
* [WordPress Functions Compatibility Data](wp-functions-compatibility-data.md)
78
* [CLI Commands](CLI.md)
89
* [Running Unit tests](running-unit-tests.md)
910
* [Releasing a New Version of Plugin](releasing.md)

docs/checks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| plugin_updater | plugin_repo | Prevents altering WordPress update routines or using custom updaters, which are not allowed on WordPress.org. | [Learn more](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/) |
1616
| plugin_uninstall | plugin_repo | Checks related to plugin uninstallation. | [Learn more](https://developer.wordpress.org/plugins/plugin-basics/uninstall-methods/#method-2-uninstall-php) |
1717
| external_admin_menu_links | plugin_repo | Detects external URLs used in top-level WordPress admin menu, which disrupts the expected user experience. | [Learn more](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#11-plugins-should-not-hijack-the-admin) |
18+
| wp_functions_compatibility | plugin_repo | Checks whether WordPress functions used by the plugin are compatible with the declared minimum supported WordPress version ("Requires at least"). | [Learn more](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields) |
1819
| plugin_review_phpcs | plugin_repo | Runs PHP_CodeSniffer to detect certain best practices plugins should follow for submission on WordPress.org, including heredoc usage detection. | [Learn more](https://developer.wordpress.org/plugins/plugin-basics/best-practices/) |
1920
| direct_db_queries | security, plugin_repo | Checks the usage of direct database queries, which should be avoided. | [Learn more](https://developer.wordpress.org/apis/database/) |
2021
| direct_db | security, plugin_repo | Checks the escaping in direct database queries. | [Learn more](https://developer.wordpress.org/apis/database/) |
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# WordPress Functions Compatibility Data
2+
3+
The `wp_functions_compatibility` check uses a generated dataset:
4+
5+
- `includes/Vars/wp-functions-since.json`
6+
7+
That file maps WordPress function names to the WordPress version where they were introduced (`@since`).
8+
The check compares those versions with the plugin's minimum supported WordPress version (`Requires at least`).
9+
10+
## Regenerate Locally
11+
12+
From this plugin root:
13+
14+
```bash
15+
php tools/generate-wp-function-since-data.php \
16+
--wordpress-dir=/absolute/path/to/wordpress \
17+
--output=includes/Vars/wp-functions-since.json
18+
```
19+
20+
Example for this repository's standard local layout:
21+
22+
```bash
23+
php tools/generate-wp-function-since-data.php \
24+
--wordpress-dir=../../../ \
25+
--output=includes/Vars/wp-functions-since.json
26+
```
27+
28+
## Automation
29+
30+
The GitHub workflow:
31+
32+
- `.github/workflows/generate-wp-functions-since-data.yml`
33+
34+
regenerates this file on a schedule and via manual dispatch, and opens a pull request when the dataset changes.

0 commit comments

Comments
 (0)