Opened 6 years ago
Closed 5 years ago
#3450 closed enhancement (wontfix)
wp_return() function for echo/return logic
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | Administration | Version: | 2.1 |
| Severity: | minor | Keywords: | needs-patch 2nd-opinion |
| 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)
Change History (12)
markjaquith — 6 years ago
comment:1
Viper007Bond — 6 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
comment:2
in reply to:
↑ description
xmarcos — 6 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;
}
comment:4
foolswisdom — 6 years ago
- Milestone changed from 2.2 to 2.3
function wp_return( $what, $echo = true ) {
if ( $echo ) {
echo $what;
} else {
return $what;
}
}
- Keywords needs-patch added; has-patch removed
- Milestone changed from 2.3 (trunk) to 2.4 (future)
- 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.
comment:8
Viper007Bond — 5 years ago
Better code (I think this works):
function wp_return( $what, $echo = true ) {
( $echo ) ? echo $what : return $what;
}
comment:9
darkdragon — 5 years ago
Is this worth implementing? If not then just close as won't fix.
comment:10
pishmishy — 5 years ago
- Milestone 2.6 deleted
- Resolution set to wontfix
- Status changed from new to closed

Patch for trunk