Skip to:
Content

BuddyPress.org

Ticket #8461: 8461.patch

File 8461.patch, 2.0 KB (added by imath, 4 years ago)
  • src/bp-core/bp-core-update.php

    diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
    index 1556f6146..f335a20d9 100644
    function bp_update_to_2_7() { 
    552552        bp_add_option( '_bp_ignore_deprecated_code', false );
    553553}
    554554
     555/**
     556 * Retuns needed the fullname field ID for an update task.
     557 *
     558 * @since 8.0.0
     559 *
     560 * @return int The fullname field ID.
     561 */
     562function bp_get_fullname_field_id_for_update() {
     563        /**
     564         * The xProfile component is active by default on new installs, even if it
     565         * might be inactive during this update, we need to set the custom visibility
     566         * for the default field, in case the Administrator decides to reactivate it.
     567         */
     568        global $wpdb;
     569        $bp_prefix = bp_core_get_table_prefix();
     570        return (int) $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE name = %s", addslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) );
     571}
     572
    555573/**
    556574 * 5.0.0 update routine.
    557575 *
    function bp_update_to_5_0() { 
    569587         */
    570588        global $wpdb;
    571589        $bp_prefix = bp_core_get_table_prefix();
    572         $field_id  = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE name = %s", addslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) );
     590        $field_id  = bp_get_fullname_field_id_for_update();
    573591
    574592        $wpdb->insert(
    575593                $bp_prefix . 'bp_xprofile_meta',
    function bp_update_to_8_0() { 
    623641                )
    624642        );
    625643
    626         if ( bp_get_signup_allowed() ) {
     644        // Check if we need to create default signup fields.
     645        $field_id            = bp_get_fullname_field_id_for_update();
     646        $has_signup_position = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$bp_prefix}bp_xprofile_meta WHERE meta_key = 'signup_position' AND object_type = 'field' AND object_id = %d", $field_id ) );
     647        if ( bp_get_signup_allowed() && ! $has_signup_position ) {
    627648                // Get the Primary Group's fields.
    628649                $signup_fields = $wpdb->get_col( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE group_id = 1 ORDER BY field_order ASC" );
    629650