Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#28180 closed enhancement (fixed)

No get equivalent for language_attributes()

Reported by: peterrknight's profile PeterRKnight Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.3 Priority: normal
Severity: normal Version: 2.1
Component: Themes Keywords: has-patch
Focuses: template Cc:


In core most functions that can output a string call a function that returns a string instead of returning it. The language_attributes() function is an exception to this and always echoes a string. I was expecting there to be an equivalent get_language_attributes() function that returns a string instead.

I ran into this need while coding conditional IE fallback code for the opening HTML tag. Rather than call language_attributes() multiple times, I wanted to store the attributes in a string. The current workaround is either using output buffering or simply calling language_attributes() multiple times, both of which are undesirable because it adds unnecessary operations. It also imposes a limitation in how a developer may choose to output html.

I propose adding get_language_attributes() for consistency and flexibility purposes.

Attachments (3)

get-language-attributes.php (1.3 KB) - added by PeterRKnight 10 years ago.
patch adding get_language_attributes() and modifying language_attributes()
language_attributes.28180.diff (2.7 KB) - added by posykrat 9 years ago.
28180.diff (1.7 KB) - added by johnbillion 9 years ago.

Download all attachments as: .zip

Change History (9)

10 years ago

patch adding get_language_attributes() and modifying language_attributes()

#1 @obenland
10 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 3.9 to 2.1

Not sure if I18n would be a more accurate component for this.

#2 @posykrat
9 years ago

  • Keywords has-patch needs-testing 2nd-opinion added; needs-patch removed

#3 @posykrat
9 years ago

Patch inspired from @PeterRKnight PHP file

  • created get_language_attributes function with original language_attributes function code without echo
  • language_attributes function call now get_language_attributes and echo result

9 years ago

#4 @johnbillion
9 years ago

  • Keywords needs-testing 2nd-opinion removed
  • Milestone changed from Future Release to 4.3

This makes sense. Let's do it.

28180.diff corrects the language_attributes.28180.diff patch, improves the docs, and also adds $doctype as a parameter to the language_attributes filter.

#5 @wonderboymusic
9 years ago

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

In 32868:

Add get_language_attributes(), which is then used by (...drum roll...) language_attributes().

Props johnbillion, posykrat, PeterRKnight.
Fixes #28180.

#6 @DrewAPicture
9 years ago

In 32882:

Add a changelog entry to the DocBlock for language_attributes() noting that it was converted into a wrapper for get_language_attributes() in 4.3.

See [32868]. See #28180.

Note: See TracTickets for help on using tickets.