Opened 6 years ago
Closed 4 years ago
#7906 closed enhancement (fixed)
Helper function for checking WP version
Reported by: | boonebgorges | Owned by: | imath |
---|---|---|---|
Milestone: | 7.0.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Core | Keywords: | has-patch dev-feedback |
Cc: |
Description
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:
- We introduce a wrapper function for checking WP version. A proposed implementation is attached.
- 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)
Change History (13)
This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.
4 years ago
#5
@
4 years ago
@r-a-y
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
@
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
@
4 years ago
Thanks for your feedback and I agree, we should replace the function_exists
checks.
I’ll update the patch 👌
#8
@
4 years ago
This new commit could also use an update with this new function: https://buddypress.trac.wordpress.org/changeset/12737
Just to note that we already have a function to fetch the current WP version to one decimal point,
bp_get_major_wp_version()
: https://buddypress.trac.wordpress.org/browser/tags/6.3.0/src/bp-core/bp-core-wpabstraction.php#L19