Skip to:
Content

BuddyPress.org

Ticket #7196: 7196.diff

File 7196.diff, 4.6 KB (added by boonebgorges, 3 years ago)
  • bp-loader.php

    diff --git bp-loader.php bp-loader.php
    index 28a054c..0b91908 100644
     
    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

    diff --git src/bp-core/admin/bp-core-admin-functions.php src/bp-core/admin/bp-core-admin-functions.php
    index cd87ac7..be380b6 100644
    function bp_core_admin_user_spammed_js() { 
    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        return version_compare( PHP_VERSION, '5.3', '>=' );
     1130}
     1131
     1132/**
     1133 * Replaces WP's default update notice on plugins.php with an error message, when site is not running PHP 5.3 or greater.
     1134 *
     1135 * @since 2.7.0
     1136 */
     1137function bp_core_admin_maybe_disable_update_row_for_php53_requirement() {
     1138        if ( ! bp_core_admin_is_running_php53_or_greater() ) {
     1139                remove_action( 'after_plugin_row_buddypress/bp-loader.php', 'wp_plugin_update_row', 10, 2 );
     1140                add_action( 'after_plugin_row_buddypress/bp-loader.php', 'bp_core_admin_php52_plugin_row', 10, 2 );
     1141        }
     1142}
     1143add_action( 'load-plugins.php', 'bp_core_admin_maybe_disable_update_row_for_php53_requirement', 100 );
     1144
     1145/**
     1146 * Outputs a replacement for WP's default update notice, when site is not running PHP 5.3 or greater.
     1147 *
     1148 * When we see that a site is not running PHP 5.3 and is trying to update to BP 2.8+,
     1149 * we do a few things:
     1150 *   - Disable the bulk update checkbox.
     1151 *   - Replace WP's default notice with our own, which both provides a link to
     1152 *     our documentation of the requirement, and removes the link that allows
     1153 *     a single plugin to be updated.
     1154 *
     1155 * @since 2.7.0
     1156 *
     1157 * @param string $file        Plugin filename. buddypress/bp-loader.php.
     1158 * @param array  $plugin_data Data about the BuddyPress plugin, as returned by the
     1159 *                            plugins API.
     1160 */
     1161function bp_core_admin_php52_plugin_row( $file, $plugin_data ) {
     1162        if ( is_multisite() && ! is_network_admin() ) {
     1163                return;
     1164        }
     1165
     1166        $current = get_site_transient( 'update_plugins' );
     1167        if ( ! isset( $current->response[ $file ] ) ) {
     1168                return false;
     1169        }
     1170
     1171        $response = $current->response[ $file ];
     1172
     1173        if ( version_compare( $response->new_version, '2.8', '<' ) ) {
     1174                return false;
     1175        }
     1176
     1177        $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
     1178
     1179        if ( is_network_admin() ) {
     1180                $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
     1181        } else {
     1182                $active_class = is_plugin_active( $file ) ? ' active' : '';
     1183        }
     1184
     1185        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>';
     1186
     1187        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>' );
     1188        echo '</p></td></tr>';
     1189
     1190        // JavaScript to disable the bulk upgrade checkbox.
     1191        $checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
     1192        echo "<script type='text/javascript'>document.getElementById('$checkbox_id').disabled = true;</script>";
     1193}
     1194
     1195/**
     1196 * Disables BP's bulk update checkbox on update-core.php, when minimum PHP requirement is not met.
     1197 *
     1198 * This is the only way we can prevent updates on this page. There are no other hooks,
     1199 * filters, or even CSS selectors.
     1200 *
     1201 * @since 2.7.0
     1202 */
     1203function bp_core_admin_disable_update_from_update_core() {
     1204        if ( bp_core_admin_is_running_php53_or_greater() ) {
     1205                return;
     1206        }
     1207
     1208        $checkbox_id = 'checkbox_' . md5( 'BuddyPress' );
     1209
     1210        ?>
     1211        <script type="text/javascript">
     1212                document.getElementById('<?php echo $checkbox_id; ?>').disabled = true;
     1213        </script>
     1214        <?php
     1215}
     1216add_action( 'core_upgrade_preamble', 'bp_core_admin_disable_update_from_update_core' );