Changeset 3771 for branches/2.0/wp-includes/pluggable-functions.php
- Timestamp:
- 05/11/2006 11:05:45 PM (20 years ago)
- File:
-
- 1 edited
-
branches/2.0/wp-includes/pluggable-functions.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/wp-includes/pluggable-functions.php
r3739 r3771 6 6 if ( !function_exists('set_current_user') ) : 7 7 function set_current_user($id, $name = '') { 8 global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity, $current_user; 9 10 $current_user = ''; 11 12 $current_user = new WP_User($id, $name); 13 14 $userdata = get_userdatabylogin($user_login); 15 16 $user_login = $userdata->user_login; 17 $user_level = $userdata->user_level; 18 $user_ID = $userdata->ID; 19 $user_email = $userdata->user_email; 20 $user_url = $userdata->user_url; 21 $user_pass_md5 = md5($userdata->user_pass); 22 $user_identity = $userdata->display_name; 8 return wp_set_current_user($id, $name); 9 } 10 endif; 11 12 if ( !function_exists('wp_set_current_user') ) : 13 function wp_set_current_user($id, $name = '') { 14 global $current_user; 15 16 if ( isset($current_user) && ($id == $current_user->ID) ) 17 return $current_user; 18 19 $current_user = new WP_User($id, $name); 20 21 setup_userdata($current_user->ID); 23 22 24 23 do_action('set_current_user'); … … 28 27 endif; 29 28 29 if ( !function_exists('current_user') ) : 30 function wp_get_current_user() { 31 global $current_user; 32 33 get_currentuserinfo(); 34 35 return $current_user; 36 } 37 endif; 30 38 31 39 if ( !function_exists('get_currentuserinfo') ) : 32 40 function get_currentuserinfo() { 33 global $ user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity, $current_user;41 global $current_user; 34 42 35 43 if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) 36 44 return false; 45 46 if ( ! empty($current_user) ) 47 return; 37 48 38 49 if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || 39 50 !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { 40 $current_user = new WP_User(0); 41 return false; 42 } 43 $user_login = $_COOKIE[USER_COOKIE]; 44 $userdata = get_userdatabylogin($user_login); 45 $user_level = $userdata->user_level; 46 $user_ID = $userdata->ID; 47 $user_email = $userdata->user_email; 48 $user_url = $userdata->user_url; 49 $user_pass_md5 = md5($userdata->user_pass); 50 $user_identity = $userdata->display_name; 51 52 if ( empty($current_user) ) 53 $current_user = new WP_User($user_ID); 51 wp_set_current_user(0); 52 return false; 53 } 54 55 $user_login = $_COOKIE[USER_COOKIE]; 56 wp_set_current_user(0, $user_login); 54 57 } 55 58 endif; … … 202 205 if ( !function_exists('is_user_logged_in') ) : 203 206 function is_user_logged_in() { 204 global $current_user; 205 206 if ( $current_user->id == 0 ) 207 return false; 207 $user = wp_get_current_user(); 208 209 if ( $user->id == 0 ) 210 return false; 211 208 212 return true; 209 213 } … … 225 229 226 230 if ( !function_exists('check_admin_referer') ) : 227 function check_admin_referer() { 231 function check_admin_referer($action = -1) { 232 global $pagenow; 228 233 $adminurl = strtolower(get_settings('siteurl')).'/wp-admin'; 229 234 $referer = strtolower($_SERVER['HTTP_REFERER']); 230 if (!strstr($referer, $adminurl)) 231 die(__('Sorry, you need to <a href="http://codex.wordpress.org/Enable_Sending_Referrers">enable sending referrers</a> for this feature to work.')); 235 if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) ) { 236 $html = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'>\n\n"; 237 $html .= "<head>\n\t<title>" . __('WordPress Confirmation') . "</title>\n"; 238 $html .= "</head>\n<body>\n"; 239 if ( $_POST ) { 240 $q = http_build_query($_POST); 241 $q = explode( ini_get('arg_separator.output'), $q); 242 $html .= "\t<form method='post' action='$pagenow'>\n"; 243 foreach ( (array) $q as $a ) { 244 $v = substr(strstr($a, '='), 1); 245 $k = substr($a, 0, -(strlen($v)+1)); 246 $html .= "\t\t<input type='hidden' name='" . wp_specialchars( urldecode($k), 1 ) . "' value='" . wp_specialchars( urldecode($v), 1 ) . "' />\n"; 247 } 248 $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce($action) . "' />\n"; 249 $html .= "\t\t<p>" . __('Are you sure you want to do this?') . "</p>\n\t\t<p><a href='$adminurl'>No</a> <input type='submit' value='" . __('Yes') . "' /></p>\n\t</form>\n"; 250 } else { 251 $html .= "\t<p>" . __('Are you sure you want to do this?') . "</p>\n\t\t<p><a href='$adminurl'>No</a> <a href='" . add_query_arg( '_wpnonce', wp_create_nonce($action), $_SERVER['REQUEST_URI'] ) . "'>" . __('Yes') . "</a></p>\n"; 252 } 253 $html .= "</body>\n</html>"; 254 255 die($html); 256 } 232 257 do_action('check_admin_referer'); 233 } 234 endif; 258 }endif; 235 259 236 260 if ( !function_exists('check_ajax_referer') ) : … … 262 286 header("Location: $location"); 263 287 } 288 endif; 289 290 if ( !function_exists('wp_get_cookie_login') ): 291 function wp_get_cookie_login() { 292 if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ) 293 return false; 294 295 return array('login' => $_COOKIE[USER_COOKIE], 'password' => $_COOKIE[PASS_COOKIE]); 296 } 297 264 298 endif; 265 299 … … 445 479 endif; 446 480 481 if ( !function_exists('wp_verify_nonce') ) : 482 function wp_verify_nonce($nonce, $action = -1) { 483 $user = wp_get_current_user(); 484 $uid = $user->id; 485 486 $i = ceil(time() / 43200); 487 488 //Allow for expanding range, but only do one check if we can 489 if( substr(md5($i . DB_PASSWORD . $action . $uid), -12, 10) == $nonce || substr(md5(($i - 1) . DB_PASSWORD . $action . $uid), -12, 10) == $nonce ) 490 return true; 491 return false; 492 } 493 endif; 494 495 if ( !function_exists('wp_create_nonce') ) : 496 function wp_create_nonce($action = -1) { 497 $user = wp_get_current_user(); 498 $uid = $user->id; 499 500 $i = ceil(time() / 43200); 501 502 return substr(md5($i . DB_PASSWORD . $action . $uid), -12, 10); 503 } 504 endif; 505 447 506 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)