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/classes/class-bp-xprofile-field.php

    r12868 r12885  
    139139     */
    140140    public $do_autolink;
     141
     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;
    141149
    142150    /**
     
    861869
    862870    /**
     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
     886    /**
    863887     * Get whether the field values should be auto-linked to a directory search.
    864888     *
     
    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();
     
    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
     
    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        }
     
    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() {
     
    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() {
     
    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() {
     
    17041734
    17051735    <?php
     1736    }
     1737
     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
    17061776    }
    17071777
     
    17551825                    'value' => 'textbox',
    17561826                ),
     1827                array(
     1828                    'name'  => 'signup-position',
     1829                    'id'    => 'has-signup-position',
     1830                    'value' => $this->get_signup_position(),
     1831                ),
    17571832            );
    17581833        }
Note: See TracChangeset for help on using the changeset viewer.