From c8f5e21b5cb58c2e5f72f6c9c068070531e6f5c9 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 15 May 2026 11:00:07 +1000 Subject: [PATCH 1/8] Add domain to translated strings. --- src/Validator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Validator.php b/src/Validator.php index 1a76482..262977f 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -118,13 +118,13 @@ public function is_plugin_compatible() { switch ( $item_name ) { case 'php_min_required_version': if ( ! empty( $item_details['value'] ) && version_compare( phpversion(), $item_details['value'], '<' ) ) { - $this->messages[] = sprintf( esc_html__( 'The minimum PHP version required is %s' ), $item_details['value'] ); + $this->messages[] = sprintf( __( 'The minimum PHP version required is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); } break; case 'php_max_required_version': if ( ! empty( $item_details['value'] ) && version_compare( phpversion(), $item_details['value'], '>' ) ) { - $this->messages[] = sprintf( esc_html__( 'The maximum PHP version supported is %s' ), $item_details['value'] ); + $this->messages[] = sprintf( __( 'The maximum PHP version supported is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); } break; @@ -149,7 +149,7 @@ public function render_php_compat_error() {

- checklist['plugin_name']['value'] ); ?> + checklist['plugin_name']['value'] ); ?>

messages ) > 1 ) : ?> From 883e31a4232f8e3eec9dab53bf75feca73283b3c Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 15 May 2026 11:04:16 +1000 Subject: [PATCH 2/8] Add translator comments. --- src/Validator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Validator.php b/src/Validator.php index 262977f..b39ec4b 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -118,12 +118,14 @@ public function is_plugin_compatible() { switch ( $item_name ) { case 'php_min_required_version': if ( ! empty( $item_details['value'] ) && version_compare( phpversion(), $item_details['value'], '<' ) ) { + // translators: %s: PHP version $this->messages[] = sprintf( __( 'The minimum PHP version required is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); } break; case 'php_max_required_version': if ( ! empty( $item_details['value'] ) && version_compare( phpversion(), $item_details['value'], '>' ) ) { + // translators: %s: PHP version $this->messages[] = sprintf( __( 'The maximum PHP version supported is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); } break; @@ -149,7 +151,10 @@ public function render_php_compat_error() {

- checklist['plugin_name']['value'] ); ?> + checklist['plugin_name']['value'] ); + ?>

messages ) > 1 ) : ?> From 16d09806bd6b3d06125bd740a5902ec405cba935 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 15 May 2026 11:17:19 +1000 Subject: [PATCH 3/8] Add optional argument to replace translation domain. --- replace-namespace.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/replace-namespace.sh b/replace-namespace.sh index 1ff562b..a54a47b 100755 --- a/replace-namespace.sh +++ b/replace-namespace.sh @@ -4,14 +4,21 @@ SCRIPT_DIR="$(dirname "$0")" SCRIPT_NAME="$(basename "$0")" -# Check for the required argument -if [ "$#" -ne 1 ]; then +# Check for the required first argument +if [ -z "$1" ]; then echo "Usage: $0 New_Namespace" exit 1 fi NEW_NAMESPACE="$1" +# Check for the optional translation domain argument and set it if provided +if [ -n "$2" ]; then + TRANSLATION_DOMAIN="$2" +else + echo "No translation domain provided. Skipping translation domain replacement." +fi + # Use find to get all files recursively from the script's directory, excluding the script itself find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIPT_NAME" | while read -r file; do echo $file @@ -19,4 +26,13 @@ find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIP perl -pi -e "s/WP_Compat_Validation_Tool/$NEW_NAMESPACE/g" "$file" done +# If a new translation domain was provided, replace the old one with the new one +if [ -n "$TRANSLATION_DOMAIN" ]; then + find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIPT_NAME" | while read -r file; do + echo $file + # Replace the exact string when surrounded by either single or double quotes + perl -pi -e "s/(['\"])wp-compat-validation-tool\\1/$TRANSLATION_DOMAIN/g" "$file" + done +fi + cd 10up-lib/wp-compat-validation-tool && rm -rf .git .github .gitignore composer.json composer.lock CHANGELOG.md CONTRIBUTING.md README.md LICENSE.md CODE_OF_CONDUCT.md CREDITS.md replace-namespace.sh From 51d9f7011aed76d6739d807ae8a60888a0c96d54 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 15 May 2026 11:22:48 +1000 Subject: [PATCH 4/8] Fix domain replacement regex. --- replace-namespace.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replace-namespace.sh b/replace-namespace.sh index a54a47b..8cf015a 100755 --- a/replace-namespace.sh +++ b/replace-namespace.sh @@ -31,7 +31,7 @@ if [ -n "$TRANSLATION_DOMAIN" ]; then find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIPT_NAME" | while read -r file; do echo $file # Replace the exact string when surrounded by either single or double quotes - perl -pi -e "s/(['\"])wp-compat-validation-tool\\1/$TRANSLATION_DOMAIN/g" "$file" + perl -pi -e "s/(['\"])wp-compat-validation-tool\\1/\\1$TRANSLATION_DOMAIN\\1/g" "$file" done fi From e2e10babbf8b076219079f891d81198b72e2242c Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 15 May 2026 11:30:02 +1000 Subject: [PATCH 5/8] Prevent direct access to file. --- src/Validator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Validator.php b/src/Validator.php index b39ec4b..c9944bc 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -1,6 +1,10 @@ Date: Fri, 15 May 2026 11:31:18 +1000 Subject: [PATCH 6/8] Escape plugin name. --- src/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validator.php b/src/Validator.php index c9944bc..d4a5c46 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -157,7 +157,7 @@ public function render_php_compat_error() { checklist['plugin_name']['value'] ); + printf( esc_html__( '%s error:', 'wp-compat-validation-tool' ), esc_html( $this->checklist['plugin_name']['value'] ) ); ?>

From 92da6a4ca718aabcbca7d1930ebfd0c5c00521a7 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 15 May 2026 11:37:45 +1000 Subject: [PATCH 7/8] Check supported WordPress versions. --- src/Validator.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Validator.php b/src/Validator.php index d4a5c46..e186120 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -108,6 +108,27 @@ public function set_wordpress_max_required_version( $value = '' ) { return $this; } + /** + * Returns the current WordPress version. + * + * Returns an unmodified value of `$wp_version`. Some plugins modify the global + * in an attempt to improve security through obscurity. This practice can cause + * errors in WordPress, so the ability to get an unmodified version is needed. + * + * Ports the WordPress function `wp_get_wp_version()` available in WordPress 6.7.0 and later. + * + * @return string The current WordPress version. + */ + public function wp_get_wp_version() { + static $wp_version; + + if ( ! isset( $wp_version ) ) { + require ABSPATH . WPINC . '/version.php'; + } + + return $wp_version; + } + /** * Returns true if the plugin meets all compatibility checks, false otherwise. * @@ -134,6 +155,20 @@ public function is_plugin_compatible() { } break; + case 'wp_min_required_version': + if ( ! empty( $item_details['value'] ) && version_compare( $this->wp_get_wp_version(), $item_details['value'], '<' ) ) { + // translators: %s: WordPress version + $this->messages[] = sprintf( __( 'The minimum WordPress version required is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); + } + break; + + case 'wp_max_required_version': + if ( ! empty( $item_details['value'] ) && version_compare( $this->wp_get_wp_version(), $item_details['value'], '>' ) ) { + // translators: %s: WordPress version + $this->messages[] = sprintf( __( 'The maximum WordPress version supported is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); + } + break; + default: break; } From 7b440004bde20e435af68dad8385912ec3398d00 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 15 May 2026 11:59:09 +1000 Subject: [PATCH 8/8] Update documentation. --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b522e54..05617c6 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ In your project's `composer.json`, add the following: ], "scripts": { "post-install-cmd": [ - "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " + "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " ], "post-update-cmd": [ - "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " + "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " ] }, "extra": { @@ -43,6 +43,9 @@ In your project's `composer.json`, add the following: Replace `` with a unique namespace specific to your project. The `WP_Compat_Validation_Tools` namespace will be replaced by `` to avoid namespace collisions in situations where multiple plugins use this package as their dependencies. +Replace `` with a unique translation domain specific to your project. +This is usually the slug for your theme or plugin. The `wp-compat-validation-tool` translation domain will be replaced by ``. + ## Usage ```php