Skip to content

Fix incorrect version number when creating zip archive#124

Merged
swissspidy merged 2 commits intomainfrom
copilot/fix-zip-archive-version-number
Mar 12, 2026
Merged

Fix incorrect version number when creating zip archive#124
swissspidy merged 2 commits intomainfrom
copilot/fix-zip-archive-version-number

Conversation

Copy link
Contributor

Copilot AI commented Mar 12, 2026

When PHP files are scanned alphabetically for a plugin version, PHPdoc @version tags (e.g. in class-lifterlms.php) were incorrectly matched before the WordPress plugin header Version: in the main plugin file.

Root cause: The docblock parser matched both @version 7.2.0 (no colon, PHPdoc) and Version: 7.6.0 (with colon, WP plugin header). Any file alphabetically preceding the main plugin file with a @version tag would win.

Changes:

  • src/Dist_Archive_Command.php: Replace docblock-based version detection for PHP files with the WordPress get_file_data() style regex, which requires a colon after Version:

    $pattern = '/^[ \t\/*#@]*Version:(.*)$/mi';

    @version 7.2.0 (no colon) no longer matches; * Version: 7.6.0 does. Removes the now-dead get_version_in_code(), get_version_in_docblock(), and parse_doc_block() methods.

  • features/dist-archive.feature: Adds a scenario that directly reproduces the bug — a plugin directory where class-my-plugin.php (with @version 7.2.0) sorts before my-plugin.php (with Version: 7.6.0) — asserting the archive is named using 7.6.0.

Original prompt

This section details on the original issue you should resolve

<issue_title>Incorrect version number used when creating zip archive</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

It looks like if there's a PHP file with a PHPdoc version number in the header like this, in a class file in the root folder of the plugin that isn't the main plugin file, it will be used instead of the actual plugin version number:

/**
 * Class file
 * 
 * @version 7.2.0
 */

Describe how other contributors can replicate this bug

  • Create a folder lifterlms with a main plugin file with the standard plugin header (ie. lifterlms.php)
<?php
/**
 * Main LifterLMS plugin file
 *
 * @package LifterLMS/Main
 *
 * @since 1.0.0
 * @version 5.3.0
 *
 * Plugin Name: LifterLMS
 * Plugin URI: https://lifterlms.com/
 * Description: Complete e-learning platform to sell online courses, protect lessons, offer memberships, and quiz students.
 * Version: 7.6.0
 * Author: LifterLMS
 * Author URI: https://lifterlms.com/
 * Text Domain: lifterlms
 * Domain Path: /languages
 * License: GPLv3
 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
 * Requires at least: 5.9
 * Tested up to: 6.5
 * Requires PHP: 7.4
 *
 * * * * * * * * * * * * * * * * * * * * * *
 *                                         *
 * Reporting a Security Vulnerability      *
 *                                         *
 * Please disclose any security issues or  *
 * vulnerabilities to team@lifterlms.com   *
 *                                         *
 * See our full Security Policy at         *
 * https://lifterlms.com/security-policy   *
 *                                         *
 * * * * * * * * * * * * * * * * * * * * * *
 */
  • Create a file that's alphabetically before the main plugin file with the following header, ie. class-lifterlms.php
<?php
/**
 * Main LifterLMS class
 *
 * @package LifterLMS/Main
 *
 * @since 1.0.0
 * @version 7.2.0
 */
  • Run wp dist-archive lifterlms from the wp-content/plugins folder

Expected

Creates zip archive with name lifterlms.7.6.0.zip

Actual

Creates zip archive with name liftrerlms.7.2.0.zip

Let us know what environment you are running this on

OS:	Darwin 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030 x86_64
Shell:	/bin/zsh
PHP binary:	/usr/local/Cellar/php@8.2/8.2.18/bin/php
PHP version:	8.2.18
php.ini used:	/usr/local/etc/php/8.2/php.ini
MySQL binary:	/usr/local/bin/mysql
MySQL version:	mysql  Ver 8.1.0 for macos14.0 on x86_64 (Homebrew)
SQL modes:
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/brianhogg/laravel/lifter2/wp-content/plugins/lifterlms
WP-CLI packages dir:	/Users/brianhogg/.wp-cli/packages/
WP-CLI cache dir:	/Users/brianhogg/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version:	2.10.0

Provide a possible solution

Other than removing the @version 7.2.0 header in the other class file I'm not sure a fix without checking the code that fetches the plugin version number. Likely just needs a tweak to what it's looking for to ignore @version but grab Version:
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Thanks for the report, @brianhogg ! This seems like a genuine bug.

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.</comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect version number used when creating zip archive Fix incorrect version number when creating zip archive Mar 12, 2026
@github-actions github-actions bot added bug command:dist-archive Related to 'dist-archive' command scope:distribution Related to distribution state:unconfirmed labels Mar 12, 2026
@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review March 12, 2026 08:40
@swissspidy swissspidy requested a review from a team as a code owner March 12, 2026 08:40
Copilot AI review requested due to automatic review settings March 12, 2026 08:40
@swissspidy swissspidy added this to the 3.2.1 milestone Mar 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect version detection for wp dist-archive when scanning PHP files in alphabetical order by ensuring only WordPress-style Version: headers (with a colon) are matched, not PHPdoc @version tags.

Changes:

  • Update PHP version detection to use a WordPress get_file_data()-style regex that requires Version: (colon required).
  • Remove now-unused docblock/token parsing helpers used for version extraction.
  • Add a Behat scenario that reproduces the original bug (alphabetically earlier @version tag vs. main plugin Version: header).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Dist_Archive_Command.php Switches plugin version extraction to a Version:-header regex and removes docblock-based parsing methods.
features/dist-archive.feature Adds regression coverage ensuring Version: wins over PHPdoc @version when naming the archive.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@swissspidy swissspidy merged commit 18392ac into main Mar 12, 2026
73 checks passed
@swissspidy swissspidy deleted the copilot/fix-zip-archive-version-number branch March 12, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:dist-archive Related to 'dist-archive' command scope:distribution Related to distribution state:unconfirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect version number used when creating zip archive

3 participants