Skip to:

Opened 6 years ago

Closed 4 years ago

#7906 closed enhancement (fixed)

Helper function for checking WP version

Reported by: boonebgorges's profile boonebgorges Owned by: imath's profile imath
Milestone: 7.0.0 Priority: normal
Severity: normal Version:
Component: Core Keywords: has-patch dev-feedback


There are a few dozen places in BP where we check for the current WP version. This is generally done with something like:

if ( version_compare( $GLOBALS['wp_version'], '4.9', '>=' ) ) {

though in other places, we do function_exists() checks and other such things.

Two proposals:

  1. We introduce a wrapper function for checking WP version. A proposed implementation is attached.
  2. We standardize on using it throughout BP. This makes it easier to identify backward-compatibility chunks when we bump our minimum WP version.

Attachments (3)

7906.diff (798 bytes) - added by boonebgorges 6 years ago.
7906.2.diff (3.3 KB) - added by imath 4 years ago.
7906.3.diff (10.8 KB) - added by imath 4 years ago.

Download all attachments as: .zip

Change History (13)

6 years ago

#1 @boonebgorges
6 years ago

  • Milestone changed from 4.0 to Up Next

#2 @imath
4 years ago

  • Milestone changed from Up Next to 7.0.0

This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.

4 years ago

#4 @r-a-y
4 years ago

Just to note that we already have a function to fetch the current WP version to one decimal point, bp_get_major_wp_version():

4 years ago

#5 @imath
4 years ago


Yes at the beginning I thought it was duplicating the job with it. But the function includes the version comparison and makes possible to check minor WP Version. Although new features mainly appears in major versions, there was a time just before WP 5.0 when WordPress was included new features in minor versions, eg: the GDPR/privacy ones.

I've just refreshed the patch and use the bp_is_running_wp() function into some places.

What about including it?

#6 @r-a-y
4 years ago

I'm okay with this.

There are also various spots where we check for the existence of a WordPress function from a specific WP version such as wp_switch_roles_and_user(). Perhaps we could switch those out with the WP version where the function was introduced?

#7 @imath
4 years ago

Thanks for your feedback and I agree, we should replace the function_exists checks.

I’ll update the patch 👌

#8 @espellcaste
4 years ago

This new commit could also use an update with this new function:

4 years ago

#9 @imath
4 years ago

  • Type changed from defect (bug) to enhancement

7906.3.diff adds function_exists replacements when it is used to check WP version.

#10 @imath
4 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 12745:

Core: introduce the bp_is_running_wp() function

This helper function checks WordPress version and is used by BuddyPress to ensure backward-compatibility when a WordPress feature/function is not yet available on the WordPress site BuddyPress is running on.

We have standardized the way we were doing these checks so far by replacing these with the use of this new bp_is_running_wp() function. It will help us to identify backward-compatibility chunks when we bump our minimum WP version.

bp_is_running_wp() accepts two arguments:

  • the WP version, in "PHP-standardized" format.
  • the comparison operator. It defaults to >=.

Props boonebgorges, r-a-y, espellcaste

Fixes #7906

Note: See TracTickets for help on using tickets.