WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#19503 closed enhancement (wontfix)

Add major core version global for easier plugin/theme development

Reported by: johnjamesjacoby Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description (last modified by johnjamesjacoby)

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)

19503.diff (476 bytes) - added by johnjamesjacoby 4 years ago.

Download all attachments as: .zip

Change History (11)

@johnjamesjacoby4 years ago

comment:1 @johnjamesjacoby4 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

comment:2 @johnjamesjacoby4 years ago

  • Description modified (diff)

comment:3 @johnjamesjacoby4 years ago

  • Description modified (diff)

comment:4 @DJPaul4 years ago

  • Cc djpaul@… added

comment:5 follow-up: @sirzooro4 years ago

You can use following code to reliable check for WP 3.3+:
version_compare( $wp_version, '3.2.999', '>' );

comment:6 in reply to: ↑ 5 ; follow-up: @johnjamesjacoby4 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.

comment:7 @johnbillion4 years ago

You can also use floatval($wp_version) to get the major version number. A $wp_major_version variable would be nice though.

comment:8 @dd324 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 );
+	}

comment:9 in reply to: ↑ 6 @mikeschinkel4 years ago

  • Cc mikeschinkel@… added

Replying to johnjamesjacoby:

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.

How about a wp_major_version() function instead?

comment:10 @johnjamesjacoby3 years ago

  • Keywords dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

No traction in a year, and unlikely to happen based on above feedback.

Closing as wontfix.

Note: See TracTickets for help on using tickets.