Ticket #3628 (closed enhancement: fixed)

Opened 2 years ago

Last modified 8 months ago

Make wp_nonce_field, wp_referrer_field and wp_original_referer_field be able to return output

Reported by: BjornW Assigned to: robmil
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?

  1. consistency
  2. 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

wp_nonces.diff (8.6 kB) - added by BjornW on 01/21/07 15:02:28.
wp_nonces.2.diff (1.9 kB) - added by BjornW on 01/21/07 15:03:02.
3628.diff (1.5 kB) - added by robmil on 06/26/07 12:43:24.
This is probably a little more in keeping with the rest of our idiosyncrasies, plus the same treatment for wp_referer_field

Change History

01/21/07 15:02:28 changed by BjornW

  • attachment wp_nonces.diff added.

01/21/07 15:03:02 changed by BjornW

  • attachment wp_nonces.2.diff added.

01/21/07 15:04:57 changed by BjornW

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

01/21/07 15:25:28 changed by Viper007Bond

  • 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 deleted.

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.

(follow-up: ↓ 5 ) 01/21/07 18:11:08 changed by BjornW

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 :)

03/27/07 19:36:13 changed by foolswisdom

  • milestone changed from 2.2 to 2.3.

(in reply to: ↑ 3 ) 03/27/07 19:37:43 changed by foolswisdom

Replying to BjornW:

Could you please tell me what I need to change in my coding style to better match with the preferred style?

http://codex.wordpress.org/WordPress_Coding_Standards ?

06/26/07 12:43:24 changed by robmil

  • 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

06/26/07 12:44:34 changed by robmil

  • keywords set to bg|has-patch.
  • owner changed from anonymous to robmil.
  • version changed from 2.0.7 to 2.3.
  • status changed from new to assigned.

09/13/07 21:21:50 changed by ryan

  • milestone changed from 2.3 to 2.4.

03/15/08 22:44:34 changed by westi

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7323]) Allow for wp_nonce_field, wp_referrer_field and wp_original_referer_field be able to return output. Fixes #3628 props robmil.