Ticket #3628 (closed enhancement: fixed)
Make wp_nonce_field, wp_referrer_field and wp_original_referer_field be able to return output
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.5 |
| Component: | General | Version: | 2.3 |
| Severity: | minor | Keywords: | bg|has-patch |
| Cc: |
Description
The wp_nonce_field, wp_referrer_field and wp_original_referer_field functions should return values instead of using echo. This would be more consistent with for instance wp_nonce_url which does return value. My proposal is easy to implement because the default behaviour is still using echo. If you want to get the value returned one can add the $return = TRUE parameter and the value will be returned instead of echo'ed.
Why is this useful?
- consistency
- useful for building forms using vars instead of mingling PHP and HTML e.g:
function formbuilder($formdata = NULL) {
if ( function_exists('wp_nonce_field') ) {
$nonce_field = wp_nonce_field('faces-update-face_upload', $return = TRUE);
}
$form = '<form>';
$form .= $nonce_field;
$form .= '<input type="text" />';
$form .= '</form>'
return $form
}
Basically it enhances the way these functions can be used and therefor also expands the possible ways of using the code, while maintaining the old behavior. Somewhere in the future the echo functionality could be deprecated and functions would be consistent in returning values instead of echo'ing.
Attachments
Change History
Please ignore the first attached diff. It contains too much info which is not relevant for this ticket. Sorry, I'm kinda new to Trac and didn't know how to remove the false one. All the info you need is in wp_nonces.2.diff
comment:2
Viper007Bond — 5 years ago
- Severity changed from normal to minor
- Component changed from Optimization to General
- Summary changed from Proposal: wp_nonce_field, wp_referrer_field and wp_original_referer_field should return value to Make wp_nonce_field, wp_referrer_field and wp_original_referer_field be able to return output
- Version set to 2.0.7
- Milestone changed from 2.1 to 2.2
- Keywords proposal, wp_nonce_field, wp_referrer_field, wp_original_referer_field removed
Patch needs some cleaning up to better match our coding standards as well as making use of some of our custom functions (I believe we have a echo vs. return function), but as to the actual idea itself, I like it. Very useful for those times when you are generating output or whatnot and don't want to echo at that moment.
Viper007Bond,
Could you please tell me what I need to change in my coding style to better match with the preferred style? If you do find the custom function let me know where I can find it so I can change this as well.
Good to hear my proposal is useful :)
comment:5
in reply to:
↑ 3
foolswisdom — 5 years ago
Replying to BjornW:
Could you please tell me what I need to change in my coding style to better match with the preferred style?
-
attachment
3628.diff
added
This is probably a little more in keeping with the rest of our idiosyncrasies, plus the same treatment for wp_referer_field
- Keywords bg|has-patch added
- Owner changed from anonymous to robmil
- Version changed from 2.0.7 to 2.3
- Status changed from new to assigned
