Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/26/2022 01:31:07 PM (21 months ago)
Author:
imath
Message:

Start using a new strategy about deprecated functions management

The main goal of this commit is to change the way we load the files containing deprecated functions. This files are located into the src/bp-core/deprecated/ directory and there's one file for each version of BuddyPress we created to store the deprecate functions.

We noticed that these files were not necessarily loaded although they should have. This case happens to all users who firstly installed BuddyPress when its version was upper than 2.7.

From now on, here's how deprecated code will eventually load into your BuddyPress installation:

  • First installs won't load deprecated code.
  • Updated installs will load the 2 latest BuddyPress versions deprecated code.
  • Defining the BP_IGNORE_DEPRECATED constant to true will change the 2 above points behavior ignoring any BuddyPress versions deprecated code.
  • Defining the BP_IGNORE_DEPRECATED constant to false will change the 2 first points behavior loading all BuddyPress versions deprecated code.

Props djpaul, dcavins.

Fixes #8687

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/functions.php

    r12680 r13304  
    66
    77class BP_Tests_Core_Functions extends BP_UnitTestCase {
     8    protected $bp_initial_version;
     9
    810    /**
    911     * @group bp_esc_sql_order
     
    876878        return array_merge( $page_default_titles, array( 'newcomponent' => 'NewComponent' ) );
    877879    }
     880
     881    public function override_initial_version() {
     882        return $this->bp_initial_version;
     883    }
     884
     885    /**
     886     * @ticket BP8687
     887     */
     888    public function test_bp_get_deprecated_functions_versions() {
     889        $current_version = (float) bp_get_version();
     890        $versions        = bp_get_deprecated_functions_versions();
     891
     892        // When current version is the initial version, we shouldn't load deprecated functions files.
     893        $this->assertTrue( is_array( $versions ) && ! $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.' );
     894
     895        // We should load the 2 lasts deprecated functions files.
     896        $this->bp_initial_version = '8.0';
     897
     898        add_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
     899
     900        $versions = bp_get_deprecated_functions_versions();
     901
     902        remove_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
     903
     904        $this->assertTrue( 2 === count( $versions ) );
     905
     906        // Even if this version does not exist in deprecated functions files, we should load the 2 lasts.
     907        $this->bp_initial_version = '1.0';
     908
     909        add_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
     910
     911        $versions = bp_get_deprecated_functions_versions();
     912
     913        remove_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
     914
     915        $this->assertTrue( 2 === count( $versions ) );
     916    }
    878917}
Note: See TracChangeset for help on using the changeset viewer.