Skip to:
Content

BuddyPress.org

Changeset 13705


Ignore:
Timestamp:
01/22/2024 03:50:51 AM (2 years ago)
Author:
imath
Message:

Use the current major version to decide about deprecated code to load

Using the current version in case of a minor version was preventing deprecated code to be loaded when this minor version was used to first activate BuddyPress.

Props vapvarun, emaralive

See #9075 (trunk)
Closes https://github.com/buddypress/buddypress/pull/219

Location:
trunk
Files:
3 edited

Legend:

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

    r13682 r13705  
    48474847        // List of versions containing deprecated functions.
    48484848        $deprecated_functions_versions = array(
    4849                 '1.2',
    4850                 '1.5',
    4851                 '1.6',
    4852                 '1.7',
    4853                 '1.9',
    4854                 '2.0',
    4855                 '2.1',
    4856                 '2.2',
    4857                 '2.3',
    4858                 '2.4',
    4859                 '2.5',
    4860                 '2.6',
    4861                 '2.7',
    4862                 '2.8',
    4863                 '2.9',
    4864                 '3.0',
    4865                 '4.0',
    4866                 '6.0',
    4867                 '7.0',
    4868                 '8.0',
    4869                 '9.0',
    4870                 '10.0',
    4871                 '11.0',
    4872                 '12.0',
     4849                1.2,
     4850                1.5,
     4851                1.6,
     4852                1.7,
     4853                1.9,
     4854                2.0,
     4855                2.1,
     4856                2.2,
     4857                2.3,
     4858                2.4,
     4859                2.5,
     4860                2.6,
     4861                2.7,
     4862                2.8,
     4863                2.9,
     4864                3.0,
     4865                4.0,
     4866                6.0,
     4867                7.0,
     4868                8.0,
     4869                9.0,
     4870                10.0,
     4871                11.0,
     4872                12.0,
    48734873        );
    48744874
     
    48944894         */
    48954895        $initial_version        = (float) bp_get_initial_version();
    4896         $current_version        = (float) bp_get_version();
    4897         $load_latest_deprecated = $initial_version < $current_version;
     4896        $current_major_version  = (float) bp_get_major_version( bp_get_version() );
     4897        $load_latest_deprecated = $initial_version < $current_major_version;
    48984898
    48994899        // New installs.
     
    49054905                                        function( $file ) {
    49064906                                                if ( false !== strpos( $file, '.php' ) ) {
    4907                                                         return str_replace( '.php', '', $file );
     4907                                                        return (float) str_replace( '.php', '', $file );
    49084908                                                };
    49094909                                        },
     
    49184918
    49194919                // Only load 12.0 deprecated functions.
    4920                 return array( '12.0' );
    4921         }
    4922 
    4923         // Try to get the first major version that was in used when BuddyPress was fist installed.
    4924         $first_major = '';
    4925         if ( $initial_version ) {
    4926                 $first_major = bp_get_major_version( $initial_version );
    4927         }
    4928 
    4929         $index_first_major = array_search( $first_major, $deprecated_functions_versions, true );
     4920                return array( 12.0 );
     4921        }
     4922
     4923        $index_first_major = array_search( $initial_version, $deprecated_functions_versions, true );
    49304924        if ( false === $index_first_major ) {
    49314925                return array_splice( $deprecated_functions_versions, -2 );
     
    49384932        }
    49394933
    4940         $index_initial_version = array_search( $first_major, $latest_deprecated_functions_versions, true );
     4934        $index_initial_version = array_search( $initial_version, $latest_deprecated_functions_versions, true );
    49414935        if ( false !== $index_initial_version ) {
    49424936                unset( $latest_deprecated_functions_versions[ $index_initial_version ] );
  • trunk/src/class-buddypress.php

    r13667 r13705  
    655655                        foreach ( $deprecated_functions_versions as $deprecated_functions_version ) {
    656656                                // Load all or last 2 deprecated versions.
    657                                 require $this->plugin_dir . sprintf( 'bp-core/deprecated/%s.php', $deprecated_functions_version );
     657                                require $this->plugin_dir . sprintf( 'bp-core/deprecated/%s.php', number_format( $deprecated_functions_version, 1 ) );
    658658                        }
    659659                }
  • trunk/tests/phpunit/testcases/core/functions.php

    r13632 r13705  
    870870        /**
    871871         * @ticket BP8687
     872         * @ticket BP9075
    872873         */
    873874        public function test_bp_get_deprecated_functions_versions() {
    874                 $current_version = (float) bp_get_version();
     875                $current_version = bp_get_version();
    875876                $versions        = bp_get_deprecated_functions_versions();
    876 
    877                 // When current version is the initial version, we should only load 12.0 deprecated functions file.
    878                 $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.' );
     877                $bp              = buddypress();
     878
     879                // When current major version is the initial version, we should only load 12.0 deprecated functions file.
     880                $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.' );
     881
     882                $bp->version = '12.1.1';
     883
     884                // We should load the 2 lasts deprecated functions files.
     885                $this->bp_initial_version = '12.0';
     886
     887                add_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
     888
     889                $versions = bp_get_deprecated_functions_versions();
     890
     891                $this->assertContains( 12.0, $versions, '12.0 deprecated functions should be loaded when 12.1.1 was the first installed version.' );
     892
     893                $this->bp_initial_version = '9.0';
     894
     895                $versions = bp_get_deprecated_functions_versions();
     896
     897                $this->assertContains( 12.0, $versions, '12.0 deprecated functions should be loaded when 12.0 was updated for a minor release' );
     898
     899                remove_filter( 'pre_option__bp_initial_major_version', array( $this, 'override_initial_version' ), 10, 0 );
     900
     901                $bp->version = $current_version;
    879902
    880903                // We should load the 2 lasts deprecated functions files.
Note: See TracChangeset for help on using the changeset viewer.