Skip to content

Commit 4a1a0c1

Browse files
committed
Fixes
1 parent fbf0d12 commit 4a1a0c1

3 files changed

Lines changed: 29 additions & 26 deletions

File tree

.github/scripts/check-wordpress-tested-up-to.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33

44
from __future__ import annotations
55

6-
import http.client
76
import json
87
import os
98
import re
109
import sys
1110
from pathlib import Path
1211

1312

14-
WORDPRESS_API_HOST = "api.wordpress.org"
15-
WORDPRESS_VERSION_CHECK_PATH = "/core/version-check/1.7/"
1613
WORDPRESS_LATEST_VERSION = os.environ.get("WORDPRESS_LATEST_VERSION")
14+
WORDPRESS_VERSION_CHECK_FILE = Path("wordpress-version-check.json")
1715
SCAN_EXTENSIONS = {".php", ".md", ".txt"}
1816
DEFAULT_EXCLUDED_DIRS = {
1917
".git",
@@ -83,37 +81,24 @@ def get_latest_wordpress_major_minor() -> str:
8381
if WORDPRESS_LATEST_VERSION:
8482
return normalize_major_minor(WORDPRESS_LATEST_VERSION)
8583

86-
connection = http.client.HTTPSConnection(WORDPRESS_API_HOST, timeout=20)
87-
connection.request(
88-
"GET",
89-
WORDPRESS_VERSION_CHECK_PATH,
90-
headers={
91-
"Accept": "application/json",
92-
"User-Agent": "wordpress-tested-up-to-check/1.0",
93-
},
94-
)
95-
96-
response = connection.getresponse()
97-
try:
98-
if response.status != http.client.OK:
99-
raise RuntimeError(
100-
f"WordPress version-check API returned HTTP {response.status}."
101-
)
102-
103-
payload = json.loads(response.read().decode("utf-8"))
104-
finally:
105-
connection.close()
84+
if not WORDPRESS_VERSION_CHECK_FILE.is_file():
85+
raise RuntimeError(
86+
"WORDPRESS_LATEST_VERSION must be set, or wordpress-version-check.json must exist."
87+
)
10688

89+
payload = json.loads(WORDPRESS_VERSION_CHECK_FILE.read_text(encoding="utf-8"))
10790
versions = []
91+
10892
for offer in payload.get("offers", []):
10993
version = offer.get("current") or offer.get("version")
11094
if isinstance(version, str) and VERSION_PATTERN.match(version):
11195
versions.append(version)
11296

11397
if not versions:
114-
raise RuntimeError("Could not determine the latest WordPress version from the version-check API.")
98+
raise RuntimeError("Could not determine the latest WordPress version.")
11599

116-
return normalize_major_minor(max(versions, key=version_sort_key))
100+
latest = max(versions, key=version_sort_key)
101+
return normalize_major_minor(latest)
117102

118103

119104
def normalize_major_minor(version: str) -> str:

.github/workflows/wordpress-tested-up-to.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,12 @@ jobs:
2424
- name: Checkout code
2525
uses: actions/checkout@v6
2626

27+
- name: Download WordPress version data
28+
run: |
29+
curl --fail --silent --show-error --location \
30+
--proto '=https' --tlsv1.2 \
31+
https://api.wordpress.org/core/version-check/1.7/ \
32+
--output wordpress-version-check.json
33+
2734
- name: Check WordPress Tested Up To metadata
2835
run: python3 .github/scripts/check-wordpress-tested-up-to.py

tests/unit/DomainValidationTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ private function resetTestState(): void {
4141
$wp_settings_errors = array();
4242
}
4343

44+
/**
45+
* Get registered settings errors from the WordPress test state.
46+
*
47+
* @return array<int, array<string, string>> Registered settings errors.
48+
*/
49+
private function get_settings_errors(): array {
50+
global $wp_settings_errors;
51+
52+
return is_array( $wp_settings_errors ) ? $wp_settings_errors : array();
53+
}
54+
4455
/**
4556
* Clean HTTPS domains are accepted and normalized.
4657
*
@@ -173,7 +184,7 @@ public function test_domain_list_keeps_unique_clean_https_domains(): void {
173184
'message' => 'Some preconnect domains were rejected for security reasons: https://example.com/path (file paths are not allowed; use domains only)',
174185
'type' => 'warning',
175186
),
176-
$GLOBALS['wp_settings_errors']
187+
$this->get_settings_errors()
177188
);
178189
}
179190

0 commit comments

Comments
 (0)