Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/27/2014 07:34:02 PM (10 years ago)
Author:
djpaul
Message:

xProfile: re-architecture profile field types and de-duplicate the templating and validation logic to make it easier for core and plugins to add new profile field types.

Until now, it's been pretty hard to add new types of profile field to BuddyPress. There are a couple of plugins that do a good job, but BuddyPress makes it much harder than it should be because, historically, we've hardcoded values and checks in templates throughout the project. For example, profile field templating was duplicated in the registration template, the member/profile/edit template, in parts of the wp-admin xProfile screens, and in the new wp-admin extended profile editor.

This change implements a new approach that creates a class for each profile field type; selectbox, textbox, textarea, and so on. They all share an abstract base class BP_XProfile_Field_Type which consolidates a lot of special behaviour that had been added to BuddyPress over the years (e.g. some fields accept null values, some accept multiple default values), and adds true field value validation. Unit tests are included.

We've also implemented a new "Numbers" field type with these changes. It behaves much the same as a regular textbox field does, but it only accepts numbers.

Fixes #5220 and #4694

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/xprofile/functions.php

    r8133 r8178  
    553553        $this->assertSame( 'foo', $found );
    554554    }
     555
     556    /**
     557     * @group xprofile_set_field_data
     558     */
     559    public function test_get_field_data_integer_zero() {
     560        $u = $this->create_user();
     561        $g = $this->factory->xprofile_group->create();
     562        $f = $this->factory->xprofile_field->create( array(
     563            'field_group_id' => $g,
     564            'type' => 'number',
     565            'name' => 'Pens',
     566        ) );
     567        xprofile_set_field_data( $f, $u, 0 );
     568
     569        $this->assertEquals( 0, xprofile_get_field_data( 'Pens', $u ) );
     570    }
    555571}
Note: See TracChangeset for help on using the changeset viewer.