Skip to:
Content

BuddyPress.org

Opened 9 years ago

Closed 6 years ago

#6132 closed enhancement (maybelater)

Custom xprofile field: email

Reported by: sooskriszta's profile sooskriszta Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Extended Profile Keywords: trac-tidy-2018
Cc: brajesh@…, vivek@…

Description

email would be a useful field. General email validation rules apply: handle@…

Often the email you register with on the site may not be the email that you want to share with others. This field should be useful there. Also, BuddyPress at the moment does not have a way to show even the email registered with in the profile.

Would need to convert to mailto links (as opposed to search links like text fields) when displaying in profile.

Change History (8)

#1 @sbrajesh
9 years ago

Sounds good.
here is an implementation

<?php

/**
 * Email xprofile field type.
 *
 * @since BuddyPress (2.2.0)
 */
class BP_XProfile_Field_Type_Email extends BP_XProfile_Field_Type {

	/**
	 * Constructor for the Email field type
	 *
	 * @since BuddyPress (2.2.0)
	 */
	public function __construct() {
		
		parent::__construct();

		$this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' );
		$this->name     = _x( 'Email', 'xprofile field type', 'buddypress' );

	
		do_action( 'bp_xprofile_field_type_email', $this );
	}

	public function is_valid( $val ){
		
		return is_email( $val );
	}
	/**
	 * Output the edit field HTML for this field type.
	 *
	 * Must be used inside the {@link bp_profile_fields()} template loop.
	 *
	 * @param array $raw_properties Optional key/value array of
	 *        {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes}
	 *        that you want to add.
	 * @since BuddyPress (2.1.0)
	 */
	public function edit_field_html( array $raw_properties = array() ) {

		// `user_id` is a special optional parameter that certain other
		// fields types pass to {@link bp_the_profile_field_options()}.
		if ( isset( $raw_properties['user_id'] ) ) {
			unset( $raw_properties['user_id'] );
		}
		//bp_xprofile_extended_helper()->set_shown( bp_get_the_profile_field_id() );
		
		$r = bp_parse_args( $raw_properties, array(
			'type'      => 'email',
			//'inputmode' => 'email',
			'value'     => esc_attr( bp_get_the_profile_field_edit_value() ),
		) ); ?>

		<label for="<?php bp_the_profile_field_input_name(); ?>">
			<?php bp_the_profile_field_name(); ?>
			<?php if ( bp_get_the_profile_field_is_required() ) : ?>
				<?php esc_html_e( '(required)', 'buddypress' ); ?>
			<?php endif; ?>
		</label>

		<?php do_action( bp_get_the_profile_field_errors_action() ); ?>

		<input <?php echo $this->get_edit_field_html_elements( $r ); ?>>

		<?php
	}

	/**
	 * Output HTML for this field type on the wp-admin Profile Fields screen.
	 *
	 * Must be used inside the {@link bp_profile_fields()} template loop.
	 *
	 * @param array $raw_properties Optional key/value array of permitted
	 *        attributes that you want to add.
	 * @since BuddyPress (2.1.0)
	 */
	public function admin_field_html( array $raw_properties = array() ) {

		$r = bp_parse_args( $raw_properties, array(
			'type' => 'email'
		) ); ?>

		<input <?php echo $this->get_edit_field_html_elements( $r ); ?>>

		<?php
	}

	/**
	 * This method usually outputs HTML for this field type's children options
	 * on the wp-admin Profile Fields "Add Field" and "Edit Field" screens, but
	 * for this field type, we don't want it, so it's stubbed out.
	 *
	 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
	 * @param string $control_type Optional. HTML input type used to render the current field's child options.
	 * @since BuddyPress (2.2.0)
	 */
	public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}

	

	/**
	 * Format URL values for display.
	 *
	 * @since BuddyPress (2.1.0)
	 *
	 * @param string $field_value The URL value, as saved in the database.
	 * @return string URL converted to a link.
	 */
	public static function display_filter( $field_value ) {
		$link      = strip_tags( $field_value );
		
		//$url_text  = str_replace( $link, $no_scheme, $field_value );
		return '<a href="mailto:' . esc_attr( $field_value ) . '" rel="nofollow">' . esc_html( $field_value ) . '</a>';
	}
}

All it needs to be done is hook into the 'bp_xprofile_get_field_types' and add the email field using the above class.

#2 @sbrajesh
9 years ago

  • Cc brajesh@… added

#3 follow-up: @DJPaul
9 years ago

  • Component changed from Core to XProfile
  • Milestone changed from Awaiting Review to Future Release

Since there's a kind-of patch here, I'm going to move into the Future Release milestone while this idea is (hopefully) developed further into a real patch and discussed.

I am concerned about confusion between a new "email" field type, and the user's email field on the registration/edit profile screens. I think we'd need to imagine how that might all work together.

#4 in reply to: ↑ 3 @sooskriszta
9 years ago

Replying to DJPaul:

I am concerned about confusion between a new "email" field type, and the user's email field on the registration/edit profile screens. I think we'd need to imagine how that might all work together.

So far, the WordPress account email is not shown in frontend profiles.

#5 @sooskriszta
9 years ago

  • Cc vivek@… added

#6 @sooskriszta
9 years ago

@sbrajesh Thanks for sharing. Could you please submit this as a patch? @DJPaul may be more willing to review it then :-)

  1. Replicate https://buddypress.svn.wordpress.org/trunk/ on your hard drive, say at buddypresstrunk/ using SVN Checkout
  2. Make the changes.
  3. "Create Patch" using Tortoise SVN or the like
  4. Upload the .patch file here.

#7 @DJPaul
6 years ago

  • Keywords trac-tidy-2018 added

We're closing this ticket because it has not received any contribution or comments for at least two years. We have decided that it is better to close tickets that are good ideas, which have not gotten (or are unlikely to get) contributions, rather than keep things open indefinitely. This will help us share a more realistic roadmap for BuddyPress with you.

Everyone very much appreciates the time and effort that you spent sharing your idea with us. On behalf of the entire BuddyPress team, thank you.

If you feel strongly that this enhancement should still be added to BuddyPress, and you are able to contribute effort towards it, we encourage you to re-open the ticket, or start a discussion about it in our Slack channel. Please consider that time has proven that good ideas without contributions do not get built.

For more information, see https://bpdevel.wordpress.com/2018/01/21/our-awaiting-contributions-milestone-contains/
or find us on Slack, in the #buddypress channel: https://make.wordpress.org/chat/

#8 @DJPaul
6 years ago

  • Milestone Awaiting Contributions deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.