Skip to:
Content

BuddyPress.org

Ticket #6347: 6347.alt.2.patch

File 6347.alt.2.patch, 48.9 KB (added by imath, 4 years ago)
  • src/bp-core/admin/bp-core-admin-functions.php

    diff --git src/bp-core/admin/bp-core-admin-functions.php src/bp-core/admin/bp-core-admin-functions.php
    index c9a5259e9..b81786427 100644
    function bp_core_add_contextual_help_content( $tab = '' ) { 
    586586                        break;
    587587
    588588                case 'bp-profile-overview':
    589                         $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.', 'buddypress' ) . '<br /><br />' . __( 'Note: Any fields in the first group will appear on the signup page.', 'buddypress' );
     589                        $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.', 'buddypress' ) . '<br /><br />' . __( 'Note: Drag fields from other groups and drop them on the "Signup Fields" tab to include them into your registration form.', 'buddypress' );
    590590                        break;
    591591
    592592                default:
  • src/bp-core/admin/bp-core-admin-schema.php

    diff --git src/bp-core/admin/bp-core-admin-schema.php src/bp-core/admin/bp-core-admin-schema.php
    index d7cab5bbe..7a10e39eb 100644
    function bp_core_install_extended_profiles() { 
    389389                // Make sure the custom visibility is disabled for the default field.
    390390                if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_meta WHERE id = 1" ) ) {
    391391                        $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_meta ( object_id, object_type, meta_key, meta_value ) VALUES ( 1, 'field', 'allow_custom_visibility', 'disabled' );";
     392                        $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_meta ( object_id, object_type, meta_key, meta_value ) VALUES ( 1, 'field', 'signup_position', 1 );";
    392393                }
    393394        }
    394395
  • src/bp-core/bp-core-update.php

    diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
    index a7791c445..7cb66c837 100644
    function bp_update_to_5_0() { 
    598598 * 8.0.0 update routine.
    599599 *
    600600 * - Edit the `new_avatar` activity type's component to `members`.
     601 * - Upgrade Primary xProfile Group's fields to signup fields.
    601602 *
    602603 * @since 8.0.0
    603604 */
    function bp_update_to_8_0() { 
    621622                        '%s',
    622623                )
    623624        );
     625
     626        if ( bp_get_signup_allowed() ) {
     627                // Get the Primary Group's fields.
     628                $signup_fields = $wpdb->get_col( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE group_id = 1 ORDER BY field_order ASC" );
     629
     630                // Migrate potential signup fields.
     631                if ( $signup_fields ) {
     632                        $signup_position = 0;
     633                        foreach ( $signup_fields as $signup_field_id ) {
     634                                $signup_position += 1;
     635
     636                                $wpdb->insert(
     637                                        $bp_prefix . 'bp_xprofile_meta',
     638                                        array(
     639                                                'object_id'   => $signup_field_id,
     640                                                'object_type' => 'field',
     641                                                'meta_key'    => 'signup_position',
     642                                                'meta_value'  => $signup_position,
     643                                        ),
     644                                        array(
     645                                                '%d',
     646                                                '%s',
     647                                                '%s',
     648                                                '%d',
     649                                        )
     650                                );
     651                        }
     652                }
     653        }
    624654}
    625655
    626656/**
  • src/bp-templates/bp-legacy/buddypress/members/register.php

    diff --git src/bp-templates/bp-legacy/buddypress/members/register.php src/bp-templates/bp-legacy/buddypress/members/register.php
    index 4e8418e7f..d263470f2 100644
     
    165165                                        <h2><?php _e( 'Profile Details', 'buddypress' ); ?></h2>
    166166
    167167                                        <?php /* Use the profile field loop to render input fields for the 'base' profile field group */ ?>
    168                                         <?php if ( bp_is_active( 'xprofile' ) ) : if ( bp_has_profile( array( 'profile_group_id' => 1, 'fetch_field_data' => false ) ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
     168                                        <?php if ( bp_is_active( 'xprofile' ) ) : if ( bp_has_profile( bp_xprofile_signup_args() ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
    169169
    170170                                        <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    171171
  • src/bp-templates/bp-nouveau/buddypress/members/register.php

    diff --git src/bp-templates/bp-nouveau/buddypress/members/register.php src/bp-templates/bp-nouveau/buddypress/members/register.php
    index 2c0a688f2..3a4fdfaac 100644
     
    33 * BuddyPress - Members/Blogs Registration forms
    44 *
    55 * @since 3.0.0
    6  * @version 4.0.0
     6 * @version 8.0.0
    77 */
    88
    99?>
     
    3838
    3939                                <?php /***** Extra Profile Details ******/ ?>
    4040
    41                                 <?php if ( bp_is_active( 'xprofile' ) && bp_nouveau_base_account_has_xprofile() ) : ?>
     41                                <?php if ( bp_is_active( 'xprofile' ) && bp_nouveau_has_signup_xprofile_fields( true ) ) : ?>
    4242
    4343                                        <?php bp_nouveau_signup_hook( 'before', 'signup_profile' ); ?>
    4444
  • src/bp-templates/bp-nouveau/includes/template-tags.php

    diff --git src/bp-templates/bp-nouveau/includes/template-tags.php src/bp-templates/bp-nouveau/includes/template-tags.php
    index 3439280fb..5ee755a05 100644
    function bp_nouveau_container_classes() { 
    15151515                }
    15161516
    15171517                // Provide a class token to acknowledge additional extended profile fields added to default account reg screen
    1518                 if ( 'register' === bp_current_component() && bp_is_active( 'xprofile' ) && bp_nouveau_base_account_has_xprofile()) {
     1518                if ( 'register' === bp_current_component() && bp_is_active( 'xprofile' ) && bp_nouveau_has_signup_xprofile_fields()) {
    15191519                        $classes[] = 'extended-default-reg';
    15201520                }
    15211521
  • src/bp-templates/bp-nouveau/includes/xprofile/template-tags.php

    diff --git src/bp-templates/bp-nouveau/includes/xprofile/template-tags.php src/bp-templates/bp-nouveau/includes/xprofile/template-tags.php
    index 26ef5199f..ba92bd40e 100644
     
    33 * xProfile Template tags
    44 *
    55 * @since 3.0.0
    6  * @version 3.0.0
     6 * @version 8.0.0
    77 */
    88
    99// Exit if accessed directly.
    function bp_nouveau_xprofile_edit_visibilty() { 
    6262 * profile fields added to it for the registration screen.
    6363 *
    6464 * @since 3.0.0
     65 * @deprecated 8.0.0
    6566 */
    6667function bp_nouveau_base_account_has_xprofile() {
    67         return (bool) bp_has_profile(
    68                 array(
    69                         'profile_group_id' => 1,
    70                         'fetch_field_data' => false,
    71                 )
    72         );
     68        _deprecated_function( __FUNCTION__, '8.0.0', 'bp_nouveau_has_signup_xprofile_fields()' );
     69        return bp_nouveau_has_signup_xprofile_fields();
     70}
     71
     72/**
     73 * Checks whether there are signup profile fields to display.
     74 *
     75 * @since 8.0.0
     76 *
     77 * @param bool Whether to init an xProfile loop.
     78 * @return bool True if there are signup profile fields to display. False otherwise.
     79 */
     80function bp_nouveau_has_signup_xprofile_fields( $do_loop = false ) {
     81        $signup_fields = (array) bp_xprofile_get_signup_field_ids();
     82
     83        if ( ! $do_loop ) {
     84                return 1 <= count( $signup_fields );
     85        }
     86
     87        return bp_has_profile( bp_xprofile_signup_args() );
    7388}
  • src/bp-xprofile/admin/css/admin.css

    diff --git src/bp-xprofile/admin/css/admin.css src/bp-xprofile/admin/css/admin.css
    index b84db929a..36d01b81c 100644
    ul#field-group-tabs li.ui-state-active a.ui-tab { 
    6262        color: #000;
    6363}
    6464
     65li#signup-group a:focus {
     66        box-shadow: none;
     67}
     68
    6569/* Toolbar */
    6670.tab-toolbar {
    6771        clear: left;
  • src/bp-xprofile/admin/js/admin.js

    diff --git src/bp-xprofile/admin/js/admin.js src/bp-xprofile/admin/js/admin.js
    index 99a5b4b5d..0773d6548 100644
    function show_options( forWhat ) { 
    9696        }
    9797
    9898        // Show/hides metaboxes according to selected field type supports.
    99         jQuery( '#field-type-visibiliy-metabox, #field-type-required-metabox, #field-type-autolink-metabox, #field-type-member-types' ).show();
     99        jQuery( '#field-type-visibiliy-metabox, #field-type-required-metabox, #field-type-autolink-metabox, #field-type-member-types, #field-signup-position-metabox' ).show();
    100100        if ( -1 !== XProfileAdmin.hide_required_metabox.indexOf( forWhat ) ) {
    101101                jQuery( '#field-type-required-metabox' ).hide();
    102102        }
    103103
     104        if ( -1 !== XProfileAdmin.hide_signup_position_metabox.indexOf( forWhat ) ) {
     105                jQuery( '#field-signup-position-metabox' ).hide();
     106        }
     107
    104108        if ( -1 !== XProfileAdmin.hide_allow_custom_visibility_metabox.indexOf( forWhat ) ) {
    105109                jQuery( '#field-type-visibiliy-metabox' ).hide();
    106110        }
    function titleHint( id ) { 
    207211}
    208212
    209213jQuery( function() {
     214        var isMovingToSignups = false;
    210215
    211216        // Set focus in Field Title, if we're on the right page.
    212217        jQuery( '#bp-xprofile-add-field #title' ).trigger( 'focus' );
    jQuery( function() { 
    248253                cursor: 'move',
    249254                axis: 'x',
    250255                opacity: 1,
    251                 items: 'li',
     256                items: 'li:not(.not-sortable)',
    252257                tolerance: 'intersect',
    253258
    254259                update: function() {
    jQuery( function() { 
    270275                tolerance: 'pointer',
    271276
    272277                update: function() {
     278                        if ( isMovingToSignups ) {
     279                                return false;
     280                        }
     281
    273282                        jQuery.post( ajaxurl, {
    274283                                action: 'xprofile_reorder_fields',
    275284                                'cookie': encodeURIComponent(document.cookie),
    jQuery( function() { 
    348357                        // When field is dropped on tab.
    349358                        drop: function( ev, ui ) {
    350359                                var $item = jQuery(this), // The tab
    351                                         $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' ); // The tab body
     360                                        $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' ), // The tab body
     361                                        dropInGroup = function( fieldId ) {
     362                                                var fieldOrder, postData = {
     363                                                        action: 'xprofile_reorder_fields',
     364                                                        'cookie': encodeURIComponent(document.cookie),
     365                                                        '_wpnonce_reorder_fields': jQuery( 'input#_wpnonce_reorder_fields' ).val(),
     366                                                };
     367
     368                                                // Select new tab as current.
     369                                                $tabs.tabs( 'option', 'active', $tab_items.index( $item ) );
     370
     371                                                // Refresh $list variable.
     372                                                $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' );
     373                                                jQuery($list).find( 'p.nofields' ).hide( 'slow' );
     374
     375                                                jQuery.extend( postData, {
     376                                                        'field_group_id': jQuery( $list ).attr( 'id' ),
     377                                                        'group_tab': jQuery( $item ).prop( 'id' )
     378                                                } );
     379
     380                                                // Set serialized data
     381                                                fieldOrder = jQuery( $list ).sortable( 'serialize' );
     382
     383                                                if ( fieldId ) {
     384                                                        var serializedField = fieldId.replace( 'draggable_field_', 'draggable_signup_field[]=' );
     385                                                        if ( fieldOrder ) {
     386                                                                fieldOrder += '&' + serializedField;
     387                                                        } else {
     388                                                                fieldOrder = serializedField;
     389                                                        }
     390
     391                                                        jQuery.extend( postData, {
     392                                                                'new_signup_field_id': serializedField,
     393                                                        } );
     394                                                } else {
     395                                                        // Show new placement.
     396                                                        jQuery( this ).appendTo( $list ).show( 'slow' ).animate( { opacity: '1' }, 500 );
     397
     398                                                        // Refresh $list variable.
     399                                                        $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' );
     400
     401                                                        // Reset serialized data.
     402                                                        fieldOrder = jQuery( $list ).sortable( 'serialize' );
     403
     404                                                        jQuery.extend( postData, {
     405                                                                'field_group_id': jQuery( $list ).attr( 'id' )
     406                                                        } );
     407                                                }
     408
     409                                                jQuery.extend( postData, {
     410                                                        'field_order': fieldOrder,
     411                                                } );
     412
     413                                                // Ajax update field locations and orders.
     414                                                jQuery.post( ajaxurl, postData, function( response ) {
     415                                                        if ( response.data && response.data.signup_field ) {
     416                                                                jQuery( $list ).append( response.data.signup_field );
     417
     418                                                                if ( response.data.field_id ) {
     419                                                                        jQuery( '#draggable_field_' + response.data.field_id + ' legend' ).append(
     420                                                                                jQuery( '<span></span>' ).addClass( 'bp-signup-field-label' ).html( XProfileAdmin.signup_info )
     421                                                                        );
     422                                                                }
     423                                                        }
     424                                                }, 'json' ).always( function() {
     425                                                        isMovingToSignups = false;
     426                                                } );
     427                                        };
    352428
    353429                                // Remove helper class.
    354430                                jQuery($item).removeClass( 'drop-candidate' );
    355431
    356                                 // Hide field, change selected tab, and show new placement.
    357                                 ui.draggable.hide( 'slow', function() {
    358 
    359                                         // Select new tab as current.
    360                                         $tabs.tabs( 'option', 'active', $tab_items.index( $item ) );
    361 
    362                                         // Show new placement.
    363                                         jQuery(this).appendTo($list).show( 'slow' ).animate( {opacity: '1'}, 500 );
    364 
    365                                         // Refresh $list variable.
    366                                         $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' );
    367                                         jQuery($list).find( 'p.nofields' ).hide( 'slow' );
    368 
    369                                         // Ajax update field locations and orders.
    370                                         jQuery.post( ajaxurl, {
    371                                                 action: 'xprofile_reorder_fields',
    372                                                 'cookie': encodeURIComponent(document.cookie),
    373                                                 '_wpnonce_reorder_fields': jQuery( 'input#_wpnonce_reorder_fields' ).val(),
    374                                                 'field_order': jQuery( $list ).sortable( 'serialize' ),
    375                                                 'field_group_id': jQuery( $list ).attr( 'id' )
    376                                         },
    377                                         function() {} );
    378                                 });
     432                                if ( 'signup-group' === jQuery( $item ).prop( 'id' ) ) {
     433                                        // Simply add the field to signup ones.
     434                                        dropInGroup( ui.draggable.prop( 'id' ) );
     435
     436                                } else if ( ! ui.draggable.prop( 'id' ).match( /draggable_signup_field_([0-9]+)/ ) ) {
     437                                        // Hide field, change selected tab, and show new placement.
     438                                        ui.draggable.hide( 'slow', dropInGroup );
     439                                }
    379440                        },
    380441                        over: function() {
     442                                isMovingToSignups = true;
    381443                                jQuery(this).addClass( 'drop-candidate' );
    382444                        },
    383445                        out: function() {
    384446                                jQuery(this).removeClass( 'drop-candidate' );
     447                                isMovingToSignups = false;
    385448                        }
    386449                });
    387450        }
     451
     452        jQuery( '#signup-fields' ).on( 'click', '.removal', function( e ) {
     453                e.preventDefault();
     454
     455                var fieldId = jQuery( e.target ).attr( 'href' ).replace( '#remove_field-', '' ),
     456                    container = jQuery( e.target ).closest( '#draggable_signup_field_' + fieldId );
     457
     458                if ( ! fieldId ) {
     459                        return false;
     460                }
     461
     462                // Ajax update field locations and orders.
     463                jQuery.post( ajaxurl, {
     464                        action: 'xprofile_remove_signup_field',
     465                        'cookie': encodeURIComponent(document.cookie),
     466                        '_wpnonce_reorder_fields': jQuery( 'input#_wpnonce_reorder_fields' ).val(),
     467                        'signup_field_id': fieldId
     468                }, function( response ) {
     469                        if ( response.success ) {
     470                                jQuery( container ).remove();
     471                                jQuery( '#draggable_field_' + fieldId + ' .bp-signup-field-label' ).remove();
     472                        }
     473                }, 'json' );
     474        } );
    388475});
  • src/bp-xprofile/bp-xprofile-admin.php

    diff --git src/bp-xprofile/bp-xprofile-admin.php src/bp-xprofile/bp-xprofile-admin.php
    index 5bd8a899d..ed45fdd0f 100644
    function xprofile_admin_screen( $message = '', $type = 'error' ) { 
    188188
    189189                                        <?php endforeach; endif; ?>
    190190
     191                                        <?php if ( bp_get_signup_allowed() ) : ?>
     192                                                <li id="signup-group" class="not-sortable last">
     193                                                        <a href="#tabs-signup-group" class="ui-tab">
     194                                                                <?php esc_html_e( 'Signup Fields', 'buddypress' ); ?>
     195                                                        </a>
     196                                                </li>
     197                                        <?php endif; ?>
     198
    191199                                </ul>
    192200
    193201                                <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) :
    function xprofile_admin_screen( $message = '', $type = 'error' ) { 
    294302
    295303                                                </fieldset>
    296304
    297                                                 <?php if ( empty( $group->can_delete ) ) : ?>
    298 
    299                                                         <p><?php esc_html_e( '* Fields in this group appear on the signup page.', 'buddypress' ); ?></p>
    300 
    301                                                 <?php endif; ?>
    302 
    303305                                        </div>
    304306
    305307                                <?php endforeach; else : ?>
    function xprofile_admin_screen( $message = '', $type = 'error' ) { 
    309311
    310312                                <?php endif; ?>
    311313
     314                                <?php
     315                                // List fields to use into the signup form.
     316                                if ( bp_get_signup_allowed() ) {
     317                                        $signup_groups = bp_xprofile_get_groups(
     318                                                array(
     319                                                        'fetch_fields'       => true,
     320                                                        'signup_fields_only' => true,
     321                                                )
     322                                        );
     323                                        $has_signup_fields   = false;
     324                                        $signup_fields       = array();
     325                                        $signup_fields_order = bp_xprofile_get_signup_field_ids();
     326                                        ?>
     327                                        <div id="tabs-signup-group"" class="tab-wrapper">
     328                                                <div class="tab-toolbar">
     329                                                        <p class="description"><?php esc_html_e( 'Drag fields from other groups and drop them on the above tab to include them into your registration form.', 'buddypress' ); ?></a>
     330                                                </div>
     331                                                <fieldset id="signup-fields" class="connectedSortable field-group" aria-live="polite" aria-atomic="true" aria-relevant="all">
     332                                                        <legend class="screen-reader-text">
     333                                                                <?php esc_html_e( 'Fields to use into the registration form', 'buddypress' );?>
     334                                                        </legend>
     335
     336                                                        <?php
     337                                                        if ( ! empty( $signup_groups ) ) {
     338                                                                foreach ( $signup_groups as $signup_group ) {
     339                                                                        if ( ! empty( $signup_group->fields ) ) {
     340                                                                                $has_signup_fields = true;
     341
     342                                                                                foreach ( $signup_group->fields as $signup_field ) {
     343                                                                                        // Load the field.
     344                                                                                        $_signup_field = xprofile_get_field( $signup_field, null, false );
     345
     346                                                                                        /**
     347                                                                                         * This function handles the WYSIWYG profile field
     348                                                                                         * display for the xprofile admin setup screen.
     349                                                                                         */
     350                                                                                        $signup_fields[ $_signup_field->id ] = bp_xprofile_admin_get_signup_field( $_signup_field, $signup_group, '' );
     351                                                                                }
     352                                                                        }
     353                                                                }
     354
     355                                                                // Output signup fields according to their signup position.
     356                                                                foreach ( $signup_fields_order as $ordered_signup_field_id ) {
     357                                                                        if ( ! isset( $signup_fields[ $ordered_signup_field_id ] ) ) {
     358                                                                                continue;
     359                                                                        }
     360
     361                                                                        echo $signup_fields[ $ordered_signup_field_id ];
     362                                                                }
     363                                                        }
     364
     365                                                        if ( ! $has_signup_fields ) {
     366                                                                ?>
     367                                                                <p class="nodrag nofields"><?php esc_html_e( 'There are no registration fields set. The registration form uses the primary group by default.', 'buddypress' ); ?></p>
     368                                                                <?php
     369                                                        }
     370                                                        ?>
     371                                                </fieldset>
     372
     373                                                <p><?php esc_html_e( '* Fields in this group appear on the registration page.', 'buddypress' ); ?></p>
     374                                        </div>
     375                                        <?php
     376                                }
     377                                ?>
    312378                        </div>
    313379                </form>
    314380        </div>
    315 
    316381<?php
    317382}
    318383
    function xprofile_admin_manage_field( $group_id, $field_id = null ) { 
    575640                                }
    576641
    577642                                // Validate signup.
    578                                 if ( ! empty( $_POST['signup-position'] ) ) {
    579                                         bp_xprofile_update_field_meta( $field_id, 'signup_position', (int) $_POST['signup-position'] );
    580                                 } else {
    581                                         bp_xprofile_delete_meta( $field_id, 'field', 'signup_position' );
     643                                if ( $field->field_type_supports( 'signup_position' ) ) {
     644                                        if ( ! empty( $_POST['signup-position'] ) ) {
     645                                                bp_xprofile_update_field_meta( $field_id, 'signup_position', (int) $_POST['signup-position'] );
     646                                        } else {
     647                                                bp_xprofile_delete_meta( $field_id, 'field', 'signup_position' );
     648                                        }
    582649                                }
    583650
    584651                                $do_autolink = '';
    function xprofile_admin_delete_field_screen( $field_id, $field_type ) { 
    730797 * Handles the ajax reordering of fields within a group.
    731798 *
    732799 * @since 1.0.0
     800 * @since 8.0.0 Returns a JSON object.
    733801 */
    734802function xprofile_ajax_reorder_fields() {
    735 
    736803        // Check the nonce.
    737804        check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' );
    738805
    739806        if ( empty( $_POST['field_order'] ) ) {
    740                 return false;
     807                return wp_send_json_error();
    741808        }
    742809
    743         parse_str( $_POST['field_order'], $order );
    744 
    745810        $field_group_id = $_POST['field_group_id'];
     811        $group_tab      = '';
     812
     813        if ( isset( $_POST['group_tab'] ) && $_POST['group_tab'] ) {
     814                $group_tab = wp_unslash( $_POST['group_tab'] );
     815        }
     816
     817        if ( 'signup-fields' === $field_group_id ) {
     818                parse_str( $_POST['field_order'], $order );
     819                $fields = (array) $order['draggable_signup_field'];
     820                $fields = array_map( 'intval', $fields );
     821
     822                if ( isset( $_POST['new_signup_field_id'] ) && $_POST['new_signup_field_id'] ) {
     823                        parse_str( $_POST['new_signup_field_id'], $signup_field );
     824                        $signup_fields = (array) $signup_field['draggable_signup_field'];
     825                }
     826
     827                // Adding a new field to the registration form.
     828                if ( 'signup-group' === $group_tab ) {
     829                        $field_id = (int) reset( $signup_fields );
     830
     831                        // Load the field.
     832                        $field = xprofile_get_field( $field_id, null, false );
     833
     834                        if ( $field instanceof BP_XProfile_Field ) {
     835                                // The field doesn't support the feature, stop right away!
     836                                if ( ! $field->field_type_supports( 'signup_position' ) ) {
     837                                        wp_send_json_error(
     838                                                array(
     839                                                        'message' => __( 'This field cannot be inserted into the registration form.', 'buddypress' ),
     840                                                )
     841                                        );
     842                                }
     843
     844                                $signup_position = bp_xprofile_get_meta( $field->id, 'field', 'signup_position' );
     845
     846                                if ( ! $signup_position ) {
     847                                        $position = array_search( $field->id, $fields, true );
     848                                        if ( false !== $position ) {
     849                                                $position += 1;
     850                                        } else {
     851                                                $position = 1;
     852                                        }
     853
     854                                        // Set the signup position.
     855                                        bp_xprofile_update_field_meta( $field->id, 'signup_position', $position );
     856
     857                                        // Get the real Group object.
     858                                        $group = xprofile_get_field_group( $field->id );
     859
     860                                        // Gets the HTML Output of the signup field.
     861                                        $signup_field = bp_xprofile_admin_get_signup_field( $field, $group );
     862
     863                                        /**
     864                                         * Fires once a signup field has been inserted.
     865                                         *
     866                                         * @since 8.0.0
     867                                         */
     868                                        do_action( 'bp_xprofile_inserted_signup_field' );
     869
     870                                        // Send the signup field to output.
     871                                        wp_send_json_success(
     872                                                array(
     873                                                        'signup_field' => $signup_field,
     874                                                        'field_id'     => $field->id,
     875                                                )
     876                                        );
     877                                } else {
     878                                        wp_send_json_error(
     879                                                array(
     880                                                        'message' => __( 'This field has been already added to the registration form.', 'buddypress' ),
     881                                                )
     882                                        );
     883                                }
     884
     885                        } else {
     886                                wp_send_json_error();
     887                        }
     888                } else {
     889                        // it's a sort operation.
     890                        foreach ( $fields as $position => $field_id ) {
     891                                bp_xprofile_update_field_meta( (int) $field_id, 'signup_position', (int) $position + 1 );
     892                        }
    746893
    747         foreach ( (array) $order['draggable_field'] as $position => $field_id ) {
    748                 xprofile_update_field_position( (int) $field_id, (int) $position, (int) $field_group_id );
     894                        /**
     895                         * Fires once the signup fields have been reordered.
     896                         *
     897                         * @since 8.0.0
     898                         */
     899                        do_action( 'bp_xprofile_reordered_signup_fields' );
     900
     901                        wp_send_json_success();
     902                }
     903        } else {
     904                /**
     905                 * @todo there's something going wrong here.
     906                 * moving a field to another tab when there's only the fullname field fails.
     907                 */
     908                parse_str( $_POST['field_order'], $order );
     909                $fields = (array) $order['draggable_field'];
     910
     911                foreach ( $fields as $position => $field_id ) {
     912                        xprofile_update_field_position( (int) $field_id, (int) $position, (int) $field_group_id );
     913                }
     914
     915                wp_send_json_success();
    749916        }
    750917}
    751918add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' );
    752919
     920/**
     921 * Removes a field from signup fields.
     922 *
     923 * @since 8.0.0
     924 */
     925function bp_xprofile_ajax_remove_signup_field() {
     926        // Check the nonce.
     927        check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' );
     928
     929        if ( ! isset( $_POST['signup_field_id'] ) || ! $_POST['signup_field_id'] ) {
     930                return wp_send_json_error();
     931        }
     932
     933        $signup_field_id = (int) wp_unslash( $_POST['signup_field_id'] );
     934
     935        // Validate the field ID.
     936        $signup_position = bp_xprofile_get_meta( $signup_field_id, 'field', 'signup_position' );
     937
     938        if ( ! $signup_position ) {
     939                wp_send_json_error();
     940        }
     941
     942        bp_xprofile_delete_meta( $signup_field_id, 'field', 'signup_position' );
     943
     944        /**
     945         * Fires when a signup field is removed from the signup form.
     946         *
     947         * @since 8.0.0
     948         */
     949        do_action( 'bp_xprofile_removed_signup_field' );
     950
     951        wp_send_json_success();
     952}
     953add_action( 'wp_ajax_xprofile_remove_signup_field', 'bp_xprofile_ajax_remove_signup_field' );
     954
    753955/**
    754956 * Handles the reordering of field groups.
    755957 *
    add_action( 'wp_ajax_xprofile_reorder_groups', 'xprofile_ajax_reorder_field_grou 
    776978 * Handles the WYSIWYG display of each profile field on the edit screen.
    777979 *
    778980 * @since 1.5.0
     981 * @since 8.0.0 Adds the `$is_signup` parameter.
    779982 *
    780983 * @param BP_XProfile_Field   $admin_field Admin field.
    781984 * @param object $admin_group Admin group object.
    782985 * @param string $class       Classes to append to output.
     986 * @param bool   $is_signup   Whether the admin field output is made inside the signup group.
    783987 */
    784 function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) {
     988function xprofile_admin_field( $admin_field, $admin_group, $class = '', $is_signup = false ) {
    785989        global $field;
    786990
    787         $field = $admin_field;
     991        $field       = $admin_field;
     992        $fieldset_id = sprintf( 'draggable_field_%d', $field->id );
    788993
    789994        // Users admin URL.
    790995        $url = bp_get_admin_url( 'users.php' );
    function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 
    8041009                        'mode'     => 'delete_field',
    8051010                        'field_id' => (int) $field->id
    8061011                ), $url . '#tabs-' . (int) $field->group_id );
    807         } ?>
     1012        }
     1013
     1014        // Avoid duplicate IDs into the signup group.
     1015        if ( $is_signup ) {
     1016                $fieldset_id = sprintf( 'draggable_signup_field_%d', $field->id );
     1017        }
     1018        ?>
    8081019
    809         <fieldset id="draggable_field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( !empty( $class ) ) echo ' ' . $class; ?>">
     1020        <fieldset id="<?php echo esc_attr( $fieldset_id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( !empty( $class ) ) echo ' ' . $class; ?>">
    8101021                <legend>
    8111022                        <span>
    8121023                                <?php bp_the_profile_field_name(); ?>
    8131024
    814                                 <?php if ( empty( $field->can_delete )                                    ) : ?><?php esc_html_e( '(Primary)', 'buddypress' ); endif; ?>
     1025                                <?php if ( empty( $field->can_delete ) ) : ?><?php esc_html_e( '(Primary)', 'buddypress' ); endif; ?>
    8151026                                <?php bp_the_profile_field_required_label(); ?>
    816                                 <?php if ( bp_xprofile_get_meta( $field->id, 'field', 'signup_position' ) ) : ?><?php esc_html_e( '(Sign-up)', 'buddypress' ); endif; ?>
     1027                                <?php if ( bp_get_signup_allowed() && $field->get_signup_position() ) : ?>
     1028                                        <span class="bp-signup-field-label"><?php esc_html_e( '(Sign-up)', 'buddypress' );?></span>
     1029                                <?php endif; ?>
    8171030                                <?php if ( bp_get_member_types() ) : echo $field->get_member_type_label(); endif; ?>
    8181031
    8191032                                <?php
    function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 
    8591072                        <div class="actions">
    8601073                                <a class="button edit" href="<?php echo esc_url( $field_edit_url ); ?>"><?php _ex( 'Edit', 'Edit field link', 'buddypress' ); ?></a>
    8611074
    862                                 <?php if ( $field->can_delete ) : ?>
     1075                                <?php if ( $field->can_delete && ! $is_signup ) : ?>
    8631076
    8641077                                        <div class="delete-button">
    8651078                                                <a class="confirm submit-delete deletion" href="<?php echo esc_url( wp_nonce_url( $field_delete_url, 'bp_xprofile_delete_field-' . $field->id, 'bp_xprofile_delete_field' ) ); ?>"><?php _ex( 'Delete', 'Delete field link', 'buddypress' ); ?></a>
    function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 
    8671080
    8681081                                <?php endif; ?>
    8691082
     1083                                <?php if ( $field->can_delete && $is_signup ) : ?>
     1084
     1085                                        <div class="delete-button">
     1086                                                <a class="submit-delete removal" href="<?php echo esc_attr( sprintf( '#remove_field-%d', $field->id ) ); ?>"><?php echo esc_html_x( 'Remove', 'Remove field link', 'buddypress' ); ?></a>
     1087                                        </div>
     1088
     1089                                <?php endif; ?>
     1090
    8701091                                <?php
    8711092
    8721093                                /**
    function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 
    8821103                        </div>
    8831104                </div>
    8841105        </fieldset>
    885 
    8861106<?php
    8871107}
    8881108
     1109/**
     1110 * Handles the WYSIWYG display of signup profile fields on the edit screen.
     1111 *
     1112 * @since 8.0.0
     1113 *
     1114 * @param BP_XProfile_Field   $signup_field The field to use into the signup form.
     1115 * @param object $field_group The real field group object.
     1116 * @param string $class       Classes to append to output.
     1117 * @param bool   $echo        Whether to return or display the HTML output.
     1118 * @return string The HTML output.
     1119 */
     1120function bp_xprofile_admin_get_signup_field( $signup_field, $field_group = null, $class = '', $echo = false ) {
     1121        add_filter( 'bp_get_the_profile_field_input_name', 'bp_get_the_profile_signup_field_input_name' );
     1122
     1123        if ( ! $echo ) {
     1124                // Set up an output buffer.
     1125                ob_start();
     1126                xprofile_admin_field( $signup_field, $field_group, $class, true );
     1127                $output = ob_get_contents();
     1128                ob_end_clean();
     1129        } else {
     1130                xprofile_admin_field( $signup_field, $field_group, $class, true );
     1131        }
     1132
     1133        remove_filter( 'bp_get_the_profile_field_input_name', 'bp_get_the_profile_signup_field_input_name' );
     1134
     1135        if ( ! $echo ) {
     1136                return $output;
     1137        }
     1138}
     1139
    8891140/**
    8901141 * Print <option> elements containing the xprofile field types.
    8911142 *
  • src/bp-xprofile/bp-xprofile-cache.php

    diff --git src/bp-xprofile/bp-xprofile-cache.php src/bp-xprofile/bp-xprofile-cache.php
    index 5c5badae5..6881b7082 100644
    function bp_xprofile_reset_user_mid_cache( $user_id ) { 
    314314        wp_cache_delete( $user_id, 'bp_user_mid' );
    315315}
    316316add_action( 'profile_update', 'bp_xprofile_reset_user_mid_cache', 10, 1 );
     317
     318/**
     319 * Resets the signup field IDs cache.
     320 *
     321 * @since 8.0.0
     322 */
     323function bp_xprofile_reset_signup_field_cache() {
     324        wp_cache_delete( 'signup_fields', 'bp_xprofile' );
     325}
     326add_action( 'bp_xprofile_inserted_signup_field', 'bp_xprofile_reset_signup_field_cache' );
     327add_action( 'bp_xprofile_reordered_signup_fields', 'bp_xprofile_reset_signup_field_cache' );
     328add_action( 'bp_xprofile_removed_signup_field', 'bp_xprofile_reset_signup_field_cache' );
  • src/bp-xprofile/bp-xprofile-cssjs.php

    diff --git src/bp-xprofile/bp-xprofile-cssjs.php src/bp-xprofile/bp-xprofile-cssjs.php
    index 94478187e..a92669499 100644
    function xprofile_add_admin_js() { 
    5757                        'hide_allow_custom_visibility_metabox' => array(),
    5858                        'hide_required_metabox'                => array(),
    5959                        'hide_member_types_metabox'            => array(),
     60                        'hide_signup_position_metabox'         => array(),
    6061                        'text'                                 => array(
    6162                                'defaultValue' => __( 'Default Value', 'buddypress' ),
    6263                                'deleteLabel'  => __( 'Delete', 'buddypress' ),
    6364                        ),
     65                        'signup_info'                          => _x( '(Sign-up)', 'xProfile Group Admin Screen Signup field information', 'buddypress' ),
    6466                );
    6567
    6668                foreach ( bp_xprofile_get_field_types() as $field_type => $field_type_class ) {
  • src/bp-xprofile/bp-xprofile-filters.php

    diff --git src/bp-xprofile/bp-xprofile-filters.php src/bp-xprofile/bp-xprofile-filters.php
    index 7a2fc06be..1f21f1f01 100644
    function bp_xprofile_register_personal_data_exporter( $exporters ) { 
    691691
    692692        return $exporters;
    693693}
     694
     695/**
     696 * Used to edit the field input name inside the xProfile Admin Screen
     697 *
     698 * @see bp_xprofile_admin_get_signup_field()
     699 *
     700 * @since 8.0.0
     701 *
     702 * @param string $field_selector The text to use as the input name/id attribute.
     703 * @return string                The text to use as the input name/id attribute.
     704 */
     705function bp_get_the_profile_signup_field_input_name( $field_selector = '' ) {
     706        global $field;
     707
     708        if ( isset( $field->id ) && $field->id ) {
     709                $field_selector = sprintf( 'signup_field_%d', $field->id );
     710        }
     711
     712        return $field_selector;
     713}
     714
     715/**
     716 * Provides Signup fields argument back compatibility for template overrides.
     717 *
     718 * @since 8.0.0
     719 * @access private
     720 *
     721 * @param array $args The xProfile loop's signup arguments.
     722 * @return array The xProfile loop's signup arguments.
     723 */
     724function _bp_xprofile_signup_do_backcompat( $args = array() ) {
     725        $expected_args = bp_xprofile_signup_args();
     726        $needed_args   = array_intersect_key( $args, $expected_args );
     727
     728        if ( 1 === $args['profile_group_id'] || array_diff_key( $expected_args, $needed_args ) ) {
     729                _doing_it_wrong( 'bp_has_profile()', __( 'The argument of this function into your custom `members/register.php` template should be bp_xprofile_signup_args()', 'buddypress' ), '8.0.0' );
     730                $args = $expected_args;
     731        }
     732
     733        return $args;
     734}
     735
     736/**
     737 * Checks whether back compatibility is needed about xProfile loop's signup arguments.
     738 *
     739 * @since 8.0.0
     740 * @access private
     741 *
     742 * @param string $template      The located path for registration template.
     743 * @param string $template_name The needed template name.
     744 */
     745function _bp_xprofile_signup_check_backcompat( $template = '', $template_name = '' ) {
     746        if ( 'members/register.php' !== $template_name ) {
     747                return;
     748        }
     749
     750        if ( 0 !== strpos( $template, buddypress()->theme_compat->theme->dir ) ) {
     751                add_filter( 'bp_after_has_profile_parse_args', '_bp_xprofile_signup_do_backcompat', 100 );
     752        }
     753}
     754
     755/**
     756 * Starts Signup fields back compatibility process only on the signup's page.
     757 *
     758 * @since 8.0.0
     759 * @access private
     760 */
     761function _bp_xprofile_signup_start_backcompat() {
     762        add_action( 'bp_locate_template', '_bp_xprofile_signup_check_backcompat', 10, 2 );
     763}
     764add_action( 'bp_core_screen_signup', '_bp_xprofile_signup_start_backcompat' );
  • src/bp-xprofile/bp-xprofile-functions.php

    diff --git src/bp-xprofile/bp-xprofile-functions.php src/bp-xprofile/bp-xprofile-functions.php
    index 9764102f4..dfc56013c 100644
    function bp_xprofile_get_wp_user_keys() { 
    14201420                array_keys( wp_get_user_contact_methods() )
    14211421        );
    14221422}
     1423
     1424/**
     1425 * Returns the signup field IDs.
     1426 *
     1427 * @since 8.0.0
     1428 *
     1429 * @return int[] The signup field IDs.
     1430 */
     1431function bp_xprofile_get_signup_field_ids() {
     1432        $signup_field_ids = wp_cache_get( 'signup_fields', 'bp_xprofile' );
     1433
     1434        if ( ! $signup_field_ids ) {
     1435                global $wpdb;
     1436                $bp = buddypress();
     1437
     1438                $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" );
     1439
     1440                wp_cache_set( 'signup_fields', $signup_field_ids, 'bp_xprofile' );
     1441        }
     1442
     1443        return array_map( 'intval', $signup_field_ids );
     1444}
     1445
     1446/**
     1447 * Returns xProfile loop's signup arguments.
     1448 *
     1449 * @since 8.0.0
     1450 *
     1451 * @param array $extra Optional extra arguments.
     1452 * @return array The xProfile loop's signup arguments.
     1453 */
     1454function bp_xprofile_signup_args( $extra = array() ) {
     1455        return array_merge(
     1456                array(
     1457                        'fetch_fields'       => true,
     1458                        'fetch_field_data'   => false,
     1459                        'signup_fields_only' => true,
     1460                ),
     1461                $extra
     1462        );
     1463}
  • src/bp-xprofile/bp-xprofile-template.php

    diff --git src/bp-xprofile/bp-xprofile-template.php src/bp-xprofile/bp-xprofile-template.php
    index 10b5188c9..78fff208c 100644
    defined( 'ABSPATH' ) || exit; 
    1515 *
    1616 * @since 1.0.0
    1717 * @since 2.4.0 Introduced `$member_type` argument.
    18  * @since 8.0.0 Introduced `$hide_field_types` argument.
     18 * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
    1919 *
    2020 * @global object $profile_template
    2121 * @see BP_XProfile_Group::get() for full description of `$args` array.
    defined( 'ABSPATH' ) || exit; 
    3636 *     @type int[]|bool   $exclude_groups         Default: false.
    3737 *     @type int[]|bool   $exclude_fields         Default: false.
    3838 *     @type string[]     $hide_field_types       Default: empty array.
     39 *     @type bool         $signup_fields_only     Default: false.
    3940 *     @type bool         $update_meta_cache      Default: true.
    4041 * }
    4142 *
    function bp_has_profile( $args = '' ) { 
    6869                'exclude_groups'         => false, // Comma-separated list of profile field group IDs to exclude.
    6970                'exclude_fields'         => false, // Comma-separated list of profile field IDs to exclude.
    7071                'hide_field_types'       => array(), // List of field types to hide from profile fields loop.
     72                'signup_fields_only'     => false, // Whether to only return signup fields.
    7173                'update_meta_cache'      => true,
    7274        ), 'has_profile' );
    7375
  • src/bp-xprofile/classes/class-bp-xprofile-data-template.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-data-template.php src/bp-xprofile/classes/class-bp-xprofile-data-template.php
    index 8aa3a4909..ca478f174 100644
    class BP_XProfile_Data_Template { 
    105105         *
    106106         * @since 1.5.0
    107107         * @since 2.4.0 Introduced `$member_type` argument.
    108          * @since 8.0.0 Introduced `$hide_field_types` argument.
     108         * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
    109109         *
    110110         * @param array|string $args {
    111111         *     An array of arguments. All items are optional.
    class BP_XProfile_Data_Template { 
    120120         *     @type array        $exclude_fields          Exclude these fields.
    121121         *     @type int|bool     $hide_empty_fields       Should empty fields be skipped.
    122122         *     @type int|bool     $fetch_visibility_level  Fetch visibility levels.
    123          *     @type int|bool     $update_meta_cache       Should metadata cache be updated.
    124123         *     @type string[]     $hide_field_types        List of field types to hide form loop. Default: empty array.
     124         *     @type bool         $signup_fields_only      Whether to only return signup fields. Default: false.
     125         *     @type int|bool     $update_meta_cache       Should metadata cache be updated.
    125126         * }
    126127         */
    127128        public function __construct( $args = '' ) {
    class BP_XProfile_Data_Template { 
    159160                        'exclude_groups'         => false,
    160161                        'exclude_fields'         => false,
    161162                        'hide_field_types'       => array(),
     163                        'signup_fields_only'     => false,
    162164                        'update_meta_cache'      => true
    163165                ) );
    164166
    165                 $this->groups      = bp_xprofile_get_groups( $r );
     167                $groups = bp_xprofile_get_groups( $r );
     168
     169                if ( true === $r['signup_fields_only'] && bp_get_signup_allowed() ) {
     170                        $signup_fields_order       = bp_xprofile_get_signup_field_ids();
     171                        $signup_group              = new BP_XProfile_Group();
     172                        $signup_group->id          = 0;
     173                        $signup_group->name        = __( 'Signup Fields', 'buddypress' );
     174                        $signup_group->description = '';
     175                        $signup_group->can_delete  = 0;
     176                        $signup_group->group_order = 0;
     177                        $fields                    = array();
     178                        $signup_group->fields      = array();
     179
     180                        // Get all group fields.
     181                        foreach ( $groups as $group ) {
     182                                if ( ! $group->fields ) {
     183                                        continue;
     184                                }
     185
     186                                // Populate fields using the field ID as key.
     187                                foreach ( $group->fields as $signup_field ) {
     188                                        $fields[ $signup_field->id ] = $signup_field;
     189                                }
     190                        }
     191
     192                        if ( $fields ) {
     193                                // Reorder signup fields.
     194                                foreach ( $signup_fields_order as $ordered_signup_field_id ) {
     195                                        if ( ! isset( $fields[ $ordered_signup_field_id ] ) ) {
     196                                                continue;
     197                                        }
     198
     199                                        $signup_group->fields[] = $fields[ $ordered_signup_field_id ];
     200                                }
     201                        }
     202
     203                        // Override groups with the signup one.
     204                        $groups = array( $signup_group );
     205                }
     206
     207                $this->groups      = $groups;
    166208                $this->group_count = count( $this->groups );
    167209                $this->user_id     = $r['user_id'];
    168210        }
  • src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress-textbox.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress-textbox.php src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress-textbox.php
    index 3c5828a73..0a2d17404 100644
    class BP_XProfile_Field_Type_WordPress_Textbox extends BP_XProfile_Field_Type_Wo 
    144144                        $this->wp_user_key = self::get_field_settings( bp_get_the_profile_field_id() );
    145145                }
    146146
     147                $field_value = '';
    147148                if ( 'user_url' === $this->wp_user_key ) {
    148149                        if ( bp_displayed_user_id() ) {
    149150                                $field_value = bp_get_displayed_user()->userdata->{$this->wp_user_key};
  • src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress.php src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress.php
    index 153cae0cc..fc48228b8 100644
    abstract class BP_XProfile_Field_Type_WordPress extends BP_XProfile_Field_Type { 
    5656                'do_autolink'             => false,
    5757                'allow_custom_visibility' => false,
    5858                'member_types'            => false,
     59                'signup_position'         => true,
    5960        );
    6061
    6162        /**
  • src/bp-xprofile/classes/class-bp-xprofile-field.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-field.php src/bp-xprofile/classes/class-bp-xprofile-field.php
    index 55318cfd6..b32b5c928 100644
    class BP_XProfile_Field { 
    139139         */
    140140        public $do_autolink;
    141141
     142        /**
     143         * The signup position of the field into the signups form.
     144         *
     145         * @since 8.0.0
     146         * @var int
     147         */
     148        public $signup_position;
     149
    142150        /**
    143151         * Field type option.
    144152         *
    class BP_XProfile_Field { 
    859867                return $this->allow_custom_visibility;
    860868        }
    861869
     870        /**
     871         * Get the field's signup position.
     872         *
     873         * @since 8.0.0
     874         *
     875         * @return int the field's signup position.
     876         *             0 if the field has not been added to the signup form.
     877         */
     878        public function get_signup_position() {
     879                if ( ! isset( $this->signup_position ) ) {
     880                        $this->signup_position = (int) bp_xprofile_get_meta( $this->id, 'field', 'signup_position' );
     881                }
     882
     883                return $this->signup_position;
     884        }
     885
    862886        /**
    863887         * Get whether the field values should be auto-linked to a directory search.
    864888         *
    class BP_XProfile_Field { 
    12771301                                                        // Output the required metabox.
    12781302                                                        $this->required_metabox();
    12791303
     1304                                                        // Output signup position metabox.
     1305                                                        $this->signup_position_metabox();
     1306
    12801307                                                        // Output the Member Types metabox.
    12811308                                                        $this->member_type_metabox();
    12821309
    class BP_XProfile_Field { 
    13451372        public function get_field_type_supports() {
    13461373                $supports = array(
    13471374                        'switch_fieldtype'        => true,
    1348                         'allow_required'          => true,
    1349                         'allow_autolink'          => true,
     1375                        'required'                => true,
     1376                        'do_autolink'             => true,
    13501377                        'allow_custom_visibility' => true,
    13511378                        'member_types'            => true,
     1379                        'signup_position'         => true,
    13521380                );
    13531381
    13541382                if ( isset( $this->type_obj ) && $this->type_obj ) {
    class BP_XProfile_Field { 
    15021530         * Private method used to output field Member Type metabox.
    15031531         *
    15041532         * @since 2.4.0
     1533         *
     1534         * @return void If default field or if the field does not support the feature.
    15051535         */
    15061536        private function member_type_metabox() {
    15071537
    15081538                // The primary field is for all, so bail.
    1509                 if ( 1 === (int) $this->id || ! $this->field_type_supports( 'member_types' ) ) {
     1539                if ( true === $this->is_default_field() || ! $this->field_type_supports( 'member_types' ) ) {
    15101540                        return;
    15111541                }
    15121542
    class BP_XProfile_Field { 
    15561586         *
    15571587         * @since 2.3.0
    15581588         *
    1559          * @return void If default field id 1.
     1589         * @return void If default field or if the field does not support the feature.
    15601590         */
    15611591        private function visibility_metabox() {
    15621592
    class BP_XProfile_Field { 
    16051635         *
    16061636         * @since 2.3.0
    16071637         *
    1608          * @return void If default field.
     1638         * @return void If default field or if the field does not support the feature.
    16091639         */
    16101640        private function required_metabox() {
    16111641
    class BP_XProfile_Field { 
    16321662         *
    16331663         * @since 2.5.0
    16341664         *
    1635          * @return void If default field id 1.
     1665         * @return void If the field does not support the feature.
    16361666         */
    16371667        private function autolink_metabox() {
    16381668
    class BP_XProfile_Field { 
    17051735        <?php
    17061736        }
    17071737
     1738        /**
     1739         * Output the metabox for setting the field's position into the signup form.
     1740         *
     1741         * @since 8.0.0
     1742         *
     1743         * @return void If default field or if the field does not support the feature.
     1744         */
     1745        private function signup_position_metabox() {
     1746                // Field types not supporting the feature cannot be added to signups form.
     1747                if ( ! $this->field_type_supports( 'signup_position' ) || true === $this->is_default_field() ) {
     1748                        return;
     1749                }
     1750
     1751                $next_signup_position = 1;
     1752                $signup_position      = $this->get_signup_position();
     1753
     1754                if ( 0 === $signup_position ) {
     1755                        $signup_fields_order = bp_xprofile_get_signup_field_ids();
     1756                        $next_signup_position = count( $signup_fields_order ) + 1;
     1757                } else {
     1758                        $next_signup_position = $signup_position;
     1759                }
     1760                ?>
     1761
     1762                <div class="postbox" id="field-signup-position-metabox">
     1763                        <h2><label for="default-visibility"><?php esc_html_e( 'Signups', 'buddypress' ); ?></label></h2>
     1764                        <div class="inside">
     1765                                <div>
     1766                                        <ul>
     1767                                                <li>
     1768                                                        <input type="checkbox" id="has-signup-position" name="signup-position" value="<?php echo esc_attr( $next_signup_position ); ?>" <?php checked( $signup_position, $next_signup_position ); ?> />
     1769                                                        <label for="has-signup-position"><?php esc_html_e( 'Use the field into the registration form.', 'buddypress' ); ?></label>
     1770                                                </li>
     1771                                        </ul>
     1772                                </div>
     1773                        </div>
     1774                </div>
     1775                <?php
     1776        }
     1777
    17081778        /**
    17091779         * Output hidden fields used by default field.
    17101780         *
    class BP_XProfile_Field { 
    17541824                                        'id'    => 'fieldtype',
    17551825                                        'value' => 'textbox',
    17561826                                ),
     1827                                array(
     1828                                        'name'  => 'signup-position',
     1829                                        'id'    => 'has-signup-position',
     1830                                        'value' => $this->get_signup_position(),
     1831                                ),
    17571832                        );
    17581833                }
    17591834
  • src/bp-xprofile/classes/class-bp-xprofile-group.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-group.php src/bp-xprofile/classes/class-bp-xprofile-group.php
    index b6f196838..6b50d35b6 100644
    class BP_XProfile_Group { 
    238238         *
    239239         * @since 1.2.0
    240240         * @since 2.4.0 Introduced `$member_type` argument.
    241          * @since 8.0.0 Introduced `$hide_field_types` argument.
     241         * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
    242242         *
    243243         * @global object $wpdb WordPress DB access object.
    244244         *
    245245         * @param array $args {
    246246         *  Array of optional arguments:
    247          *      @type int          $profile_group_id  Limit results to a single profile group.
    248          *      @type int          $user_id           Required if you want to load a specific user's data.
    249          *                                            Default: displayed user's ID.
    250          *      @type array|string $member_type       Limit fields by those restricted to a given member type, or array of
    251          *                                            member types. If `$user_id` is provided, the value of `$member_type`
    252          *                                            will be overridden by the member types of the provided user. The
    253          *                                            special value of 'any' will return only those fields that are
    254          *                                            unrestricted by member type - i.e., those applicable to any type.
    255          *      @type bool         $hide_empty_groups True to hide groups that don't have any fields. Default: false.
    256          *      @type bool         $hide_empty_fields True to hide fields where the user has not provided data.
    257          *                                            Default: false.
    258          *      @type bool         $fetch_fields      Whether to fetch each group's fields. Default: false.
    259          *      @type bool         $fetch_field_data  Whether to fetch data for each field. Requires a $user_id.
    260          *                                            Default: false.
    261          *      @type int[]|bool   $exclude_groups    Comma-separated list or array of group IDs to exclude.
    262          *      @type int[]|bool   $exclude_fields    Comma-separated list or array of field IDs to exclude.
    263          *      @type string[]     $hide_field_types  List of field types to hide form loop. Default: empty array.
    264          *      @type bool         $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
    265          *                                            and data. Default: true.
     247         *      @type int          $profile_group_id   Limit results to a single profile group.
     248         *      @type int          $user_id            Required if you want to load a specific user's data.
     249         *                                             Default: displayed user's ID.
     250         *      @type array|string $member_type        Limit fields by those restricted to a given member type, or array of
     251         *                                             member types. If `$user_id` is provided, the value of `$member_type`
     252         *                                             will be overridden by the member types of the provided user. The
     253         *                                             special value of 'any' will return only those fields that are
     254         *                                             unrestricted by member type - i.e., those applicable to any type.
     255         *      @type bool         $hide_empty_groups  True to hide groups that don't have any fields. Default: false.
     256         *      @type bool         $hide_empty_fields  True to hide fields where the user has not provided data.
     257         *                                             Default: false.
     258         *      @type bool         $fetch_fields       Whether to fetch each group's fields. Default: false.
     259         *      @type bool         $fetch_field_data   Whether to fetch data for each field. Requires a $user_id.
     260         *                                             Default: false.
     261         *      @type int[]|bool   $exclude_groups     Comma-separated list or array of group IDs to exclude.
     262         *      @type int[]|bool   $exclude_fields     Comma-separated list or array of field IDs to exclude.
     263         *      @type string[]     $hide_field_types   List of field types to hide form loop. Default: empty array.
     264         *      @type bool         $signup_fields_only Whether to only return signup fields. Default: false.
     265         *      @type bool         $update_meta_cache  Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
     266         *                                             and data. Default: true.
    266267         * }
    267268         * @return array $groups
    268269         */
    class BP_XProfile_Group { 
    283284                        'exclude_fields'         => false,
    284285                        'hide_field_types'       => array(),
    285286                        'update_meta_cache'      => true,
     287                        'signup_fields_only'     => false,
    286288                ) );
    287289
    288290                // Keep track of object IDs for cache-priming.
    class BP_XProfile_Group { 
    342344                // Pull field objects from the cache.
    343345                $fields = array();
    344346                foreach ( $field_ids as $field_id ) {
     347                        if ( true === $r['signup_fields_only'] && ! in_array( $field_id, bp_xprofile_get_signup_field_ids(), true ) ) {
     348                                continue;
     349                        }
     350
    345351                        $_field = xprofile_get_field( $field_id, null, false );
    346352
    347353                        if ( in_array( $_field->type, $r['hide_field_types'], true ) ) {