Skip to:
Content

BuddyPress.org

Changeset 12745


Ignore:
Timestamp:
10/09/2020 07:17:20 PM (3 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

Location:
trunk/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-filters.php

    r12698 r12745  
    3232add_filter( 'bp_activity_action_before_save',        'force_balance_tags' );
    3333
    34 if ( function_exists( 'wp_encode_emoji' ) ) {
    35     add_filter( 'bp_activity_content_before_save', 'wp_encode_emoji' );
    36 }
     34add_filter( 'bp_activity_content_before_save', 'wp_encode_emoji' );
    3735
    3836add_filter( 'bp_get_activity_action',                'wptexturize' );
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r12734 r12745  
    576576}
    577577
    578 if ( function_exists( 'wp_switch_roles_and_user' ) ) {
     578if ( bp_is_running_wp( '4.9.0' ) ) {
    579579    add_action( 'clean_site_cache', 'bp_blogs_delete_url_blogmeta' );
    580580} else {
  • trunk/src/bp-core/bp-core-blocks.php

    r12684 r12745  
    2020 */
    2121function bp_support_blocks() {
    22     return function_exists( 'register_block_type' ) && bp_rest_api_is_available();
     22    return bp_is_running_wp( '5.0.0' ) && bp_rest_api_is_available();
    2323}
    2424
  • trunk/src/bp-core/bp-core-catchuri.php

    r12541 r12745  
    464464     * embed template, which is what we want.
    465465     */
    466     if ( function_exists( 'is_embed' ) && is_embed() ) {
     466    if ( is_embed() ) {
    467467        $located_template = '';
    468468    }
  • 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 ) {
  • trunk/src/bp-core/bp-core-rest-api.php

    r12455 r12745  
    5757     * @param boolean $value True if the BP REST API is available. False otherwise.
    5858     */
    59     return apply_filters( 'bp_rest_api_is_available', function_exists( 'create_initial_rest_routes' ) && bp_rest_in_buddypress() ) || bp_rest_is_plugin_active();
     59    return apply_filters( 'bp_rest_api_is_available', bp_is_running_wp( '4.7.0' ) && bp_rest_in_buddypress() ) || bp_rest_is_plugin_active();
    6060}
    6161
  • trunk/src/bp-core/bp-core-theme-compatibility.php

    r12558 r12745  
    666666function bp_template_include_theme_compat( $template = '' ) {
    667667    // If embed template, bail.
    668     if ( true === function_exists( 'is_embed' ) && is_embed() ) {
     668    if ( is_embed() ) {
    669669        return $template;
    670670    }
  • trunk/src/bp-core/classes/class-bp-admin.php

    r12730 r12745  
    563563    public function add_privacy_policy_content() {
    564564        // Nothing to do if we're running < WP 4.9.6.
    565         if ( version_compare( $GLOBALS['wp_version'], '4.9.6', '<' ) ) {
     565        if ( bp_is_running_wp( '4.9.6', '<' ) ) {
    566566            return;
    567567        }
  • trunk/src/bp-core/classes/class-bp-embed.php

    r12414 r12745  
    118118        $id = apply_filters( 'embed_post_id', 0 );
    119119
    120         $unfiltered_html   = current_user_can( 'unfiltered_html' );
    121         $default_discovery = false;
    122 
    123120        // Since 4.4, WordPress is now an oEmbed provider.
    124         if ( function_exists( 'wp_oembed_register_route' ) ) {
    125             $unfiltered_html   = true;
    126             $default_discovery = true;
    127         }
     121        $unfiltered_html   = true;
     122        $default_discovery = true;
    128123
    129124        /**
  • trunk/src/bp-groups/bp-groups-cssjs.php

    r12531 r12745  
    5151
    5252    $preloaded_members = array();
    53     if ( function_exists( 'rest_preload_api_request' ) ) {
     53    if ( bp_is_running_wp( '5.0.0' ) ) {
    5454        $preloaded_members = rest_preload_api_request( '', $path );
    5555    }
  • trunk/src/bp-groups/bp-groups-filters.php

    r12440 r12745  
    5454
    5555// Support emoji.
    56 if ( function_exists( 'wp_encode_emoji' ) ) {
    57     add_filter( 'groups_group_description_before_save', 'wp_encode_emoji' );
    58 }
     56add_filter( 'groups_group_description_before_save', 'wp_encode_emoji' );
    5957
    6058// Escape output of new group creation details.
  • trunk/src/bp-members/bp-members-template.php

    r12693 r12745  
    24172417function bp_signup_requires_privacy_policy_acceptance() {
    24182418    // Bail if we're running a version of WP that doesn't have the Privacy Policy feature.
    2419     if ( version_compare( $GLOBALS['wp_version'], '4.9.6', '<' ) ) {
     2419    if ( bp_is_running_wp( '4.9.6', '<' ) ) {
    24202420        return false;
    24212421    }
  • trunk/src/bp-messages/bp-messages-filters.php

    r12416 r12745  
    3333add_filter( 'messages_notice_subject_before_save',  'force_balance_tags' );
    3434
    35 if ( function_exists( 'wp_encode_emoji' ) ) {
    36     add_filter( 'messages_message_subject_before_save', 'wp_encode_emoji' );
    37     add_filter( 'messages_message_content_before_save', 'wp_encode_emoji' );
    38     add_filter( 'messages_notice_message_before_save',  'wp_encode_emoji' );
    39     add_filter( 'messages_notice_subject_before_save',  'wp_encode_emoji' );
    40 }
     35add_filter( 'messages_message_subject_before_save', 'wp_encode_emoji' );
     36add_filter( 'messages_message_content_before_save', 'wp_encode_emoji' );
     37add_filter( 'messages_notice_message_before_save',  'wp_encode_emoji' );
     38add_filter( 'messages_notice_subject_before_save',  'wp_encode_emoji' );
    4139
    4240add_filter( 'bp_get_message_notice_subject',     'wptexturize' );
  • trunk/src/bp-settings/bp-settings-functions.php

    r12694 r12745  
    250250    if ( ! empty( $query->post ) ) {
    251251        // WP 5.4 changed the user request function name to wp_get_user_request()
    252         $user_request = function_exists( 'wp_get_user_request' ) ? 'wp_get_user_request' : 'wp_get_user_request_data';
     252        $user_request = bp_is_running_wp( '4.9.6' ) ? 'wp_get_user_request' : 'wp_get_user_request_data';
    253253        return $user_request( $query->post->ID );
    254254    } else {
  • trunk/src/bp-settings/classes/class-bp-settings-component.php

    r12272 r12745  
    194194
    195195        // Export Data - only available for WP 4.9.6+.
    196         if ( true === $show_data_page && version_compare( $GLOBALS['wp_version'], '4.9.6', '>=' ) ) {
     196        if ( true === $show_data_page && bp_is_running_wp( '4.9.6' ) ) {
    197197            $sub_nav[] = array(
    198198                'name'            => __( 'Export Data', 'buddypress' ),
     
    269269
    270270            // Export Data.
    271             if ( true === $show_data_page && version_compare( $GLOBALS['wp_version'], '4.9.6', '>=' ) ) {
     271            if ( true === $show_data_page && bp_is_running_wp( '4.9.6' ) ) {
    272272                $wp_admin_nav[] = array(
    273273                    'parent'   => 'my-account-' . $this->id,
Note: See TracChangeset for help on using the changeset viewer.