Skip to:
Content

BuddyPress.org

Changeset 11175


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

Admin: Add dismissable notice for BuddyPress 2.8 PHP requirement.

Props boonebgorges.

See #7196.

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

Legend:

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

    r11174 r11175  
    12501250    echo "<script type='text/javascript'>document.getElementById('$checkbox_id').disabled = true;</script>";
    12511251}
     1252
     1253/**
     1254 * Add an admin notice to installations that are not running PHP 5.3+.
     1255 *
     1256 * @since 2.7.0
     1257 */
     1258function bp_core_admin_php53_admin_notice() {
     1259    if ( ! current_user_can( 'update_core' ) ) {
     1260        return;
     1261    }
     1262
     1263    if ( bp_core_admin_is_running_php53_or_greater() ) {
     1264        return;
     1265    }
     1266
     1267    $notice_id = 'bp28-php53';
     1268    if ( bp_get_option( "bp-dismissed-notice-$notice_id" ) ) {
     1269        return;
     1270    }
     1271
     1272    $bp  = buddypress();
     1273    $min = bp_core_get_minified_asset_suffix();
     1274
     1275    wp_enqueue_script(
     1276        'bp-dismissible-admin-notices',
     1277        "{$bp->plugin_url}bp-core/admin/js/dismissible-admin-notices{$min}.js",
     1278        array( 'jquery' ),
     1279        bp_get_version(),
     1280        true
     1281    );
     1282
     1283    $php_version = PHP_VERSION;
     1284
     1285    ?>
     1286
     1287    <div id="message" class="error notice is-dismissible bp-is-dismissible" data-noticeid="<?php echo esc_attr( $notice_id ); ?>">
     1288        <p><strong><?php esc_html_e( 'Your site is not ready for BuddyPress 2.8.', 'buddypress' ); ?></strong></p>
     1289        <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>
     1290        <?php wp_nonce_field( "bp-dismissible-notice-$notice_id", "bp-dismissible-nonce-$notice_id" ); ?>
     1291    </div>
     1292    <?php
     1293}
     1294add_action( 'admin_notices',         'bp_core_admin_php53_admin_notice' );
     1295add_action( 'network_admin_notices', 'bp_core_admin_php53_admin_notice' );
     1296
     1297/**
     1298 * Catch and process an admin notice dismissal.
     1299 *
     1300 * @since 2.7.0
     1301 */
     1302function bp_core_admin_notice_dismiss_callback() {
     1303    if ( ! current_user_can( 'install_plugins' ) ) {
     1304        wp_send_json_error();
     1305    }
     1306
     1307    if ( empty( $_POST['nonce'] ) || empty( $_POST['notice_id'] ) ) {
     1308        wp_send_json_error();
     1309    }
     1310
     1311    $notice_id = wp_unslash( $_POST['notice_id'] );
     1312
     1313    if ( ! wp_verify_nonce( $_POST['nonce'], 'bp-dismissible-notice-' . $notice_id ) ) {
     1314        wp_send_json_error();
     1315    }
     1316
     1317    bp_update_option( "bp-dismissed-notice-$notice_id", 1 );
     1318
     1319    wp_send_json_success();
     1320}
     1321add_action( 'wp_ajax_bp_dismiss_notice', 'bp_core_admin_notice_dismiss_callback' );
Note: See TracChangeset for help on using the changeset viewer.