diff --git a/.gitignore b/.gitignore index 123b025d9..77bc0b703 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ dist .phpunit.result.cache # Exclude coverage reports -coverage/ \ No newline at end of file +coverage/ diff --git a/accessibility-checker.php b/accessibility-checker.php index a79b501ea..4b476fe76 100755 --- a/accessibility-checker.php +++ b/accessibility-checker.php @@ -10,7 +10,7 @@ * Plugin Name: Accessibility Checker * Plugin URI: https://a11ychecker.com * Description: Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance. - * Version: 1.32.0 + * Version: 1.33.0 * Requires PHP: 7.4 * Author: Equalize Digital * Author URI: https://equalizedigital.com @@ -36,7 +36,7 @@ // Current plugin version. if ( ! defined( 'EDAC_VERSION' ) ) { - define( 'EDAC_VERSION', '1.32.0' ); + define( 'EDAC_VERSION', '1.33.0' ); } // Current database version. diff --git a/includes/classes/WPCLI/BootstrapCLI.php b/includes/classes/WPCLI/BootstrapCLI.php index eb4aa8021..1a56a9b20 100644 --- a/includes/classes/WPCLI/BootstrapCLI.php +++ b/includes/classes/WPCLI/BootstrapCLI.php @@ -94,6 +94,14 @@ public function register() { $command, $command::get_args() ); + // For ease of typing on cli there's a shortname too in some commands. + if ( method_exists( $command, 'get_shortname' ) ) { + $this->wp_cli::add_command( + $command::get_shortname(), + $command, + $command::get_args() + ); + } } catch ( Exception $e ) { $this->wp_cli::warning( sprintf( diff --git a/includes/classes/WPCLI/Command/CleanupOrphanedIssues.php b/includes/classes/WPCLI/Command/CleanupOrphanedIssues.php index 131061c03..606278b10 100644 --- a/includes/classes/WPCLI/Command/CleanupOrphanedIssues.php +++ b/includes/classes/WPCLI/Command/CleanupOrphanedIssues.php @@ -32,7 +32,7 @@ class CleanupOrphanedIssues implements CLICommandInterface { * @param mixed|WP_CLI $wp_cli The WP-CLI instance. */ public function __construct( $wp_cli = null ) { - $this->wp_cli = $wp_cli ?? new WP_CLI(); + $this->wp_cli = $wp_cli ?? new WP_CLI(); } /** @@ -43,7 +43,18 @@ public function __construct( $wp_cli = null ) { * @return string */ public static function get_name(): string { - return 'accessibility-checker cleanup-orphaned-issues'; + return 'accessibility-checker cleanup-orphaned-issues'; + } + + /** + * Get the short name of the command. + * + * @since 1.33.0 + * + * @return string + */ + public static function get_shortname(): string { + return 'edac cleanup-orphaned-issues'; } /** @@ -54,24 +65,24 @@ public static function get_name(): string { * @return array */ public static function get_args(): array { - return [ - 'synopsis' => [ - [ - 'type' => 'assoc', - 'name' => 'batch', - 'description' => __( 'Number of orphaned posts to process in one batch.', 'accessibility-checker' ), - 'optional' => true, - 'default' => null, - ], - [ - 'type' => 'assoc', - 'name' => 'sleep', - 'description' => __( 'Seconds to sleep between deletions (default: 0).', 'accessibility-checker' ), - 'optional' => true, - 'default' => 0, - ], + return [ + 'synopsis' => [ + [ + 'type' => 'assoc', + 'name' => 'batch', + 'description' => __( 'Number of orphaned posts to process in one batch.', 'accessibility-checker' ), + 'optional' => true, + 'default' => null, + ], + [ + 'type' => 'assoc', + 'name' => 'sleep', + 'description' => __( 'Seconds to sleep between deletions (default: 0).', 'accessibility-checker' ), + 'optional' => true, + 'default' => 0, ], - ]; + ], + ]; } /** diff --git a/includes/classes/WPCLI/Command/DeleteStats.php b/includes/classes/WPCLI/Command/DeleteStats.php index 24d058d9a..bfa36bd9e 100644 --- a/includes/classes/WPCLI/Command/DeleteStats.php +++ b/includes/classes/WPCLI/Command/DeleteStats.php @@ -47,6 +47,17 @@ public static function get_name(): string { return 'accessibility-checker delete-stats'; } + /** + * Get the short name of the command. + * + * @since 1.33.0 + * + * @return string + */ + public static function get_shortname(): string { + return 'edac delete-stats'; + } + /** * Get the arguments for the command * diff --git a/includes/classes/WPCLI/Command/GetSiteStats.php b/includes/classes/WPCLI/Command/GetSiteStats.php index 6a0314b8a..419a4787d 100644 --- a/includes/classes/WPCLI/Command/GetSiteStats.php +++ b/includes/classes/WPCLI/Command/GetSiteStats.php @@ -51,6 +51,17 @@ public static function get_name(): string { return 'accessibility-checker get-site-stats'; } + /** + * Get the short name of the command. + * + * @since 1.33.0 + * + * @return string + */ + public static function get_shortname(): string { + return 'edac get-site-stats'; + } + /** * Get the arguments for the command * diff --git a/includes/classes/WPCLI/Command/GetStats.php b/includes/classes/WPCLI/Command/GetStats.php index 4cd45a5f4..b8831333d 100644 --- a/includes/classes/WPCLI/Command/GetStats.php +++ b/includes/classes/WPCLI/Command/GetStats.php @@ -69,6 +69,17 @@ public static function get_name(): string { return 'accessibility-checker get-stats'; } + /** + * Get the short name of the command. + * + * @since 1.33.0 + * + * @return string + */ + public static function get_shortname(): string { + return 'edac get-stats'; + } + /** * Get the arguments for the command * diff --git a/includes/classes/class-plugin.php b/includes/classes/class-plugin.php index 0f1f8f27d..b7cb7183f 100644 --- a/includes/classes/class-plugin.php +++ b/includes/classes/class-plugin.php @@ -45,8 +45,13 @@ public function __construct() { // When WP CLI is enabled, load the CLI commands. if ( defined( 'WP_CLI' ) && WP_CLI ) { - $cli = new BootstrapCLI(); - $cli->register(); + add_action( + 'init', + function () { + $cli = new BootstrapCLI(); + $cli->register(); + } + ); } } diff --git a/package-lock.json b/package-lock.json index 46d4c22f3..72d445ea5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "accessibility-checker", - "version": "1.26.0", + "version": "1.28.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "accessibility-checker", - "version": "1.26.0", + "version": "1.28.0", "hasInstallScript": true, "license": "GPL-2.0+", "devDependencies": { diff --git a/package.json b/package.json index 2bea8dfaa..39f697530 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "accessibility-checker", - "version": "1.32.0", + "version": "1.33.0", "description": "Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.", "author": "Equalize Digital", "license": "GPL-2.0+", diff --git a/readme.txt b/readme.txt index 1aa81a922..9158d433e 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: equalizedigital, alh0319, stevejonesdev Tags: accessibility, accessible, wcag, ada, WP accessibility Requires at least: 6.6 Tested up to: 6.8 -Stable tag: 1.32.0 +Stable tag: 1.33.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -210,6 +210,9 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro 10. Accessibility Checker automated fix settings. == Changelog == += 1.33.0 = +* Added: WP-CLI commands can now be run with short names: `wp edac ` or using long name `wp accessibility-checker `. +* Improved: Made it easier to register custom commands through filter. = 1.32.0 = * Fixed: Improved highlighter behavior to maintain original size and position of scanned elements. diff --git a/scripts/prep_release.sh b/scripts/prep_release.sh index 59d8db312..e996fafd2 100755 --- a/scripts/prep_release.sh +++ b/scripts/prep_release.sh @@ -48,6 +48,121 @@ sed -i.bak -E "s/( \* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+/\1${BUMPED_VER sed -i.bak -E "s/(define\( 'EDAC_VERSION', ')[0-9]+\.[0-9]+\.[0-9]+/\1${BUMPED_VERSION}/" "${MAIN_FILE_PATH}" sed -i.bak -E "s/(\"version\": \")[0-9]+\.[0-9]+\.[0-9]+/\1${BUMPED_VERSION}/" package.json sed -i.bak -E "s/(Stable tag: )[0-9]+\.[0-9]+\.[0-9]+/\1${BUMPED_VERSION}/" readme.txt + +echo +echo "Updating WordPress version requirements" +echo + +# Function to fetch WordPress versions and calculate required version +update_wp_requires_version() { + echo "Fetching WordPress version list..." + + # Get current "Tested up to" version from readme.txt + local tested_up_to=$(grep "Tested up to:" "${README_PATH}" | sed -E 's/Tested up to: ([0-9]+\.[0-9]+).*/\1/') + + if [[ -z "${tested_up_to}" ]]; then + echo "Error: Could not extract 'Tested up to' version from readme.txt" >&2 + return 1 + fi + + echo "Current 'Tested up to': ${tested_up_to}" + + # Try to fetch WordPress versions from the API first + local wp_versions_json=$(curl -s --max-time 10 "https://api.wordpress.org/core/version-check/1.7/" 2>/dev/null || echo "") + + if [[ -n "${wp_versions_json}" ]]; then + echo "Using WordPress API for version data..." + # Parse JSON response to get version list in reverse chronological order + # Extract major.minor versions from major.minor.patch format + local versions_list=$(echo "${wp_versions_json}" | \ + grep -o '"version":"[0-9]*\.[0-9]*\.[0-9]*"' | \ + sed 's/"version":"\([0-9]*\.[0-9]*\)\.[0-9]*"/\1/' | \ + sort -rV | \ + uniq) + else + echo "API unavailable, trying to parse releases page..." + # Fallback: try to parse the releases page + local releases_html=$(curl -s --max-time 15 "https://wordpress.org/download/releases/" 2>/dev/null || echo "") + + if [[ -n "${releases_html}" ]]; then + # Extract version numbers from the releases page + # Look for patterns like "WordPress 6.8" or "wordpress-6.7.zip" + local versions_list=$(echo "${releases_html}" | \ + grep -oE '(WordPress [0-9]+\.[0-9]+|wordpress-[0-9]+\.[0-9]+)' | \ + sed -E 's/(WordPress |wordpress-)([0-9]+\.[0-9]+)/\2/' | \ + sort -rV | \ + uniq) + else + echo "Error: Could not fetch WordPress version data from any source" >&2 + return 1 + fi + fi + + if [[ -z "${versions_list}" ]]; then + echo "Error: No WordPress versions found in response" >&2 + return 1 + fi + + echo "Found WordPress versions (latest first):" + echo "${versions_list}" | head -10 + + # Find the current tested version in the list and go back 2 versions (to support last 3 versions) + local found_current=false + local version_count=0 + local target_version="" + + while IFS= read -r version; do + if [[ "${found_current}" == true ]]; then + version_count=$((version_count + 1)) + if [[ ${version_count} -eq 2 ]]; then + target_version="${version}" + break + fi + elif [[ "${version}" == "${tested_up_to}" ]]; then + found_current=true + echo "Found current tested version ${tested_up_to} in version list" + fi + done <<< "${versions_list}" + + if [[ "${found_current}" == false ]]; then + echo "Warning: Current 'Tested up to' version ${tested_up_to} not found in WordPress version list" >&2 + echo "Available versions: $(echo "${versions_list}" | tr '\n' ' ')" >&2 + return 1 + fi + + if [[ -z "${target_version}" ]]; then + echo "Warning: Could not find version 2 releases back from ${tested_up_to}" >&2 + # Try to use the oldest version we found if we don't have enough history + target_version=$(echo "${versions_list}" | tail -1) + if [[ -n "${target_version}" ]]; then + echo "Using oldest available version: ${target_version}" + else + return 1 + fi + fi + + # Ensure we don't go below WordPress 5.0 (reasonable minimum) + local min_major=$(echo "${target_version}" | cut -d. -f1) + if [[ ${min_major} -lt 5 ]]; then + target_version="5.0" + echo "Adjusted to minimum supported version: ${target_version}" + fi + + echo "Setting 'Requires at least' to: ${target_version} (2 versions back from ${tested_up_to} to support last 3 versions)" + + # Update the readme.txt file + sed -i.bak -E "s/(Requires at least: )[0-9]+\.[0-9]+/\1${target_version}/" "${README_PATH}" + + return 0 +} + +# Update WordPress version requirements +if update_wp_requires_version; then + echo "Successfully updated WordPress version requirements" +else + echo "Warning: Could not update WordPress version requirements, keeping current values" +fi + rm "${MAIN_FILE_PATH}.bak" "${PACKAGE_JSON_PATH}.bak" "${README_PATH}.bak" echo