Skip to:
Content

BuddyPress.org

Changeset 13999


Ignore:
Timestamp:
08/07/2024 02:09:47 PM (2 months ago)
Author:
imath
Message:

Make sure 12.0 deprecated code is loaded until version 15.0

Version 12.0 changed BuddyPress a lot with the introduction of the BP Rewrites API. To give more time to advanced users, BP plugin or theme developers so that they make their code ready for this API, unlike how we deal with deprecated code since r13304 & for the 2 following major releases (14.0 & 15.0), we will carry on loading it to prevent potential errors.

Props emaralive, espellcaste.

Fixes #9210 (branch 14.0)

Location:
branches/14.0
Files:
2 edited

Legend:

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

    r13965 r13999  
    50125012        }
    50135013
    5014         // Only load 12.0 deprecated functions.
    5015         return array( 12.0 );
    5016     }
    5017 
    5018     $index_first_major = array_search( $initial_version, $deprecated_functions_versions, true );
    5019     if ( false === $index_first_major ) {
    5020         return array_splice( $deprecated_functions_versions, -2 );
    5021     }
    5022 
    5023     $latest_deprecated_functions_versions = array_splice( $deprecated_functions_versions, $index_first_major );
    5024 
    5025     if ( 2 <= count( $latest_deprecated_functions_versions ) ) {
    5026         $latest_deprecated_functions_versions = array_splice( $latest_deprecated_functions_versions, -2 );
    5027     }
    5028 
    5029     $index_initial_version = array_search( $initial_version, $latest_deprecated_functions_versions, true );
    5030     if ( false !== $index_initial_version && 12.0 !== $initial_version ) {
    5031         unset( $latest_deprecated_functions_versions[ $index_initial_version ] );
    5032     }
    5033 
    5034     return $latest_deprecated_functions_versions;
     5014        // Load 12.0 deprecated functions only when BP was installed with 12.0, 14.0 or 15.0.
     5015        if ( in_array( $initial_version, array( 12.0, 14.0, 15.0 ), true ) ) {
     5016            return array( 12.0 );
     5017        }
     5018
     5019        return array();
     5020    }
     5021
     5022    $keep_last = 2;
     5023    if ( (float) 15 >= $initial_version ) {
     5024        $keep_last = count( $deprecated_functions_versions ) - array_search( 12.0, $deprecated_functions_versions, true );
     5025    }
     5026
     5027    return array_splice( $deprecated_functions_versions, -$keep_last );
    50355028}
    50365029
  • branches/14.0/tests/phpunit/testcases/core/functions.php

    r13720 r13999  
    879879
    880880    /**
     881     * This test acts like a reminder: $deprecated_functions_versions needs to include each versions of the `/src/bp-core/deprecated` directory.
     882     *
     883     * eg:  if `/src/bp-core/deprecated/15.0.php` exists, then $deprecated_functions_versions should include `15.0`.
     884     *
     885     * @group bp_get_deprecated_functions_versions
     886     * @ticket BP9210
     887     */
     888    public function test_bp_get_deprecated_functions_versions_array_is_consistent_with_deprecated_files() {
     889        // When current major version is the initial version, we shouldn't load any deprecated functions file.
     890        $this->assertTrue( false !== bp_get_deprecated_functions_versions(), 'Please check the list of `$deprecated_functions_versions` in `bp_get_deprecated_functions_versions()`. There should be one for each file of the `/src/bp-core/deprecated` directory.' );
     891    }
     892
     893    /**
     894     * @group bp_get_deprecated_functions_versions
    881895     * @ticket BP8687
    882896     * @ticket BP9075
     897     * @ticket BP9210
    883898     */
    884899    public function test_bp_get_deprecated_functions_versions() {
    885         $current_version = bp_get_version();
     900        $current_version = (float) bp_get_version();
    886901        $versions        = bp_get_deprecated_functions_versions();
    887902        $bp              = buddypress();
    888903
    889         // When current major version is the initial version, we should only load 12.0 deprecated functions file.
    890         $this->assertSame( $versions, array( 12.0 ), 'Please check the list of `$deprecated_functions_versions` in `bp_get_deprecated_functions_versions()`. There should be one for each file of the `/src/bp-core/deprecated` directory.' );
    891 
    892         $bp->version = '12.1.1';
    893 
    894         // We should load the 2 lasts deprecated functions files.
    895         $this->bp_initial_version = '12.0';
    896 
    897904        add_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
    898905
     906        // Fresh install.
     907        $this->bp_initial_version = $current_version;
     908        $expected_versions        = array();
     909
     910        // Include 12.0 until version 15.0.
     911        if ( $current_version <= (float) 15 ) {
     912            $expected_versions = array( 12.0 );
     913        }
     914
    899915        $versions = bp_get_deprecated_functions_versions();
    900916
    901         $this->assertContains( 12.0, $versions, '12.0 deprecated functions should be loaded when 12.1.1 was the first installed version.' );
    902 
    903         $this->bp_initial_version = '9.0';
     917        $this->assertSame( $versions, $expected_versions, 'Deprecated functions are not loaded for fresh installs.' );
     918
     919        // BuddyPress updated from previous versions.
     920        $expected_versions = array( $current_version - 1, $current_version ); // The 2 last deprecated function files.
     921
     922        // First BuddyPress installed version is older than 11.0. In this case, the initial version is 0.
     923        // See https://buddypress.trac.wordpress.org/changeset/13304
     924        $this->bp_initial_version = 0;
    904925
    905926        $versions = bp_get_deprecated_functions_versions();
    906927
    907         $this->assertContains( 12.0, $versions, '12.0 deprecated functions should be loaded when 12.0 was updated for a minor release' );
     928        // Include 12.0 until version 15.0.
     929        if ( $current_version <= (float) 15 ) {
     930            $this->assertContains( 12.0, $versions, '12.0 deprecated functions should be loaded when first installed version is <= 15.0' );
     931        } else {
     932            $this->assertSame( $versions, $expected_versions, 'The last deprecated function files are loaded for updated BuddyPress.' );
     933        }
     934
     935        // Testing with previous major version.
     936        $this->bp_initial_version = $current_version - 1;
     937
     938        $versions = bp_get_deprecated_functions_versions();
     939
     940        // Include 12.0 until version 15.0.
     941        if ( $current_version <= (float) 15 ) {
     942            $this->assertContains( 12.0, $versions, '12.0 deprecated functions should be loaded when first installed version is <= 15.0' );
     943        } else {
     944            $this->assertSame( $versions, $expected_versions, 'The last deprecated function files are loaded for updated BuddyPress.' );
     945        }
     946
     947        // Testing with 2 versions older.
     948        $this->bp_initial_version = (float) 15 === $current_version ? (float) 12 : $current_version - 2;
     949
     950        $versions = bp_get_deprecated_functions_versions();
     951
     952        // Include 12.0 until version 15.0.
     953        if ( $current_version <= (float) 15 ) {
     954            $this->assertContains( 12.0, $versions, '12.0 deprecated functions should be loaded when first installed version is <= 15.0' );
     955        } else {
     956            $this->assertSame( $versions, $expected_versions, 'The last deprecated function files are loaded for updated BuddyPress.' );
     957        }
    908958
    909959        remove_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
    910 
    911         $bp->version = $current_version;
    912 
    913         // We should load the 2 lasts deprecated functions files.
    914         $this->bp_initial_version = '8.0';
    915 
    916         add_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
    917 
    918         $versions = bp_get_deprecated_functions_versions();
    919 
    920         remove_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
    921 
    922         $this->assertTrue( 2 === count( $versions ) );
    923 
    924         // Even if this version does not exist in deprecated functions files, we should load the 2 lasts.
    925         $this->bp_initial_version = '1.0';
    926 
    927         add_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
    928 
    929         $versions = bp_get_deprecated_functions_versions();
    930 
    931         remove_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
    932 
    933         $this->assertTrue( 2 === count( $versions ) );
    934960    }
    935961
Note: See TracChangeset for help on using the changeset viewer.