Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/16/2021 05:29:26 AM (5 years ago)
Author:
imath
Message:

Improve the Field/Group APIs to pick selected fields as signup ones

  • Introduce the bp_xprofile_get_signup_field_ids() function to get an ordered list of field IDs to use as signup fields.
  • Introduce the bp_xprofile_signup_args() function to get the signup arguments to use into the registration page xProfile loop. If no signup fields are available, it falls back to the primary fields group.
  • Introduce the $signup_fields_only xProfile loop argument to restrict fetched fields to signup ones if set to true.
  • Adapt the BP_XProfile_Data_Template class to build a unique xProfile field group out of any possible field groups containing one or more signup fields when the $signup_fields_only argument is set to true and registration is allowed on the site.
  • Adapt the BP_XProfile_Field class to get the possible field's signup position and add a new metabox to add a field to signup ones from the xProfile Field Administration screen.
  • Adapt the BP_XProfile_Group class to ignore non signup fields if the $signup_fields_only argument is set to true.

Props johnjamesjacoby, boonebgorges, DJPaul, Offereins

See #6347

File:
1 edited

Legend:

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

    r12882 r12885  
    14221422    );
    14231423}
     1424
     1425/**
     1426 * Returns the signup field IDs.
     1427 *
     1428 * @since 8.0.0
     1429 *
     1430 * @return int[] The signup field IDs.
     1431 */
     1432function bp_xprofile_get_signup_field_ids() {
     1433    $signup_field_ids = wp_cache_get( 'signup_fields', 'bp_xprofile' );
     1434
     1435    if ( ! $signup_field_ids ) {
     1436        global $wpdb;
     1437        $bp = buddypress();
     1438
     1439        $signup_field_ids = $wpdb->get_col( "SELECT object_id FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND meta_key = 'signup_position' ORDER BY meta_value ASC" );
     1440
     1441        wp_cache_set( 'signup_fields', $signup_field_ids, 'bp_xprofile' );
     1442    }
     1443
     1444    return array_map( 'intval', $signup_field_ids );
     1445}
     1446
     1447/**
     1448 * Returns xProfile loop's signup arguments.
     1449 *
     1450 * @since 8.0.0
     1451 *
     1452 * @param array $extra Optional extra arguments.
     1453 * @return array The xProfile loop's signup arguments.
     1454 */
     1455function bp_xprofile_signup_args( $extra = array() ) {
     1456    $signup_fields = (array) bp_xprofile_get_signup_field_ids();
     1457    $default_args  = array(
     1458        'fetch_fields'     => true,
     1459        'fetch_field_data' => false,
     1460    );
     1461
     1462    // No signup fields? Let's bring back primary group.
     1463    if ( ! $signup_fields && bp_is_register_page() ) {
     1464        $default_args['profile_group_id'] = 1;
     1465    } else {
     1466        $default_args['signup_fields_only'] = true;
     1467    }
     1468
     1469    return array_merge( $default_args, $extra );
     1470}
Note: See TracChangeset for help on using the changeset viewer.