General: Introduce wp_get_branch_version() helper to extract major.minor version safely.#11211
General: Introduce wp_get_branch_version() helper to extract major.minor version safely.#11211tejas0306 wants to merge 59 commits intoWordPress:trunkfrom
Conversation
…nor version safely.
This introduces a new helper function `wp_get_branch_version()` for extracting the WordPress branch version (major.minor) from a version string.
Currently, several different approaches are used across core to determine the branch version, including:
- `(float)` casting of `get_bloginfo( 'version' )`
- `substr( $ver, 0, 3 )`
- `explode( '.' )` based parsing
- `preg_split()` in `class-core-upgrader.php`
Some of these approaches are fragile or incorrect:
- `(float)` casting can produce incorrect values due to floating-point precision issues.
- `substr( $ver, 0, 3 )` breaks for versions >= 10.
- Multiple inconsistent approaches make maintenance harder.
This patch introduces `wp_get_branch_version()` using a string-based approach:
```php
function wp_get_branch_version( $version = '' ) {
if ( '' === $version ) {
$version = wp_get_wp_version();
}
$parts = preg_split( '/[.-]/', $version, 3 );
return $parts[0] . '.' . ( $parts[1] ?? '0' );
}
|
Hi @tejas0306! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
… edge case, add tests.
…p_version_minor()
Admin Cards and Metabox were modified in [61646] to better align with the modern WordPress design system, but dashboard widgets drop zones weren't updated as such. This changeset adds rounded corners to these drop zones for better consistency. Follow-up to [61646]. Props ocean90, niravsherasiya7707, stefanvelthuys, valentingrenier, manhar, huzaifaalmesbah, r1k0. Fixes #64787. See #64549. git-svn-id: https://develop.svn.wordpress.org/trunk@61877 602fd350-edb4-49c9-b593-d223f7449a82
This commit adjusts cross-reference comments where the hook was moved to a different file but the cross-reference was not updated. Props apermo, mukesh27. See #64224. git-svn-id: https://develop.svn.wordpress.org/trunk@61878 602fd350-edb4-49c9-b593-d223f7449a82
Props xknown, johnbillion, peterwilsoncc. git-svn-id: https://develop.svn.wordpress.org/trunk@61879 602fd350-edb4-49c9-b593-d223f7449a82
…d and add some extra logic for validating pattern and template file paths. Props dmsnell, xknown, jonsurrell, peterwilsoncc, johnbillion. git-svn-id: https://develop.svn.wordpress.org/trunk@61880 602fd350-edb4-49c9-b593-d223f7449a82
This corrects the accidental revert of [61879] in [61880]. git-svn-id: https://develop.svn.wordpress.org/trunk@61881 602fd350-edb4-49c9-b593-d223f7449a82
Props dmsnell, xknown, johnbillion. git-svn-id: https://develop.svn.wordpress.org/trunk@61882 602fd350-edb4-49c9-b593-d223f7449a82
Some attributes require double encoding, which is disallowed by `esc_attr()`. Props westonruter, dmsnell, johnbillion. git-svn-id: https://develop.svn.wordpress.org/trunk@61883 602fd350-edb4-49c9-b593-d223f7449a82
…showing a link to it in the media manager. Props johnbillion, peterwilsoncc. git-svn-id: https://develop.svn.wordpress.org/trunk@61884 602fd350-edb4-49c9-b593-d223f7449a82
…onding `data-wp-on--` attribute should be used instead. Props luisherranz, peterwilsoncc, johnbillion, ocean90, jorbin, xknown. git-svn-id: https://develop.svn.wordpress.org/trunk@61885 602fd350-edb4-49c9-b593-d223f7449a82
…hey're correctly associated with a script tag. Props johnbillion, peterwilsoncc, jorbin. git-svn-id: https://develop.svn.wordpress.org/trunk@61886 602fd350-edb4-49c9-b593-d223f7449a82
…n using the PclZip library. This brings the handling inline with the same guard condition in `_unzip_file_ziparchive()` with ZipArchive. Props johnbillion, peterwilsoncc, xknown. git-svn-id: https://develop.svn.wordpress.org/trunk@61887 602fd350-edb4-49c9-b593-d223f7449a82
…target post. Props johnbillion, peterwilsoncc, adamsilverstein. git-svn-id: https://develop.svn.wordpress.org/trunk@61888 602fd350-edb4-49c9-b593-d223f7449a82
Props johnbillion, xknown, dmsnell, jorbin. git-svn-id: https://develop.svn.wordpress.org/trunk@61889 602fd350-edb4-49c9-b593-d223f7449a82
…ames in nav menus. This should have been committed in [61883] but got missed. git-svn-id: https://develop.svn.wordpress.org/trunk@61890 602fd350-edb4-49c9-b593-d223f7449a82
Props wildworks, hmbashar, bpayton, mcsf, joedolson, sabernhardt, westonruter. See #64672. git-svn-id: https://develop.svn.wordpress.org/trunk@61912 602fd350-edb4-49c9-b593-d223f7449a82
…hrough the `template_include` filter despite it being documented as only accepting a string. This has historically worked until [61892] increased the strictness of the template file validation which dismissed any value of a type other than a string, which a stringable object is not. Props dmsnell, westonruter. git-svn-id: https://develop.svn.wordpress.org/trunk@61913 602fd350-edb4-49c9-b593-d223f7449a82
git-svn-id: https://develop.svn.wordpress.org/trunk@61918 602fd350-edb4-49c9-b593-d223f7449a82
git-svn-id: https://develop.svn.wordpress.org/trunk@61919 602fd350-edb4-49c9-b593-d223f7449a82
…s and styles. Previously in r61397, `add_query_arg()` was used to append versions or handle-specific query arguments. This resulted in stripping any existing duplicate query variables in the source URL (common in Google Fonts URLs). This change refactors `WP_Styles::_css_href()` and `WP_Scripts::do_item()` to manually append these parameters to the URL string. This ensures all original query variables are preserved exactly as provided. It also improves fragment handling by ensuring query parameters are inserted before any '#' anchor while maintaining the anchor's presence. The URL encoding changes in `tests/phpunit/tests/dependencies/scripts.php` are reversions of what had previously been done in r61397. Developed in WordPress#11164 Follow-up to r61397, r61358. Props westonruter, jonsurrell. Fixes #64372. git-svn-id: https://develop.svn.wordpress.org/trunk@61927 602fd350-edb4-49c9-b593-d223f7449a82
…w` or `fetchpriority=auto`. This updates `wp_get_loading_optimization_attributes()` and `wp_maybe_add_fetchpriority_high_attr()` to account for cases where an `IMG` has `fetchpriority=low` or `fetchpriority=auto`: * `IMG` tags with `fetchpriority=low` are not lazy-loaded since they may be in a Navigation overlay, Details block, or Accordion Item block and need to be loaded the instant the user toggles the block. * `IMG` tags with `fetchpriority=auto` do not increase the media count since they may be hidden in a viewport by block visibility settings. * Blocks with conditional visibility (such as hidden on mobile or desktop) now automatically add `fetchpriority="auto"` to their contained `IMG` tags to prevent them from erroneously receiving `fetchpriority=high` or affecting the lazy-loading of subsequent images. * An `IMG` with `fetchpriority=auto` which also surpasses the `wp_min_priority_img_pixels` threshold will prevent a subsequent image from getting `fetchpriority=high`. Developed in WordPress#11196 Includes backport of [WordPress/gutenberg#76302 Gutenberg#76302]. See related Gutenberg issues: - [WordPress/gutenberg#76181 76181]: Image in navigation overlay can get `fetchpriority=high` and degrade LCP metric for page. - [WordPress/gutenberg#76268 76268]: Image in collapsed Details block may erroneously get `fetchpriority=high` even though hidden. - [WordPress/gutenberg#76301 76301]: Block Visibility: `IMG` in viewport-conditional block may get `fetchpriority=high` even when not displayed. - [WordPress/gutenberg#76335 76335]: Image in collapsed Accordion block may erroneously get `fetchpriority=high` even though hidden. Follow-up to r56347, r56037. Props westonruter, mukesh27, ramonopoly, wildworks. See #58235. Fixes #64823. git-svn-id: https://develop.svn.wordpress.org/trunk@61934 602fd350-edb4-49c9-b593-d223f7449a82
This adjusts cross-reference comments where the referenced file path contains a typo or an incorrect prefix. Follow-up to [61878]. Props apermo, mukesh27. See #64224. git-svn-id: https://develop.svn.wordpress.org/trunk@61946 602fd350-edb4-49c9-b593-d223f7449a82
Document-Isolation-Policy (DIP) isolates the document and blocks same-origin iframe access that page builders rely on. Skip DIP setup when a third-party page builder overrides the block editor via a custom `action` query parameter. Also gates `wp_is_client_side_media_processing_enabled()` on a secure context check, since `SharedArrayBuffer` requires a secure context (HTTPS or localhost). Props adamsilverstein, westonruter, mukesh27, louiswol94, manhar, illuminea. Fixes #64803. git-svn-id: https://develop.svn.wordpress.org/trunk@61947 602fd350-edb4-49c9-b593-d223f7449a82
The JavaScript fils within the `build/routes` and `build/pages` directories within the built `gutenberg` asset were not being copied properly into the working directory. This configures a `grunt copy:gutenberg-js` task to handle this. Follow up to [61873], [61874]. Props jorgefilipecosta, ellatrix, desrosj. See #64393. git-svn-id: https://develop.svn.wordpress.org/trunk@61978 602fd350-edb4-49c9-b593-d223f7449a82
* The keyboard shortcut is hidden in favor of a search icon on mobile. * The background color of the `KBD` element is made transparent on non-mobile. * The admin bar item is skipped from being added if the `wp-core-commands` script is not enqueued. Developed in WordPress#11222 Follow-up to r61912. Props sabernhardt, westonruter, ellatrix, mukesh27. See #64672. git-svn-id: https://develop.svn.wordpress.org/trunk@61979 602fd350-edb4-49c9-b593-d223f7449a82
When uploading images via the REST API with `generate_sub_sizes` set to `false`, skip server support checks since processing is handled on the client side. Fix an issue where uploads of formats like AVIF fail with `rest_upload_image_type_not_supported`, even though the client will handle all image processing and the server doesn't need to support the format. See also WordPress/gutenberg#76369 and WordPress/gutenberg#76371. Props adamsilverstein, westonruter, andrewserong, mukesh27. Fixes #64836. See #62717. git-svn-id: https://develop.svn.wordpress.org/trunk@61980 602fd350-edb4-49c9-b593-d223f7449a82
…from `init` to `wp_default_styles`. This ensures the filters to opt in to loading separate block styles on demand are added at the moment `WP_Styles` is constructed. This accounts for styles being registered at the `init` action before `register_core_block_style_handles()` runs at priority 9. Without this, the `wp-block-library` stylesheet may get registered with the full combined block styles as `style.css` instead of just `common.css`, due to `wp_should_load_block_assets_on_demand()` still returning false. The `wp_default_styles` action still runs during `init`. Developed in WordPress#11232 Follow-up to r61008. Props westonruter, adamsilverstein. See #64099. Fixes #64846. git-svn-id: https://develop.svn.wordpress.org/trunk@61981 602fd350-edb4-49c9-b593-d223f7449a82
Introduce a `POST /wp/v2/media/{id}/finalize` REST API endpoint that re-triggers the `wp_generate_attachment_metadata` filter with context `'update'` after client-side media processing completes. This ensures server-side plugins (watermarking, CDN sync, custom sizes, etc.) can post-process attachments when client-side processing is active.
The endpoint reuses `edit_media_item_permissions_check` for authorization and is only registered when `wp_is_client_side_media_processing_enabled()` returns true.
See WordPress/gutenberg#74913.
See WordPress/gutenberg#74358.
Props adamsilverstein, westonruter, mukesh27, divyeshpatel01.
Fixes #64804.
git-svn-id: https://develop.svn.wordpress.org/trunk@61982 602fd350-edb4-49c9-b593-d223f7449a82
Remove `_wp_connectors_get_connector_settings()` and inline `ksort()` into `_wp_connectors_get_connector_script_module_data()`. Expand `@return` and `@phpstan-return` array shapes for `wp_get_connector()` and `wp_get_connectors()`. Make `logo_url` and `credentials_url` truly optional. Rename test class to `wpGetConnectors`. Developed in WordPress#11227. Follow-up to [61943]. Props gziolo, westonruter. Fixes #64791. git-svn-id: https://develop.svn.wordpress.org/trunk@61983 602fd350-edb4-49c9-b593-d223f7449a82
Enable client-side media processing in the three `test_finalize_item*` tests so the `/finalize` route is registered before dispatching requests. Without this, the route does not exist and all assertions fail with `rest_no_route`. Extracts the repeated filter-and-reinitialize pattern into a shared `enable_client_side_media_processing()` helper, used by both the sideload and finalize tests. Follow-up to [61982]. git-svn-id: https://develop.svn.wordpress.org/trunk@61984 602fd350-edb4-49c9-b593-d223f7449a82
…masking. Add `_wp_connectors_get_api_key_source()` to detect whether an API key is configured via environment variable, PHP constant, or database. The UI uses this to show the key source and hide "Remove and replace" for externally configured keys. Replace `_wp_connectors_validate_keys_in_rest()` and `_wp_connectors_get_real_api_key()` with a single `rest_post_dispatch` handler, `_wp_connectors_rest_settings_dispatch()`, that masks keys in all `/wp/v2/settings` responses and validates on POST/PUT, reverting invalid keys. Simplify `_wp_register_default_connector_settings()` by replacing the closure-based `sanitize_callback` and `option_` mask filter with plain `sanitize_text_field`, since masking is now handled at the REST layer. Enrich `_wp_connectors_get_connector_script_module_data()` to expose `keySource`, `isConnected`, `logoUrl`, and plugin `isInstalled` / `isActivated` status to the admin screen. Update `_wp_connectors_pass_default_keys_to_ai_client()` to skip keys sourced from environment variables or constants and read the database directly via `get_option()`. Set `_wp_connectors_init` priority to 15 so the registry is ready before settings are registered at priority 20. Backports WordPress/gutenberg#76266. Backports WordPress/gutenberg#76327. Props jorgefilipecosta, gziolo, swissspidy, flixos90. Fixes #64819. git-svn-id: https://develop.svn.wordpress.org/trunk@61985 602fd350-edb4-49c9-b593-d223f7449a82
In performance tests, editing large documents in the site-editor suite (loading large-post.html) can cause performance tests in the site editor to time out with memory errors. Developed in: WordPress#11181. Props alecgeatches, mukesh27. See #64622. git-svn-id: https://develop.svn.wordpress.org/trunk@61986 602fd350-edb4-49c9-b593-d223f7449a82
Use `rest_is_field_included()` instead of `in_array()` for `content`, `title`, `excerpt`, and `guid` fields in `WP_REST_Revisions_Controller`. This lets clients request specific sub-fields (e.g. `_fields=content.raw`) and skip expensive `the_content` rendering. The [REST API `_fields` documentation](https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields) states that nested fields are supported using dot notation. However, the revisions controller uses `in_array()` which doesn't match nested keys like `content.raw`. Developed in: WordPress#11230. Props ellatrix, andrewserong, mukeshpanchal27. Fixes #64844. git-svn-id: https://develop.svn.wordpress.org/trunk@61987 602fd350-edb4-49c9-b593-d223f7449a82
This updates the pinned hash from the `gutenberg` from `9b8144036fa5faf75de43d4502ff9809fcf689ad` to `8c78d87453509661a9f28f978ba2c242d515563b`. The following changes are included: - Navigation Editor: Allow any blocks to be inserted by gating contentOnly insertion rules to section blocks (WordPress/gutenberg#76189) - Add `fetchpriority=low` to `IMG` tags in collapsed Details blocks (WordPress/gutenberg#76269) - Connectors: Add logo URL support for custom AI providers (WordPress/gutenberg#76190) - Cover Block: Add a playlist parameter to loop YouTube background videos. (WordPress/gutenberg#76004) - Connectors: Memoize getConnectors selector (WordPress/gutenberg#76339) - HTML Block: Fix broken layout (WordPress/gutenberg#76278) - Tests: Skip connector logo URL tests when AI Client is unavailable (WordPress/gutenberg#76343) - Navigation Overlay: Explicitly set fetchpriority for images (WordPress/gutenberg#76208) - Connectors: Show API key source for env vars and wp-config constants (WordPress/gutenberg#76355) - Connectors: Move API key validation and masking to REST dispatch level (WordPress/gutenberg#76327) - Connectors: Replace apiFetch with core-data store selectors (WordPress/gutenberg#76333) - Do not sync local attributes (WordPress/gutenberg#76267) - Add `fetchpriority=low` to `IMG` tags in collapsed Accordion Item blocks (WordPress/gutenberg#76336) - Implement disconnection debounce after initial connection (WordPress/gutenberg#76114) - Allow Post Content to be edited when 'Show template' is active and Post content is nested in a Template Part (WordPress/gutenberg#76305) - Fix: Document Bar: Back button flickers (WordPress/gutenberg#76320) - RTC: Move event hooks from editor to core-data (WordPress/gutenberg#76358) - fix(navigation): prevent right-justified submenu overflow in custom overlays (WordPress/gutenberg#76360) - Connectors: Add connectors registry for extensibility (WordPress/gutenberg#76364) - Connectors: Add empty state when no connectors are registered (WordPress/gutenberg#76375) - Temp: Disable RTC in the site editor (WordPress/gutenberg#76223) - Connectors: Add AI Experiments plugin callout with install/activate functionality (WordPress/gutenberg#76379) - Editor: Polish real-time collaboration presence UI and move Avatar to editor package (WordPress/gutenberg#75652) (WordPress/gutenberg#76365) - RTC: Add collaborator selection highlighting in rich text (WordPress/gutenberg#76107) - Sync changes from `wp_enqueue_global_styles()` to Gutenberg override (WordPress/gutenberg#76127) - [RTC] Fix performance regression on post save (WordPress/gutenberg#76370) - Media: Enable AVIF support for client-side uploads (WordPress/gutenberg#76371) - Connectors: Move plugin status computation to script module data (WordPress/gutenberg#76409) - Revisions: Skip rendered fields in REST API responses (WordPress/gutenberg#76347) - E2E Tests: Add connector setup flow tests with test AI provider (WordPress/gutenberg#76433) - RTC: Place sync connection modal in front of popover (WordPress/gutenberg#76431) - Connectors: Sync PHP code with WordPress Core (WordPress/gutenberg#76443) - Editor: Show own presence in collaborative editing sessions (WordPress/gutenberg#76413) (WordPress/gutenberg#76445) A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/9b8144036fa5faf75de43d4502ff9809fcf689ad…8c78d87453509661a9f28f978ba2c242d515563b. Log created with: git log --reverse --format="- %s" 9b8144036fa5faf75de43d4502ff9809fcf689ad..8c78d87453509661a9f28f978ba2c242d515563b | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy See #64595. git-svn-id: https://develop.svn.wordpress.org/trunk@61988 602fd350-edb4-49c9-b593-d223f7449a82
…sign. Developed in WordPress#11026 Props juanfra, westonruter, jeffpaul, mukesh27, audrasjb, joedolson, dd32, davidbaumwald, fabiankaegy, huzaifaalmesbah, Joen, butterflymedia, noruzzaman, karmatosed, ozgursar, fcoveram, tusharaddweb, darshitrajyaguru97. See #64308. Fixes #64708. git-svn-id: https://develop.svn.wordpress.org/trunk@61989 602fd350-edb4-49c9-b593-d223f7449a82
git-svn-id: https://develop.svn.wordpress.org/trunk@61990 602fd350-edb4-49c9-b593-d223f7449a82
git-svn-id: https://develop.svn.wordpress.org/trunk@61991 602fd350-edb4-49c9-b593-d223f7449a82
This commit simply removes a `$network_exists` variable (introduced in r41384) that was never used. Props mukesh27, Soean. Fixes #64851. git-svn-id: https://develop.svn.wordpress.org/trunk@61992 602fd350-edb4-49c9-b593-d223f7449a82
Developed in WordPress#11205 Props apermo, mukesh27. See #64224. git-svn-id: https://develop.svn.wordpress.org/trunk@61994 602fd350-edb4-49c9-b593-d223f7449a82
Update incorrect uses of `null` as a single parameter type to be `mixed` instead, largely targeting `$deprecated` variable names. Pipe `|` a few `null`s with other valid types where appropriate. Add a missing empty new-line between the `_deprecated_file()` and `_deprecated_argument()` functions. See #64224. git-svn-id: https://develop.svn.wordpress.org/trunk@61995 602fd350-edb4-49c9-b593-d223f7449a82
When an attachment is used by multiple posts, it could be included in `_embed` for a published post even if its `post_parent` is a draft. This commit avoids embedding attachments that are not viewable in this context. Props bor0. Fixes #64183. git-svn-id: https://develop.svn.wordpress.org/trunk@61996 602fd350-edb4-49c9-b593-d223f7449a82
…ded with a `null` parent. Developed in WordPress#11055 Props sky_76, westonruter, ozgursar, sabernhardt. Fixes #64728. git-svn-id: https://develop.svn.wordpress.org/trunk@61997 602fd350-edb4-49c9-b593-d223f7449a82
The `rest_revision_query` filter in `WP_REST_Revisions_Controller::get_items()` carried a cross-reference comment claiming it was documented in the posts controller. This was incorrect, as the posts controller documents `rest_{$this->post_type}_query` — a dynamic hook that fires only for post types managed by `WP_REST_Posts_Controller`.
`WP_REST_Revisions_Controller` extends `WP_REST_Controller` directly (not the posts controller), so the dynamic hook never fires for revisions. `rest_revision_query` is a standalone hook and has never had its own PHPDoc block.
Follow-up to [43584].
Props apermo, mukesh27, SergeyBiryukov.
See #64224.
git-svn-id: https://develop.svn.wordpress.org/trunk@61998 602fd350-edb4-49c9-b593-d223f7449a82
Replace `@group rest-api` with `@group restapi` to unify the tests under the one group name, chosen on the basis that majority rules. Follow up to r61045, r61032. See #64225. git-svn-id: https://develop.svn.wordpress.org/trunk@61999 602fd350-edb4-49c9-b593-d223f7449a82
src/wp-includes/functions.php
Outdated
| } | ||
|
|
||
| if ( 'minor' === $part ) { |
There was a problem hiding this comment.
| } | |
| if ( 'minor' === $part ) { | |
| } elseif ( 'minor' === $part ) { |
| * current WordPress version from wp_get_wp_version(). | ||
| * @return string The major version string in "x.y" format (e.g. "7.0"). | ||
| */ | ||
| function wp_get_branch_version( $version = '' ) { |
There was a problem hiding this comment.
I don't think this is required, the need in core isn't wide enough for what is relatively simple code.
There was a problem hiding this comment.
The problem is that it's needed in about half a dozen different places in core. Currently these are using a mixture of different ad-hoc methods to find the version number, and some of these are actually wrong/buggy.
There was a problem hiding this comment.
Thanks for the review.
The intention of wp_get_branch_version() here is mainly to consolidate several ad-hoc approaches currently used in core to derive the branch version.
At the moment, different files use different methods such as (float) casting, substr( $ver, 0, 3 ), or preg_split() / explode() logic. Some of these are fragile (for example substr( $ver, 0, 3 ) will break for versions >= 10, and (float) casting can produce incorrect results for x.0 branches).
This PR updates the current call sites that need the branch version to use a shared helper instead:
wp-admin/admin-header.phpwp-admin/includes/class-core-upgrader.phpwp-admin/includes/class-wp-site-health-auto-updates.phpwp-admin/includes/plugin-install.phpwp-admin/includes/theme.php
The goal is mainly to keep the behavior consistent and avoid repeating slightly different parsing logic across these files.
Happy to adjust the implementation or limit the scope if a smaller change would be preferred.
…it_link()` which is being passed in some templates. This addresses `arguments.count` errors identified by PHPStan at rule level 1. Developed in WordPress#11242 Follow-up to WordPress/twentyseventeen commits: [WordPress/twentyseventeen@1afb73c 1afb73c], [WordPress/twentyseventeen@7dd3025#diff-88ec0e9d51b04231a448a06c40ced21810e85361ced9481a9248f1075226c6aa 7dd3025], [https://github.com/WordPress/twentyseventeen/blob/69482880b4ae2ec145f60df417423665581a5653/inc/template-tags.php#L104-L128 6948288]. Props sabernhardt, westonruter. See #64680. Fixes #64825. git-svn-id: https://develop.svn.wordpress.org/trunk@62000 602fd350-edb4-49c9-b593-d223f7449a82
…nor version safely.
This introduces a new helper function `wp_get_branch_version()` for extracting the WordPress branch version (major.minor) from a version string.
Currently, several different approaches are used across core to determine the branch version, including:
- `(float)` casting of `get_bloginfo( 'version' )`
- `substr( $ver, 0, 3 )`
- `explode( '.' )` based parsing
- `preg_split()` in `class-core-upgrader.php`
Some of these approaches are fragile or incorrect:
- `(float)` casting can produce incorrect values due to floating-point precision issues.
- `substr( $ver, 0, 3 )` breaks for versions >= 10.
- Multiple inconsistent approaches make maintenance harder.
This patch introduces `wp_get_branch_version()` using a string-based approach:
```php
function wp_get_branch_version( $version = '' ) {
if ( '' === $version ) {
$version = wp_get_wp_version();
}
$parts = preg_split( '/[.-]/', $version, 3 );
return $parts[0] . '.' . ( $parts[1] ?? '0' );
}
… edge case, add tests.
…p_version_minor()
…306/wordpress-develop into add/wp-get-branch-version
This introduces a new helper function
wp_get_branch_version()for extracting the WordPress branch version (major.minor) from a version string.Currently, several different approaches are used across core to determine the branch version, including:
(float)casting ofget_bloginfo( 'version' )substr( $ver, 0, 3 )explode( '.' )based parsingpreg_split()inclass-core-upgrader.phpSome of these approaches are fragile or incorrect:
(float)casting can produce incorrect values due to floating-point precision issues.substr( $ver, 0, 3 )breaks for versions >= 10.This patch introduces
wp_get_branch_version()using a string-based approach:Trac ticket: https://core.trac.wordpress.org/ticket/64830