Ticket #8687: 8687.2.patch
File 8687.2.patch, 10.7 KB (added by , 3 years ago) |
---|
-
src/bp-core/bp-core-functions.php
diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php index d9e4a7eab..c24cb58b5 100644
function bp_db_version_raw() { 70 70 return !empty( $bp->db_version_raw ) ? $bp->db_version_raw : 0; 71 71 } 72 72 73 /** 74 * Output a BuddyPress major version. 75 * 76 * @since 11.0.0 77 * 78 * @param string $version BuddyPress version. 79 */ 80 function bp_major_version( $version = '' ) { 81 echo bp_get_major_version( $version ); 82 } 83 84 /** 85 * Return a BuddyPress major version. 86 * 87 * @since 11.0.0 88 * 89 * @param string $version BuddyPress version. 90 * @return string The corresponding BuddyPress major version. 91 */ 92 function bp_get_major_version( $version = '' ) { 93 if ( ! $version ) { 94 $version = bp_get_version(); 95 } 96 97 $last_wp_like_major_versions = '2.9'; 98 $float_version = (float) $version; 99 100 if ( 1 !== version_compare( $version, $last_wp_like_major_versions ) ) { 101 $major_version = (string) $float_version; 102 } else { 103 $major_version = (int) $float_version . '.0'; 104 } 105 106 return $major_version; 107 } 108 109 /** 110 * Output the BuddyPress version used for its first install. 111 * 112 * @since 11.0.0 113 */ 114 function bp_initial_version() { 115 echo bp_get_initial_version(); 116 } 117 118 /** 119 * Return the BuddyPress version used for its first install. 120 * 121 * @since 11.0.0 122 * 123 * @return string The BuddyPress version used for its first install. 124 */ 125 function bp_get_initial_version() { 126 return bp_get_option( '_bp_initial_major_version', '0' ); 127 } 128 73 129 /** 74 130 * Check whether the current version of WP exceeds a given version. 75 131 * … … function bp_delete_optout_by_id( $id = 0 ) { 4674 4730 $optout_class = new BP_Optout(); 4675 4731 return $optout_class::delete_by_id( $id ); 4676 4732 } 4733 4734 /** 4735 * Get the list of versions needing their deprecated functions to be loaded. 4736 * 4737 * @since 11.0.0 4738 * 4739 * @return array The list of versions needing their deprecated functions to be loaded. 4740 */ 4741 function bp_get_deprecated_functions_versions() { 4742 $ignore_deprecated = null; 4743 if ( defined( 'BP_IGNORE_DEPRECATED' ) ) { 4744 $ignore_deprecated = (bool) BP_IGNORE_DEPRECATED; 4745 } 4746 4747 /* 4748 * Respect the site owner's choice to ignore deprecated functions. 4749 * Return an empty array to inform no deprecated version files should be loaded. 4750 */ 4751 if ( true === $ignore_deprecated ) { 4752 return array(); 4753 } 4754 4755 // List of versions containing deprecated functions. 4756 $deprecated_functions_versions = array( 4757 '1.2', 4758 '1.5', 4759 '1.6', 4760 '1.7', 4761 '1.9', 4762 '2.0', 4763 '2.1', 4764 '2.2', 4765 '2.3', 4766 '2.4', 4767 '2.5', 4768 '2.6', 4769 '2.7', 4770 '2.8', 4771 '2.9', 4772 '3.0', 4773 '4.0', 4774 '6.0', 4775 '7.0', 4776 '8.0', 4777 '9.0', 4778 '10.0', 4779 ); 4780 4781 /* 4782 * Respect the site owner's choice to load all deprecated functions. 4783 * Return an empty array to inform no deprecated version files should be loaded. 4784 */ 4785 if ( false === $ignore_deprecated ) { 4786 return $deprecated_functions_versions; 4787 } 4788 4789 /* 4790 * If the constant is not defined, put our logic in place so that only the 4791 * 2 last versions deprecated functions will be loaded for upgraded installs. 4792 */ 4793 $initial_version = (float) bp_get_initial_version(); 4794 $current_version = (float) bp_get_version(); 4795 $load_latest_deprecated = $initial_version < $current_version; 4796 4797 // We don't load deprecated functions for new installs. 4798 if ( ! $load_latest_deprecated ) { 4799 // Run some additional checks if PHPUnit is running. 4800 if ( defined( 'BP_TESTS_DIR' ) ) { 4801 $deprecated_files = array_filter( 4802 array_map( 4803 function( $file ) { 4804 if ( false !== strpos( $file, '.php' ) ) { 4805 return str_replace( '.php', '', $file ); 4806 }; 4807 }, 4808 scandir( buddypress()->plugin_dir . 'bp-core/deprecated' ) 4809 ) 4810 ); 4811 4812 if ( array_diff( $deprecated_files, $deprecated_functions_versions ) ) { 4813 return false; 4814 } 4815 } 4816 return array(); 4817 } 4818 4819 $index_initial_version = array_search( $initial_version, $deprecated_functions_versions ); 4820 if ( false === $index_initial_version ) { 4821 return array_splice( $deprecated_functions_versions, -2 ); 4822 } 4823 4824 $latest_deprecated_functions_versions = array_splice( $deprecated_functions_versions, $index_initial_version ); 4825 4826 if ( 2 <= count( $latest_deprecated_functions_versions ) ) { 4827 $latest_deprecated_functions_versions = array_splice( $latest_deprecated_functions_versions, -2 ); 4828 } 4829 4830 return $latest_deprecated_functions_versions; 4831 } -
src/bp-core/bp-core-update.php
diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php index 2651cc0c6..357f95614 100644
function bp_version_updater() { 205 205 206 206 // Install BP schema and activate only Activity and XProfile. 207 207 if ( bp_is_install() ) { 208 // Set the first BP major version the plugin was installed. 209 bp_update_option( '_bp_initial_major_version', bp_get_major_version() ); 208 210 209 211 // Apply schema and set Activity and XProfile components as active. 210 212 bp_core_install( $default_components ); … … function bp_core_get_10_0_upgrade_email_schema( $emails ) { 761 763 * @since 11.0.0 762 764 */ 763 765 function bp_update_to_11_0() { 766 bp_delete_option( '_bp_ignore_deprecated_code' ); 764 767 765 768 add_filter( 'bp_email_get_schema', 'bp_core_get_11_0_upgrade_email_schema' ); 766 769 -
src/class-buddypress.php
diff --git src/class-buddypress.php src/class-buddypress.php index b291d956e..e41be0cfd 100644
class BuddyPress { 463 463 * @param string $value Email type taxonomy slug. 464 464 */ 465 465 $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' ); 466 475 } 467 476 468 477 /** … … class BuddyPress { 484 493 if ( ! defined( 'BP_DB_VERSION' ) ) { 485 494 define( 'BP_DB_VERSION', $this->db_version ); 486 495 } 487 488 // Define if deprecated functions should be ignored.489 if ( ! defined( 'BP_IGNORE_DEPRECATED' ) ) {490 define( 'BP_IGNORE_DEPRECATED', true );491 }492 496 } 493 497 494 498 /** … … class BuddyPress { 535 539 require $this->plugin_dir . 'bp-core/bp-core-rest-api.php'; 536 540 require $this->plugin_dir . 'bp-core/bp-core-blocks.php'; 537 541 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'; 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 } 562 553 } 563 554 564 555 // Load wp-cli module if PHP 5.6+. … … class BuddyPress { 719 710 if ( 720 711 ! in_array( $component, array( 'core', 'members' ), true ) && 721 712 ! bp_is_active( $component ) && 722 ! function_exists( 'tests_add_filter' )713 ! $this->is_phpunit_running 723 714 ) { 724 715 return; 725 716 } -
tests/phpunit/testcases/core/functions.php
diff --git tests/phpunit/testcases/core/functions.php tests/phpunit/testcases/core/functions.php index f3c20c1d8..5be246ffd 100644
5 5 */ 6 6 7 7 class BP_Tests_Core_Functions extends BP_UnitTestCase { 8 protected $bp_initial_version; 9 8 10 /** 9 11 * @group bp_esc_sql_order 10 12 */ … … class BP_Tests_Core_Functions extends BP_UnitTestCase { 875 877 public function add_newcomponent_page_title( $page_default_titles = array() ) { 876 878 return array_merge( $page_default_titles, array( 'newcomponent' => 'NewComponent' ) ); 877 879 } 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 } 878 917 }