WordPress.org

Make WordPress Core

Ticket #3628: wp_nonces.2.diff

File wp_nonces.2.diff, 1.9 KB (added by BjornW, 11 years ago)
  • functions.php

     
    920920        return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl));
    921921}
    922922
    923 function wp_nonce_field($action = -1) {
    924         echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />';
     923function wp_nonce_field($action = -1, $return = FALSE) {
     924        $nonce = '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />';
     925   
     926    if($return) {
     927        return $nonce;
     928    } else {
     929        echo $nonce;
     930    }
    925931        wp_referer_field();
    926932}
    927933
    928 function wp_referer_field() {
     934function wp_referer_field($return = FALSE) {
    929935        $ref = attribute_escape($_SERVER['REQUEST_URI']);
    930         echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
     936        $ret_val = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
    931937        if ( wp_get_original_referer() ) {
    932938                $original_ref = attribute_escape(stripslashes(wp_get_original_referer()));
    933                 echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
     939                $ret_val .= '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
    934940        }
     941    if($return) {
     942        return $ret_val;
     943    } else {
     944        echo $ret_val;
     945    }
     946   
    935947}
    936948
    937 function wp_original_referer_field() {
    938         echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
     949function wp_original_referer_field($return = FALSE) {
     950    $ret_val = '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
     951    if($return) {
     952        return $ret_val;
     953    } else {
     954        echo $ret_val;
     955    }
    939956}
    940957
    941958function wp_get_referer() {