Make WordPress Core

Opened 15 years ago

Closed 14 years ago

#3450 closed enhancement (wontfix)

wp_return() function for echo/return logic

Reported by: markjaquith's profile markjaquith Owned by:
Milestone: Priority: low
Severity: minor Version: 2.1
Component: Administration Keywords: needs-patch 2nd-opinion
Focuses: Cc:

Description

Elegant echo/return logic wrapper by Andy Skelton

Look at all the red in the patch!

// Implementation within function:  return wp_return($func_data, $echo_flag);
function wp_return($data, $echo = true) {
	echo ( $echo ) ? $data : '';
	return $data;
}

Attachments (2)

wp_return.diff (3.9 KB) - added by markjaquith 15 years ago.
Patch for trunk
wp_return2.diff (3.9 KB) - added by Viper007Bond 15 years ago.
Was missing a tab

Download all attachments as: .zip

Change History (12)

@markjaquith
15 years ago

Patch for trunk

#1 @Viper007Bond
15 years ago

Just though I'd point out that this isn't the same as the code as the code it replaces (this new function always returns something, even if it echo's it first).

Not saying this is bad (I personally think it's good as you can see what a function echo'ed), just pointing out the difference.

+1

@Viper007Bond
15 years ago

Was missing a tab

#2 in reply to: ↑ description @xmarcos
15 years ago

Replying to markjaquith:

Elegant echo/return logic wrapper by Andy Skelton

Look at all the red in the patch!

// Implementation within function:  return wp_return($func_data, $echo_flag);
function wp_return($data, $echo = true) {
	echo ( $echo ) ? $data : '';
	return $data;
}

As Viper007Bond says, this is wrong, it will always produce and echo and then return the same value.

The function should be as follows,

function wp_return($data, $echo = true) {
	if ($echo) :
		echo $data;
	else :
		return $data;
	endif;
}

#3 @matt
15 years ago

  • Milestone changed from 2.1 to 2.2

#4 @foolswisdom
15 years ago

  • Milestone changed from 2.2 to 2.3

#5 @rob1n
15 years ago

function wp_return( $what, $echo = true ) {
	if ( $echo ) {
		echo $what;
	} else {
		return $what;
	}
}

#6 @Nazgul
15 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from 2.3 (trunk) to 2.4 (future)

#7 @DD32
14 years ago

  • Milestone changed from 2.4 to 2.5

While i think this is a good idea, There doesnt seem much traction on implementing this, I'm going to set it to 2.5 for now, Feel free to move back to 2.4 if someone wants to do it.

#8 @Viper007Bond
14 years ago

Better code (I think this works):

function wp_return( $what, $echo = true ) {
	( $echo ) ? echo $what : return $what;
}

#9 @darkdragon
14 years ago

Is this worth implementing? If not then just close as won't fix.

#10 @pishmishy
14 years ago

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