WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#10240 closed enhancement (fixed)

Contact Info needs to be filterable

Reported by: joostdevalk Owned by: joostdevalk
Milestone: 2.9 Priority: normal
Severity: normal Version:
Component: Users Keywords: has-patch tested
Focuses: Cc:

Description

Right now the Contact Info is a "fixed" set of values: Email, Website, AIM, Yahoo IM, Jabber / Google Talk. With the advent of the the_author_meta functions, the way has been cleared for this entire thing to be filterable, so people can add and remove their own contact options from within a plugin.

This would require, if I'm correct, for the Contact Info to be a loop through an array of contact options, and that array has to be filtered, with the exception of the E-mail address, which should always be available.

Thoughts and remarks are very welcome :)

Attachments (1)

contactmethods.patch (4.1 KB) - added by joostdevalk 5 years ago.
Patch

Download all attachments as: .zip

Change History (21)

comment:1 Denis-de-Bernardy5 years ago

  • Component changed from General to Users
  • Keywords needs-patch added; dev-feedback 2nd-opinion removed

I like this idea.

comment:2 joostdevalk5 years ago

  • Keywords has-patch added; needs-patch removed

I've added a first patch, it's a bit rough on the edges, as I was especially unsure where to store the "default" variables, as they have to be available both in the admin and the frontend...

comment:3 joostdevalk5 years ago

  • Keywords needs-testing added

comment:4 joostdevalk5 years ago

Changed the way the patch works, now simply adding a private function to wp-admin/includes/user.php that is called in the few spots where the contactmethods are needed.

comment:5 follow-up: joostdevalk5 years ago

Sample implementation:

function add_twitter_contactmethod( $contactmethods ) {
	// Add Twitter
	$contactmethods['twitter'] = 'Twitter';
	
	// Remove Yahoo IM
	unset($contactmethods['yim'])
	
	return $contactmethods;
}
add_filter('user_contactmethods','add_twitter_contactmethod',10,1);

joostdevalk5 years ago

Patch

comment:6 in reply to: ↑ 5 joostdevalk5 years ago

Don't forget the closing semi colon after the unset of course:

Sample implementation:

function add_twitter_contactmethod( $contactmethods ) {
  // Add Twitter
  $contactmethods['twitter'] = 'Twitter';
	
  // Remove Yahoo IM
  unset($contactmethods['yim']);
 	
  return $contactmethods;
}
add_filter('user_contactmethods','add_twitter_contactmethod',10,1);

comment:7 follow-up: markjaquith5 years ago

I worked with Joost a bit on this patch. I'm +1 on it.

comment:8 in reply to: ↑ 7 joostdevalk5 years ago

Replying to markjaquith:

I worked with Joost a bit on this patch. I'm +1 on it.

For which I'm grateful, btw :)

comment:9 demetris5 years ago

I quickly tested the patch against trunk and 2.8-branch, and everything seems to work OK, both in removing and in adding contact methods.

comment:10 Denis-de-Bernardy5 years ago

  • Keywords tested added; needs-testing removed

comment:11 Viper007Bond5 years ago

Looks cool to me. :)

comment:12 aaroncampbell5 years ago

  • Cc aaroncampbell added

I tested it on trunk (Revision 11754) and was able to add, remove, and override options just fine. Works great.

comment:13 westi5 years ago

Excellent.

This is something I expected to be there when writing this:

http://blog.ftwr.co.uk/archives/2009/07/19/adding-extra-user-meta-fields/

Was disappointed to find it wasn't.

This patch makes that plugin into just a filter which is what I hoped I needed at the time.

comment:14 westi5 years ago

Cool.

Only found one little buglet to do with not setting default values on the WP_User object when loaded for the new contact types which I've fixed in the commit.

This meant you got a notice in the value field for your new contact info item.

comment:15 westi5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11784]) Make it much easier to filter contact methods from user profiles adding and removing at will. Fixes #10240 props joostdevalk.

comment:16 follow-up: ryan5 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

The registration.php changes seem to be sporadically stomping usermeta values.

comment:17 in reply to: ↑ 16 westi5 years ago

Replying to ryan:

The registration.php changes seem to be sporadically stomping usermeta values.

Hmm - any clue on what is triggering that?

comment:18 ryan5 years ago

Actually, the api_key field that is added to the users table (not usermeta) on wordpress.com was getting stomped. I haven't conclusively tied it to this changeset, but the problem started moments after I merged this changeset and seem to have stomped since reversion.

comment:19 ryan5 years ago

Maybe since api_key is not a standard users table field, it is getting tossed out somehow.

comment:20 ryan5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Anyhow, since this is looking .com specific, I'll close this again until I can pin it down.

Note: See TracTickets for help on using tickets.