Skip to:
Content

BuddyPress.org

Ticket #5563: 5563.06.patch

File 5563.06.patch, 3.2 KB (added by johnjamesjacoby, 5 years ago)

Simplify

  • bp-core/bp-core-update.php

     
    448448/** Signups *******************************************************************/
    449449
    450450/**
    451  * Check if the signups table already exists
    452  *
    453  * @since BuddyPress (2.0.1)
    454  *
    455  * @global WPDB $wpdb
    456  *
    457  * @return bool If signups table exists
    458  */
    459 function bp_core_signups_table_exists() {
    460         global $wpdb;
    461 
    462         // Some installations may already have a signups table (multisite, plugins, etc...)
    463         if ( ! empty( $wpdb->signups ) ) {
    464                 return true;
    465         }
    466 
    467         // Suppress errors because users shouldn't see this
    468         $old_suppress = $wpdb->suppress_errors();
    469 
    470         // Never use bp_core_get_table_prefix() for any global users tables
    471         // We also don't use $wpdb->signups because we want decisive evidence.
    472         $table_exists = $wpdb->get_results( "DESCRIBE {$wpdb->base_prefix}signups;" );
    473 
    474         // Restore previous error suppression setting
    475         $wpdb->suppress_errors( $old_suppress );
    476 
    477         // Return whether or not the table exists
    478         return (bool) $table_exists;
    479 }
    480 
    481 /**
    482  * Check if the signups table already exists
    483  *
    484  * @since BuddyPress (2.0.1)
    485  *
    486  * @global WPDB $wpdb
    487  *
    488  * @link https://core.trac.wordpress.org/changeset/25179
    489  *
    490  * @return bool If signup_id column exists
    491  */
    492 function bp_core_signups_id_column_exists() {
    493         global $wpdb;
    494 
    495         // No signups table to query, so bail and return false
    496         if ( empty( $wpdb->signups ) ) {
    497                 return false;
    498         }
    499 
    500         // Suppress errors because users shouldn't see this
    501         $old_suppress = $wpdb->suppress_errors();
    502 
    503         // Never use bp_core_get_table_prefix() for any global users tables
    504         $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$wpdb->signups} LIKE 'signup_id'" );
    505 
    506         // Restore previous error suppression setting
    507         $wpdb->suppress_errors( $old_suppress );
    508 
    509         // Column does not exist
    510         return $column_exists;
    511 }
    512 
    513 /**
    514451 * Check if the signups table needs to be created.
    515452 *
    516453 * @since BuddyPress (2.0.0)
     
    526463                return false;
    527464        }
    528465
     466        global $wpdb;
     467
     468        // The table to run queries against
     469        $signups_table = $wpdb->base_prefix . 'signups';
     470
     471        // Suppress errors because users shouldn't see what happens next
     472        $old_suppress  = $wpdb->suppress_errors();
     473
     474        // Never use bp_core_get_table_prefix() for any global users tables
     475        $table_exists  = (bool) $wpdb->get_results( "DESCRIBE {$signups_table};" );
     476
    529477        // Table already exists, so maybe upgrade instead?
    530         if ( bp_core_signups_table_exists() ) {
     478        if ( true === $table_exists ) {
    531479
     480                // Look for the 'signup_id' column
     481                $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$signups_table} LIKE 'signup_id'" );
     482
    532483                // 'signup_id' column doesn't exist, so run the upgrade
    533                 if ( ! bp_core_signups_id_column_exists() ) {
     484                if ( empty( $column_exists ) ) {
    534485                        bp_core_upgrade_signups();
    535486                }
    536487
    537         // Table does not exist, and not multisite, so install the signups table
     488        // Table does not exist, and we are a single site, so install the multisite
     489        // signups table using WordPress core's database schema.
    538490        } elseif ( ! is_multisite() ) {
    539491                bp_core_install_signups();
    540492        }
     493
     494        // Restore previous error suppression setting
     495        $wpdb->suppress_errors( $old_suppress );
    541496}
    542497
    543498/** Activation Actions ********************************************************/