Changeset 13304 for trunk/src/bp-core/bp-core-functions.php
- Timestamp:
- 07/26/2022 01:31:07 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-functions.php
r13273 r13304 69 69 $bp = buddypress(); 70 70 return !empty( $bp->db_version_raw ) ? $bp->db_version_raw : 0; 71 } 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' ); 71 127 } 72 128 … … 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 '11.0', 4780 ); 4781 4782 /* 4783 * Respect the site owner's choice to load all deprecated functions. 4784 * Return an empty array to inform no deprecated version files should be loaded. 4785 */ 4786 if ( false === $ignore_deprecated ) { 4787 return $deprecated_functions_versions; 4788 } 4789 4790 /* 4791 * Unless the `BP_IGNORE_DEPRECATED` constant is used & set to false, the development 4792 * version of BuddyPress do not load deprecated functions. 4793 */ 4794 if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src' ) { 4795 return array(); 4796 } 4797 4798 /* 4799 * If the constant is not defined, put our logic in place so that only the 4800 * 2 last versions deprecated functions will be loaded for upgraded installs. 4801 */ 4802 $initial_version = (float) bp_get_initial_version(); 4803 $current_version = (float) bp_get_version(); 4804 $load_latest_deprecated = $initial_version < $current_version; 4805 4806 // We don't load deprecated functions for new installs. 4807 if ( ! $load_latest_deprecated ) { 4808 // Run some additional checks if PHPUnit is running. 4809 if ( defined( 'BP_TESTS_DIR' ) ) { 4810 $deprecated_files = array_filter( 4811 array_map( 4812 function( $file ) { 4813 if ( false !== strpos( $file, '.php' ) ) { 4814 return str_replace( '.php', '', $file ); 4815 }; 4816 }, 4817 scandir( buddypress()->plugin_dir . 'bp-core/deprecated' ) 4818 ) 4819 ); 4820 4821 if ( array_diff( $deprecated_files, $deprecated_functions_versions ) ) { 4822 return false; 4823 } 4824 } 4825 return array(); 4826 } 4827 4828 // Try to get the first major version that was in used when BuddyPress was fist installed. 4829 $first_major = ''; 4830 if ( $initial_version ) { 4831 $first_major = bp_get_major_version( $initial_version ); 4832 } 4833 4834 $index_first_major = array_search( $first_major, $deprecated_functions_versions, true ); 4835 if ( false === $index_first_major ) { 4836 return array_splice( $deprecated_functions_versions, -2 ); 4837 } 4838 4839 $latest_deprecated_functions_versions = array_splice( $deprecated_functions_versions, $index_first_major ); 4840 4841 if ( 2 <= count( $latest_deprecated_functions_versions ) ) { 4842 $latest_deprecated_functions_versions = array_splice( $latest_deprecated_functions_versions, -2 ); 4843 } 4844 4845 $index_initial_version = array_search( $first_major, $latest_deprecated_functions_versions, true ); 4846 if ( false !== $index_initial_version ) { 4847 unset( $latest_deprecated_functions_versions[ $index_initial_version ] ); 4848 } 4849 4850 return $latest_deprecated_functions_versions; 4851 }
Note: See TracChangeset
for help on using the changeset viewer.