WordPress.org

Make WordPress Core

Ticket #3628: 3628.diff

File 3628.diff, 1.5 KB (added by robmil, 7 years ago)

This is probably a little more in keeping with the rest of our idiosyncrasies, plus the same treatment for wp_referer_field

  • functions.php

     
    823823        return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl)); 
    824824} 
    825825 
    826 function wp_nonce_field($action = -1, $name = "_wpnonce", $referer = true) { 
     826function wp_nonce_field($action = -1, $name = "_wpnonce", $referer = true, $echo = true) { 
    827827        $name = attribute_escape($name); 
    828         echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce($action) . '" />'; 
     828        $nonce_field = '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce($action) . '" />'; 
     829        if ( $echo ) 
     830                echo $nonce_field; 
     831         
    829832        if ( $referer ) 
    830                 wp_referer_field(); 
     833                wp_referer_field($echo); 
     834         
     835        return $nonce_field; 
    831836} 
    832837 
    833 function wp_referer_field() { 
     838function wp_referer_field( $echo = true ) { 
    834839        $ref = attribute_escape($_SERVER['REQUEST_URI']); 
    835         echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; 
     840        $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; 
    836841        if ( wp_get_original_referer() ) { 
    837842                $original_ref = attribute_escape(stripslashes(wp_get_original_referer())); 
    838                 echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />'; 
     843                $referer_field .= '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />'; 
    839844        } 
     845         
     846        if ( $echo ) 
     847                echo $referer_field; 
     848        return $referer_field; 
    840849} 
    841850 
    842851function wp_original_referer_field() {