Skip to:
Content

BuddyPress.org

Changeset 12904


Ignore:
Timestamp:
04/23/2021 11:37:10 AM (5 months ago)
Author:
imath
Message:

xProfile: make sure the signup field upgrade task runs only once

Fixes #8461

File:
1 edited

Legend:

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

    r12898 r12904  
    554554
    555555/**
     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
     573/**
    556574 * 5.0.0 update routine.
    557575 *
     
    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(
     
    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" );
Note: See TracChangeset for help on using the changeset viewer.