Make WordPress Core

Opened 4 years ago

Closed 2 years ago

Last modified 12 months ago

#20357 closed enhancement (fixed)

Add Return Empty String Function

Reported by: wpsmith Owned by: nacin
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.6
Component: General Keywords: has-patch
Focuses: Cc:


There's an easy way to return boolean, integer (0), and an empty array. But what about an empty string?

 * Returns an empty string.
 * Useful for returning an empty string to filters easily.
 * @since 3.0.0
 * @see __return_empty_string()
 * @return string Empty string
function __return_empty_string() {
	return '';

Attachments (2)

20357.diff (663 bytes) - added by trepmal 3 years ago.
20357.2.diff (655 bytes) - added by trepmal 2 years ago.
with @DrewAPicture's suggestions

Download all attachments as: .zip

Change History (13)

comment:1 @nacin4 years ago

There is also one for null, which could be used in nearly all places __return_empty_string() might be used. Where might one use it, though? I closed #20358.

comment:2 follow-up: @wpsmith4 years ago

I probably missed it but where is the return null function? I see return_false but don't see return_null. If I am not mistaken those are two different ideas/purposes. Likewise, if one wishes to be consistent with types, it would be beneficial to have return_empty_string.

Version 0, edited 4 years ago by wpsmith (next)

comment:3 @nacin4 years ago

__return_null is new in 3.4, I think.

comment:4 in reply to: ↑ 2 @SergeyBiryukov4 years ago

Replying to wpsmith:

I probably missed it but where is the return null function?

It was added in #18845.

@trepmal3 years ago

comment:5 @trepmal3 years ago

  • Keywords has-patch added

Added a patch since this ticket wasn't closed, just in case...

Using __return_null when I really want an empty string seems hackish.

There are at least 3 plugins in the repo doing their own version of __return_empty_string but 1 returns the parameter passed to it, and another actually echoes an empty string. Not sure if only 3 attempts is an indication that there's not a big enough need, or if that 2 of 3 attempts doing it wrong indicates there should be a core function to save them.

comment:6 @jtsternberg3 years ago

  • Cc justin@… added

Agreed. Seems hackish. Any word from the powers that be?

comment:7 @helen2 years ago

#24996 was marked as a duplicate.

comment:8 @DrewAPicture2 years ago

  • Milestone changed from Awaiting Review to 3.7
  • Version set to 3.6

+1. Moving to 3.7 for review.

@trepmal: Maybe change the @see tag to __return_null() and update @since to 3.7.0

@trepmal2 years ago

with @DrewAPicture's suggestions

comment:9 @nacin2 years ago

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

In 25037:

Add a function to return an empty string, for filters. props wpsmith, trepmal. fixes #20357.

comment:10 @ircbot12 months ago

This ticket was mentioned in IRC in #wordpress-themes by pixolin. View the logs.

comment:11 @ircbot12 months ago

This ticket was mentioned in IRC in #wordpress-themes by pixolin. View the logs.

Note: See TracTickets for help on using tickets.