Skip to:
Content

BuddyPress.org

Changeset 12887


Ignore:
Timestamp:
04/16/2021 05:37:03 AM (5 months ago)
Author:
imath
Message:

Update both Template Pack registration forms to use signup fields

  • Nouveau and Legacy are now usinf the bp_xprofile_signup_args() to build the argument of their registration's form xProfile loop.
  • Include a backward compatibility mechanism if the register.php page has been overriden from a theme or a plugin.
  • This commit also includes PHP Unit tests about the xProfile loop and Signup Fields.

Props johnjamesjacoby, boonebgorges, DJPaul, Offereins

Fixes #6347

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/buddypress/members/register.php

    r12595 r12887  
    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(); ?>
  • trunk/src/bp-templates/bp-nouveau/buddypress/members/register.php

    r12260 r12887  
    44 *
    55 * @since 3.0.0
    6  * @version 4.0.0
     6 * @version 8.0.0
    77 */
    88
     
    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' ); ?>
  • trunk/src/bp-templates/bp-nouveau/includes/template-tags.php

    r12836 r12887  
    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        }
  • trunk/src/bp-templates/bp-nouveau/includes/xprofile/template-tags.php

    r12082 r12887  
    44 *
    55 * @since 3.0.0
    6  * @version 3.0.0
     6 * @version 8.0.0
    77 */
    88
     
    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();
    7370}
     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    if ( ! $do_loop ) {
     82        $signup_fields = (array) bp_xprofile_get_signup_field_ids();
     83        return 1 <= count( $signup_fields );
     84    }
     85
     86    return bp_has_profile( bp_xprofile_signup_args() );
     87}
  • trunk/src/bp-xprofile/bp-xprofile-filters.php

    r12869 r12887  
    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    $signup_fields = (array) bp_xprofile_get_signup_field_ids();
     763    if ( ! $signup_fields ) {
     764        return;
     765    }
     766
     767    add_action( 'bp_locate_template', '_bp_xprofile_signup_check_backcompat', 10, 2 );
     768}
     769add_action( 'bp_core_screen_signup', '_bp_xprofile_signup_start_backcompat' );
Note: See TracChangeset for help on using the changeset viewer.