Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/26/2022 01:31:07 PM (2 years 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/src/class-buddypress.php

    r13303 r13304  
    464464         */
    465465        $this->email_taxonomy_type = apply_filters( 'bp_email_tax_type', 'bp-email-type' );
     466
     467        /**
     468         * Are PHPUnit tests running?
     469         *
     470         * @since 11.0.0
     471         *
     472         * @param bool $value True if PHPUnit tests are running, false otherwise.
     473         */
     474        $this->is_phpunit_running = function_exists( 'tests_add_filter' );
    466475    }
    467476
     
    484493        if ( ! defined( 'BP_DB_VERSION' ) ) {
    485494            define( 'BP_DB_VERSION', $this->db_version );
    486         }
    487 
    488         // Define if deprecated functions should be ignored.
    489         if ( ! defined( 'BP_IGNORE_DEPRECATED' ) ) {
    490             define( 'BP_IGNORE_DEPRECATED', true );
    491495        }
    492496    }
     
    536540        require $this->plugin_dir . 'bp-core/bp-core-blocks.php';
    537541
    538         // Maybe load deprecated functionality (this double negative is proof positive!).
    539         if ( ! bp_get_option( '_bp_ignore_deprecated_code', ! $this->load_deprecated ) ) {
    540             require $this->plugin_dir . 'bp-core/deprecated/1.2.php';
    541             require $this->plugin_dir . 'bp-core/deprecated/1.5.php';
    542             require $this->plugin_dir . 'bp-core/deprecated/1.6.php';
    543             require $this->plugin_dir . 'bp-core/deprecated/1.7.php';
    544             require $this->plugin_dir . 'bp-core/deprecated/1.9.php';
    545             require $this->plugin_dir . 'bp-core/deprecated/2.0.php';
    546             require $this->plugin_dir . 'bp-core/deprecated/2.1.php';
    547             require $this->plugin_dir . 'bp-core/deprecated/2.2.php';
    548             require $this->plugin_dir . 'bp-core/deprecated/2.3.php';
    549             require $this->plugin_dir . 'bp-core/deprecated/2.4.php';
    550             require $this->plugin_dir . 'bp-core/deprecated/2.5.php';
    551             require $this->plugin_dir . 'bp-core/deprecated/2.6.php';
    552             require $this->plugin_dir . 'bp-core/deprecated/2.7.php';
    553             require $this->plugin_dir . 'bp-core/deprecated/2.8.php';
    554             require $this->plugin_dir . 'bp-core/deprecated/2.9.php';
    555             require $this->plugin_dir . 'bp-core/deprecated/3.0.php';
    556             require $this->plugin_dir . 'bp-core/deprecated/4.0.php';
    557             require $this->plugin_dir . 'bp-core/deprecated/6.0.php';
    558             require $this->plugin_dir . 'bp-core/deprecated/7.0.php';
    559             require $this->plugin_dir . 'bp-core/deprecated/8.0.php';
    560             require $this->plugin_dir . 'bp-core/deprecated/9.0.php';
    561             require $this->plugin_dir . 'bp-core/deprecated/10.0.php';
    562             require $this->plugin_dir . 'bp-core/deprecated/11.0.php';
    563         }
     542        // Get the list of versions needing their deprecated functions to be loaded.
     543        $deprecated_functions_versions = bp_get_deprecated_functions_versions();
     544
     545        // Maybe load deprecated functionality.
     546        if ( $deprecated_functions_versions && ! $this->is_phpunit_running ) {
     547            $this->load_deprecated = true;
     548
     549            foreach ( $deprecated_functions_versions as $deprecated_functions_version ) {
     550                // Load all or last 2 deprecated versions.
     551                require $this->plugin_dir . sprintf( 'bp-core/deprecated/%s.php', $deprecated_functions_version );
     552            }
     553        }
    564554
    565555        // Load wp-cli module if PHP 5.6+.
     
    721711            ! in_array( $component, array( 'core', 'members' ), true ) &&
    722712            ! bp_is_active( $component ) &&
    723             ! function_exists( 'tests_add_filter' )
     713            ! $this->is_phpunit_running
    724714        ) {
    725715            return;
Note: See TracChangeset for help on using the changeset viewer.