Skip to:
Content

BuddyPress.org

Changeset 8337


Ignore:
Timestamp:
05/01/2014 10:38:35 PM (11 years ago)
Author:
djpaul
Message:

xProfile: prevent duplicate profile field templating when using pre-2.0 custom field types.

Prior to the xProfile field type overhaul in 2.0, plugins that added custom field types had to do so with a variety of actions.
One such plugin is "Buddypress Xprofile Custom Fields Type" and the changes in 2.0 caused an issue where the plugin's custom
templating was being rendered, alongside BuddyPress' profile field fallback type, the textbox.

BuddyPress uses a fallback field type to handle situations when extra profile types/data are provided by another plugin, and
then that plugin is removed. The original idea was that everything would fallback to rendering a textbox if a field type was
unregistered to give at least some kind of access to that profile field's data, but in practice this has caused a couple of
issues with templating, as this commit addresses.

This change essentially reverts the fallback behaviour to the pre-2.0 implementation: if a custom field type is unknown to
BuddyPress, that field simply won't be rendered.

Fixes #5589 for the 2.0 branch

Location:
branches/2.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/bp-xprofile/bp-xprofile-classes.php

    r8178 r8337  
    24982498
    24992499/**
     2500 * A placeholder xprofile field type. Doesn't do anything.
     2501 *
     2502 * Used if an existing field has an unknown type (e.g. one provided by a missing third-party plugin).
     2503 *
     2504 * @since BuddyPress (2.0.1)
     2505 */
     2506class BP_XProfile_Field_Type_Placeholder extends BP_XProfile_Field_Type {
     2507
     2508    /**
     2509     * Constructor for the placeholder field type.
     2510     *
     2511     * @since BuddyPress (2.0.1)
     2512     */
     2513    public function __construct() {
     2514    }
     2515
     2516    /**
     2517     * Prevent any HTML being output for this field type.
     2518     *
     2519     * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes} that you want to add.
     2520     * @since BuddyPress (2.0.1)
     2521     */
     2522    public function edit_field_html( array $raw_properties = array() ) {
     2523    }
     2524
     2525    /**
     2526     * Prevent any HTML being output for this field type.
     2527     *
     2528     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
     2529     * @since BuddyPress (2.0.1)
     2530     */
     2531    public function admin_field_html( array $raw_properties = array() ) {
     2532    }
     2533
     2534    /**
     2535     * Prevent any HTML being output for this field type.
     2536     *
     2537     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
     2538     * @param string $control_type Optional. HTML input type used to render the current field's child options.
     2539     * @since BuddyPress (2.0.1)
     2540     */
     2541    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     2542}
     2543
     2544/**
    25002545 * Represents a type of XProfile field and holds meta information about the type of value that it accepts.
    25012546 *
  • branches/2.0/bp-xprofile/bp-xprofile-functions.php

    r8178 r8337  
    9696
    9797    /**
    98      * For backpat and to handle (missing) field types introduced by other plugins, fallback to
    99      * textbox if a type is unknown. Textbox validation and display is intentionally low key.
     98     * To handle (missing) field types, fallback to a placeholder field object if a type is unknown.
    10099     */
    101100    if ( $class && class_exists( $class ) ) {
    102101        return new $class;
    103102    } else {
    104         return new BP_XProfile_Field_Type_Textbox;
     103        return new BP_XProfile_Field_Type_Placeholder;
    105104    }
    106105}
  • branches/2.0/tests/testcases/xprofile/class-bp-xprofile-field-type.php

    r8178 r8337  
    1515    public function test_unregistered_field_type_returns_textbox() {
    1616        $field = bp_xprofile_create_field_type( 'fakeyfield' );
    17         $this->assertEquals( get_class( $field ), 'BP_XProfile_Field_Type_Textbox' );
     17        $this->assertEquals( get_class( $field ), 'BP_XProfile_Field_Type_Placeholder' );
    1818    }
    1919
Note: See TracChangeset for help on using the changeset viewer.