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.