WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#38591 closed enhancement (duplicate)

Filter for languages select on profile-page

Reported by: neoxx Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: Users Keywords:
Focuses: administration Cc:
PR Number:

Description

It would be great to have a filter on the user's profile page to edit the languages select.

This would come in handy - for example to allow only a selection of languages for different blogs in multi-site environments or to suppress the language select at all.

Patch is attached.

Attachments (2)

38591.diff (398 bytes) - added by neoxx 3 years ago.
38591.2.diff (399 bytes) - added by neoxx 3 years ago.

Download all attachments as: .zip

Change History (7)

@neoxx
3 years ago

@neoxx
3 years ago

#1 @neoxx
3 years ago

second version includes all spaces ;)

#2 @swissspidy
3 years ago

  • Focuses ui removed

Hey there,

Thanks for your patch!

It might make more sense to add such a filter to wp_dropdown_languages() in case it's used in other places too.

Also, have a look at the inline documentation standards for hooks: https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/

#3 @neoxx
3 years ago

Hmm, I think with the current implementation of wp_dropdown_languages(), finding out if the select holds any options is only possible by an ugly string comparison.

Therefore a filter in wp_dropdown_languages would not help in case $languages is cleared by said filter to avoid extra markup in user-edit.php. Changing the implementation of wp_dropdown_languages() to something that can be captured with empty() would help, though.

I'm not sure what's the policy on selects, are they supposed to return an empty select <select></select> w/o any option at all or would an empty string be alright? If so, what's recommended - empty string, null or false?

#4 @neoxx
3 years ago

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

filter has been added in #38788

my implementation on the profile/user-edit page:

add_filter('get_available_languages', array($this, 'get_available_languages'));

/*
remove languages select
from profile page
*/

function get_available_languages($languages) {
	if (in_array(
		$GLOBALS['pagenow'],
		array(
			'user-edit.php',
			'profile.php'
		)
	))
		return array();

	return $languages;
}
Last edited 3 years ago by neoxx (previous) (diff)

#5 @netweb
3 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.