Opened 14 years ago
Closed 13 years ago
#19503 closed enhancement (wontfix)
Add major core version global for easier plugin/theme development
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | has-patch |
| Focuses: | Cc: |
Description (last modified by )
Problem:
Plugin/theme authors cannot reliably use $wp_version when doing their own feature development without hitting a chicken-egg scenario.
Example:
I want a plugin to call function foo_32() for all major WordPress 3.2 branch versions.
I want a plugin to call function foo_33() for all major WordPress 3.3 branch versions.
3.2.1 is greater than 3.2
3.3-RC2 is less than 3.3
version_compare() is inadequate for this when used in conjunction with core's versioning scheme.
Paradox:
version_compare( '3.2', $wp_version ); -- Fails when 3.2.1 comes out
version_compare( '3.3', $wp_version ); -- Fails before 3.3 is released
Using version_compare() with any combination of operators yields the same result.
Proposed Solution:
A new global: $wp_major_version
This would get bumped in trunk when development starts on the next major version. It provides plugin and theme authors the luxury of not needing to parse the major version out of $wp_version themselves. Patch attached.
Attachments (1)
Change History (11)
#1
@
14 years ago
- Summary changed from Add major core version global for easier plugin feature development to Add major core version global for easier plugin/theme development
#6
in reply to:
↑ 5
;
follow-up:
↓ 9
@
14 years ago
Replying to sirzooro:
You can use following code to reliable check for WP 3.3+:
version_compare( $wp_version, '3.2.999', '>' );
True, but seems like a hack.
#7
@
14 years ago
You can also use floatval($wp_version) to get the major version number. A $wp_major_version variable would be nice though.
#8
@
14 years ago
You can also use floatval($wp_version) to get the major version number.
That's what we do in Core, but you have to be aware that some non-en locale's don't use . as the decimal seperator, and so you end up with 3,2 See trunk's code here: admin-header.php#L85
Ideally though, you shouldn't need to do version compares if at all possible.. Instead you should be feature testing, For example: [19580]
+ $screen = get_current_screen();
+
+ if ( method_exists( $screen, 'add_help_tab' ) ) {
+ // WordPress 3.3
+ $screen->add_help_tab( array(
+ 'title' => __( 'Overview', 'twentyeleven' ),
+ 'id' => 'theme-options-help',
+ 'content' => $help,
+ )
+ );
+
+ $screen->set_help_sidebar( $sidebar );
+ } else {
+ // WordPress 3.2
+ add_contextual_help( $screen, $help . $sidebar );
+ }
You can use following code to reliable check for WP 3.3+:
version_compare( $wp_version, '3.2.999', '>' );