Feature: Add wp_version_compare
function
#7476
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac Ticket: Core-62151
Summary
wp_version_compare
function to enhance version comparison capabilities in WordPress by allowing the option to ignore the patch version. This is particularly useful for compatibility checks where only major and minor versions are relevant, simplifying the process of validating plugin and theme compatibility with WordPress core.Problem Statement
version_compare()
function in PHP compares the full version number, including the patch (third number). In many scenarios, such as plugin development, only the major and minor versions are necessary for determining compatibility. For example, a plugin tested with WordPress version6.6
should also be compatible with6.6.2
, but the standard comparison would return false due to the patch difference.Proposed Solution
The new
wp_version_compare
function provides:Customizable Version Comparison
: An option to ignore the patch version during comparisons, allowing developers to manage compatibility without altering API data.Input Validation
: Ensures that the provided versions are strings and that the comparison operator is valid, returning false for invalid parameters.Benefits
Simplifies Compatibility Checks
: By allowing developers to focus on major and minor version differences, the function enhances usability in compatibility scenarios.Improved Validation
: Robust input validation helps prevent errors, ensuring reliable comparisons.Conclusion
wp_version_compare
function, we empower developers to streamline their workflows and reduce potential compatibility issues.