Skip to:
Content

BuddyPress.org

Ticket #7196: 7196.02.patch

File 7196.02.patch, 5.0 KB (added by r-a-y, 3 years ago)
  • bp-loader.php

     
    1515 * Description: BuddyPress helps site builders and WordPress developers add community features to their websites, with user profile fields, activity streams, messaging, and notifications.
    1616 * Author:      The BuddyPress Community
    1717 * Author URI:  https://buddypress.org
    18  * Version:     2.7-alpha
     18 * Version:     2.5
    1919 * Text Domain: buddypress
    2020 * Domain Path: /bp-languages/
    2121 * License:     GPLv2 or later (license.txt)
  • src/bp-core/admin/bp-core-admin-functions.php

     
    11131113        </script>
    11141114        <?php
    11151115}
     1116
     1117/** Upgrade protection *******************************************************/
     1118
     1119/**
     1120 * Determines whether the current installation is running PHP 5.3 or greater.
     1121 *
     1122 * BuddyPress 2.8 introduces a minimum PHP requirement of PHP 5.3.
     1123 *
     1124 * @since 2.7.0
     1125 *
     1126 * @return bool
     1127 */
     1128function bp_core_admin_is_running_php53_or_greater() {
     1129        // @todo change this back to 5.3 before committing!
     1130        return version_compare( PHP_VERSION, '7', '>=' );
     1131}
     1132
     1133/**
     1134 * Replaces WP's default update notice on plugins.php with an error message, when site is not running PHP 5.3 or greater.
     1135 *
     1136 * @since 2.7.0
     1137 */
     1138function bp_core_admin_maybe_disable_update_row_for_php53_requirement() {
     1139        if ( ! bp_core_admin_is_running_php53_or_greater() ) {
     1140                $loader = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php';
     1141
     1142                remove_action( "after_plugin_row_{$loader}", 'wp_plugin_update_row', 10, 2 );
     1143                add_action( "after_plugin_row_{$loader}", 'bp_core_admin_php52_plugin_row', 10, 2 );
     1144
     1145                bp_core_admin_disable_bulk_activate();
     1146        }
     1147}
     1148add_action( 'load-plugins.php', 'bp_core_admin_maybe_disable_update_row_for_php53_requirement', 100 );
     1149
     1150/**
     1151 * Outputs a replacement for WP's default update notice, when site is not running PHP 5.3 or greater.
     1152 *
     1153 * When we see that a site is not running PHP 5.3 and is trying to update to
     1154 * BP 2.8+, we replace WP's default notice with our own, which both provides a
     1155 * link to our documentation of the requirement, and removes the link that
     1156 * allows a single plugin to be updated.
     1157 *
     1158 * @since 2.7.0
     1159 *
     1160 * @param string $file        Plugin filename. buddypress/bp-loader.php.
     1161 * @param array  $plugin_data Data about the BuddyPress plugin, as returned by the
     1162 *                            plugins API.
     1163 */
     1164function bp_core_admin_php52_plugin_row( $file, $plugin_data ) {
     1165        if ( is_multisite() && ! is_network_admin() ) {
     1166                return;
     1167        }
     1168
     1169        $current = get_site_transient( 'update_plugins' );
     1170        if ( ! isset( $current->response[ $file ] ) ) {
     1171                return false;
     1172        }
     1173
     1174        $response = $current->response[ $file ];
     1175
     1176        if ( version_compare( $response->new_version, '2.8', '<' ) ) {
     1177                //return false;
     1178        }
     1179
     1180        $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
     1181
     1182        if ( is_network_admin() ) {
     1183                $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
     1184        } else {
     1185                $active_class = is_plugin_active( $file ) ? ' active' : '';
     1186        }
     1187
     1188        echo '<tr class="plugin-update-tr' . $active_class . '" id="' . esc_attr( $response->slug . '-update' ) . '" data-slug="' . esc_attr( $response->slug ) . '" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice inline notice-error notice-alt"><p>';
     1189
     1190        printf( esc_html__( 'A BuddyPress update is available, but your system is not compatible. See %s for more information.', 'buddypress' ), '<a href="#">some link</a>' );
     1191        echo '</p></td></tr>';
     1192}
     1193
     1194/**
     1195 * Disables bulk update for BuddyPress for older WordPress installs.
     1196 *
     1197 * @since 2.7.0
     1198 */
     1199function bp_core_admin_disable_bulk_activate() {
     1200        $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
     1201
     1202        switch( $wp_list_table->current_action() ) {
     1203                case 'activate-selected':
     1204                        check_admin_referer( 'bulk-plugins' );
     1205var_dump( $_POST['checked'] );
     1206                        // Remove BuddyPress from bulk-activate attempts.
     1207                        if( ! empty( $_POST['checked'] ) ) {
     1208                                $_POST['checked'] = array_diff( $_POST['checked'], array( basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php' ) );
     1209                        }
     1210var_dump( $_POST['checked'] ); die();
     1211                        break;
     1212        }
     1213}
     1214
     1215/**
     1216 * Disables shiny update for BuddyPress.
     1217 *
     1218 * @since 2.7.0
     1219 */
     1220function bp_core_admin_disable_shiny_bulk_update() {
     1221        if ( bp_core_admin_is_running_php53_or_greater() ) {
     1222                return;
     1223        }
     1224
     1225        // Not updating BuddyPress? Bail.
     1226        if ( empty( $_POST['plugin'] ) || basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php' !== $_POST['plugin'] ) {
     1227                return;
     1228        }
     1229
     1230        wp_send_json_error( array(
     1231                'slug'         => 'buddypress',
     1232                'errorCode'    => 'plugin_incompatible',
     1233                'errorMessage' => __( 'Your system is incompatible with the latest version of BuddyPress.', 'buddypress' ),
     1234        ) );
     1235}
     1236add_action( 'wp_ajax_update-plugin', 'bp_core_admin_disable_shiny_bulk_update', 0 );