Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/09/2020 07:17:20 PM (15 months ago)
Author:
imath
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r12729 r12745  
    7070        return !empty( $bp->db_version_raw ) ? $bp->db_version_raw : 0;
    7171    }
     72
     73/**
     74 * Check whether the current version of WP exceeds a given version.
     75 *
     76 * @since 7.0.0
     77 *
     78 * @param string $version WP version, in "PHP-standardized" format.
     79 * @param string $compare Optional. Comparison operator. Default '>='.
     80 * @return bool
     81 */
     82function bp_is_running_wp( $version, $compare = '>=' ) {
     83    return version_compare( $GLOBALS['wp_version'], $version, $compare );
     84}
    7285
    7386/** Functions *****************************************************************/
     
    31353148
    31363149    // register_term_meta() was introduced in WP 4.9.8.
    3137     if ( ! function_exists( 'register_term_meta' ) ) {
     3150    if ( ! bp_is_running_wp( '4.9.8' ) ) {
    31383151        $args['object_subtype'] = $type_tax;
    31393152
     
    35393552    );
    35403553
    3541     if ( version_compare( $GLOBALS['wp_version'], '4.9.6', '>=' ) ) {
     3554    if ( bp_is_running_wp( '4.9.6' ) ) {
    35423555        $privacy_policy_url = get_privacy_policy_url();
    35433556        if ( $privacy_policy_url ) {
Note: See TracChangeset for help on using the changeset viewer.