Skip to:
Content

BuddyPress.org

Changeset 11174


Ignore:
Timestamp:
10/06/2016 07:30:54 AM (3 years ago)
Author:
r-a-y
Message:

Admin: Block updates to BuddyPress 2.8 if PHP version is < 5.3.

BuddyPress 2.8 is going to require PHP 5.3+. To prepare for this, we are
adding some functionality to block updates to BP 2.8 in the WP admin
dashboard for BP 2.7.0.

Props boonebgorges, r-a-y, hnla, mercime.

See #7196.

Location:
trunk/src/bp-core/admin
Files:
3 edited

Legend:

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

    r11059 r11174  
    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        return;
     1140    }
     1141
     1142    $loader = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php';
     1143
     1144    remove_action( "after_plugin_row_{$loader}", 'wp_plugin_update_row', 10, 2 );
     1145    add_action( "after_plugin_row_{$loader}", 'bp_core_admin_php52_plugin_row', 10, 2 );
     1146}
     1147add_action( 'load-plugins.php', 'bp_core_admin_maybe_disable_update_row_for_php53_requirement', 100 );
     1148
     1149/**
     1150 * On the "Dashboard > Updates" page, remove BuddyPress from plugins list if PHP < 5.3.
     1151 *
     1152 * @since 2.7.0
     1153 */
     1154function bp_core_admin_maybe_remove_from_update_core() {
     1155    if ( bp_core_admin_is_running_php53_or_greater() ) {
     1156        return;
     1157    }
     1158
     1159    // Add filter to remove BP from the update plugins list.
     1160    add_filter( 'site_transient_update_plugins', 'bp_core_admin_remove_buddypress_from_update_transient' );
     1161}
     1162add_action( 'load-update-core.php', 'bp_core_admin_maybe_remove_from_update_core' );
     1163
     1164/**
     1165 * Filter callback to remove BuddyPress from the update plugins list.
     1166 *
     1167 * Attached to the 'site_transient_update_plugins' filter.
     1168 *
     1169 * @since 2.7.0
     1170 *
     1171 * @param  object $retval Object of plugin update data.
     1172 * @return object
     1173 */
     1174function bp_core_admin_remove_buddypress_from_update_transient( $retval ) {
     1175    $loader = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php';
     1176
     1177    // Remove BP from update plugins list.
     1178    if ( isset( $retval->response[ $loader ] ) ) {
     1179        unset( $retval->response[ $loader ] );
     1180    }
     1181
     1182    return $retval;
     1183}
     1184
     1185/**
     1186 * Outputs a replacement for WP's default update notice, when site is not running PHP 5.3 or greater.
     1187 *
     1188 * When we see that a site is not running PHP 5.3 and is trying to update to
     1189 * BP 2.8+, we replace WP's default notice with our own, which both provides a
     1190 * link to our documentation of the requirement, and removes the link that
     1191 * allows a single plugin to be updated.
     1192 *
     1193 * @since 2.7.0
     1194 *
     1195 * @param string $file        Plugin filename. buddypress/bp-loader.php.
     1196 * @param array  $plugin_data Data about the BuddyPress plugin, as returned by the
     1197 *                            plugins API.
     1198 */
     1199function bp_core_admin_php52_plugin_row( $file, $plugin_data ) {
     1200    if ( is_multisite() && ! is_network_admin() ) {
     1201        return;
     1202    }
     1203
     1204    $current = get_site_transient( 'update_plugins' );
     1205    if ( ! isset( $current->response[ $file ] ) ) {
     1206        return false;
     1207    }
     1208
     1209    $response = $current->response[ $file ];
     1210
     1211    // No need to do this if update is for < BP 2.8.
     1212    if ( version_compare( $response->new_version, '2.8', '<' ) ) {
     1213        return false;
     1214    }
     1215
     1216    $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
     1217
     1218    if ( is_network_admin() ) {
     1219        $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
     1220    } else {
     1221        $active_class = is_plugin_active( $file ) ? ' active' : '';
     1222    }
     1223
     1224    // WP 4.6 uses different markup for the plugin row notice.
     1225    if ( function_exists( 'wp_get_ext_types' ) ) {
     1226        $p = '<p>%s</p>';
     1227
     1228    // WP < 4.6.
     1229    } else {
     1230        $p = '%s';
     1231
     1232        // Ugh.
     1233        $active_class .= ' not-shiny';
     1234    }
     1235
     1236    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 inline notice notice-error notice-alt">';
     1237
     1238    printf( $p,
     1239        esc_html__( 'A BuddyPress update is available, but your system is not compatible.', 'buddypress' ) . ' ' .
     1240        sprintf( __( 'See <a href="%s">the Codex guide</a> for more information.', 'buddypress' ), 'https://codex.buddypress.org/getting-started/buddypress-2-8-will-require-php-5-3/' )
     1241    );
     1242
     1243    echo '</div></td></tr>';
     1244
     1245    /*
     1246     * JavaScript to disable the bulk upgrade checkbox.
     1247     * See WP_Plugins_List_Table::single_row().
     1248     */
     1249    $checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
     1250    echo "<script type='text/javascript'>document.getElementById('$checkbox_id').disabled = true;</script>";
     1251}
  • trunk/src/bp-core/admin/css/common-rtl.css

    r11014 r11174  
    22224.0 Emails - Edit page
    23235.0 Tools - BuddyPress
     246.0 Plugins page
    2425------------------------------------------------------------------------------*/
    2526
     
    537538    }
    538539}
     540
     541
     542/*------------------------------------------------------------------------------
     543 * 6.0 Plugins page
     544 *----------------------------------------------------------------------------*/
     545#buddypress-update.not-shiny .update-message {
     546    border-right: 0;
     547    padding-right: 36px;
     548}
     549
     550#buddypress-update.not-shiny .update-message:before {
     551    content: "\f534";
     552}
  • trunk/src/bp-core/admin/css/common.css

    r11014 r11174  
    22224.0 Emails - Edit page
    23235.0 Tools - BuddyPress
     246.0 Plugins page
    2425------------------------------------------------------------------------------*/
    2526
     
    537538    }
    538539}
     540
     541
     542/*------------------------------------------------------------------------------
     543 * 6.0 Plugins page
     544 *----------------------------------------------------------------------------*/
     545#buddypress-update.not-shiny .update-message {
     546    border-left: 0;
     547    padding-left: 36px;
     548}
     549
     550#buddypress-update.not-shiny .update-message:before {
     551    content: "\f534";
     552}
Note: See TracChangeset for help on using the changeset viewer.