Skip to:
Content

BuddyPress.org

Changeset 11390


Ignore:
Timestamp:
01/19/2017 07:39:12 PM (8 years ago)
Author:
boonebgorges
Message:

Deprecate 2.7 functions protect against BP upgrades on PHP 5.2.x.

BuddyPress 2.8 will not load on systems running PHP 5.2.x, so that
these functions will do nothing. In the future, their logic can be
repurposed for further PHP requirement upgrades.

Fixes #7277.

Location:
trunk/src/bp-core
Files:
1 added
1 edited

Legend:

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

    r11348 r11390  
    11151115}
    11161116
    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  */
    1128 function 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  */
    1137 function 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 );
    1145     add_action( "after_plugin_row_{$loader}", 'bp_core_admin_php52_plugin_row', 10, 2 );
    1146 }
    1147 add_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  */
    1154 function 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 }
    1162 add_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  */
    1174 function 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  */
    1199 function 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 }
    1252 
    1253 /**
    1254  * Add an admin notice to installations that are not running PHP 5.3+.
    1255  *
    1256  * @since 2.7.0
    1257  */
    1258 function bp_core_admin_php53_admin_notice() {
    1259     // If not on the Plugins page, stop now.
    1260     if ( 'plugins' !== get_current_screen()->parent_base ) {
    1261         return;
    1262     }
    1263 
    1264     if ( ! current_user_can( 'update_core' ) ) {
    1265         return;
    1266     }
    1267 
    1268     if ( bp_core_admin_is_running_php53_or_greater() ) {
    1269         return;
    1270     }
    1271 
    1272     $notice_id = 'bp28-php53';
    1273     if ( bp_get_option( "bp-dismissed-notice-$notice_id" ) ) {
    1274         return;
    1275     }
    1276 
    1277     $bp  = buddypress();
    1278     $min = bp_core_get_minified_asset_suffix();
    1279 
    1280     wp_enqueue_script(
    1281         'bp-dismissible-admin-notices',
    1282         "{$bp->plugin_url}bp-core/admin/js/dismissible-admin-notices{$min}.js",
    1283         array( 'jquery' ),
    1284         bp_get_version(),
    1285         true
    1286     );
    1287 
    1288     $php_version = PHP_VERSION;
    1289 
    1290     ?>
    1291 
    1292     <div id="message" class="error notice is-dismissible bp-is-dismissible" data-noticeid="<?php echo esc_attr( $notice_id ); ?>">
    1293         <p><strong><?php esc_html_e( 'Your site is not ready for BuddyPress 2.8.', 'buddypress' ); ?></strong></p>
    1294         <p><?php printf( esc_html__( 'Your site is currently running PHP version %s, while BuddyPress 2.8 will require version 5.3+.', 'buddypress' ), $php_version ); ?> <?php printf( __( '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/' ); ?></p>
    1295         <?php wp_nonce_field( "bp-dismissible-notice-$notice_id", "bp-dismissible-nonce-$notice_id" ); ?>
    1296     </div>
    1297     <?php
    1298 }
    1299 add_action( 'admin_notices',         'bp_core_admin_php53_admin_notice' );
    1300 add_action( 'network_admin_notices', 'bp_core_admin_php53_admin_notice' );
    1301 
    13021117/**
    13031118 * Catch and process an admin notice dismissal.
Note: See TracChangeset for help on using the changeset viewer.