[ Index ]

PHP Cross Reference of WordPress Trunk (Latest)

title

Body

[close]

/wp-includes/ -> pluggable-functions.php (source)

   1  <?php
   2  
   3      /* These functions can be replaced via plugins.  They are loaded after
   4       plugins are loaded. */
   5  
   6  if ( !function_exists('set_current_user') ) :
   7  function set_current_user($id, $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);
  22  
  23      do_action('set_current_user');
  24  
  25      return $current_user;
  26  }
  27  endif;
  28  
  29  if ( !function_exists('wp_get_current_user') ) :
  30  function wp_get_current_user() {
  31      global $current_user;
  32  
  33      get_currentuserinfo();
  34  
  35      return $current_user;
  36  }
  37  endif;
  38  
  39  if ( !function_exists('get_currentuserinfo') ) :
  40  function get_currentuserinfo() {
  41      global $current_user;
  42  
  43      if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
  44          return false;
  45  
  46      if ( ! empty($current_user) )
  47          return;
  48  
  49      if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || 
  50          !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) {
  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);
  57  }
  58  endif;
  59  
  60  if ( !function_exists('get_userdata') ) :
  61  function get_userdata( $user_id ) {
  62      global $wpdb;
  63      $user_id = (int) $user_id;
  64      if ( $user_id == 0 )
  65          return false;
  66  
  67      $user = wp_cache_get($user_id, 'users');
  68  
  69      if ( $user )
  70          return $user;
  71  
  72      if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id' LIMIT 1") )
  73          return false;
  74  
  75      $wpdb->hide_errors();
  76      $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
  77      $wpdb->show_errors();
  78  
  79      if ($metavalues) {
  80          foreach ( $metavalues as $meta ) {
  81              @ $value = unserialize($meta->meta_value);
  82              if ($value === FALSE)
  83                  $value = $meta->meta_value;
  84              $user->{$meta->meta_key} = $value;
  85  
  86              // We need to set user_level from meta, not row
  87              if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
  88                  $user->user_level = $meta->meta_value;
  89          } // end foreach
  90      } //end if
  91  
  92      // For backwards compat.
  93      if ( isset($user->first_name) )
  94          $user->user_firstname = $user->first_name;
  95      if ( isset($user->last_name) )
  96          $user->user_lastname = $user->last_name;
  97      if ( isset($user->description) )
  98          $user->user_description = $user->description;
  99  
 100      wp_cache_add($user_id, $user, 'users');
 101      wp_cache_add($user->user_login, $user, 'userlogins');
 102  
 103      return $user;
 104  }
 105  endif;
 106  
 107  if ( !function_exists('update_user_cache') ) :
 108  function update_user_cache() {
 109      return true;
 110  }
 111  endif;
 112  
 113  if ( !function_exists('get_userdatabylogin') ) :
 114  function get_userdatabylogin($user_login) {
 115      global $wpdb;
 116      $user_login = sanitize_user( $user_login );
 117  
 118      if ( empty( $user_login ) )
 119          return false;
 120  
 121      $userdata = wp_cache_get($user_login, 'userlogins');
 122      if ( $userdata )
 123          return $userdata;
 124  
 125      if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") )
 126          return false;
 127  
 128      $wpdb->hide_errors();
 129      $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
 130      $wpdb->show_errors();
 131  
 132      if ($metavalues) {
 133          foreach ( $metavalues as $meta ) {
 134              @ $value = unserialize($meta->meta_value);
 135              if ($value === FALSE)
 136                  $value = $meta->meta_value;
 137              $user->{$meta->meta_key} = $value;
 138  
 139              // We need to set user_level from meta, not row
 140              if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
 141                  $user->user_level = $meta->meta_value;
 142          }
 143      }
 144  
 145      // For backwards compat.
 146      if ( isset($user->first_name) )
 147          $user->user_firstname = $user->first_name;
 148      if ( isset($user->last_name) )
 149          $user->user_lastname = $user->last_name;
 150      if ( isset($user->description) )
 151          $user->user_description = $user->description;
 152  
 153      wp_cache_add($user->ID, $user, 'users');
 154      wp_cache_add($user->user_login, $user, 'userlogins');
 155  
 156      return $user;
 157  
 158  }
 159  endif;
 160  
 161  if ( !function_exists('wp_mail') ) :
 162  function wp_mail($to, $subject, $message, $headers = '') {
 163      if( $headers == '' ) {
 164          $headers = "MIME-Version: 1.0\n" .
 165              "From: wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n" . 
 166              "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
 167      }
 168  
 169      return @mail($to, $subject, $message, $headers);
 170  }
 171  endif;
 172  
 173  if ( !function_exists('wp_login') ) :
 174  function wp_login($username, $password, $already_md5 = false) {
 175      global $wpdb, $error;
 176  
 177      if ( '' == $username )
 178          return false;
 179  
 180      if ( '' == $password ) {
 181          $error = __('<strong>Error</strong>: The password field is empty.');
 182          return false;
 183      }
 184  
 185      $login = get_userdatabylogin($username);
 186      //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
 187  
 188      if (!$login) {
 189          $error = __('<strong>Error</strong>: Wrong username.');
 190          return false;
 191      } else {
 192          // If the password is already_md5, it has been double hashed.
 193          // Otherwise, it is plain text.
 194          if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) {
 195              return true;
 196          } else {
 197              $error = __('<strong>Error</strong>: Incorrect password.');
 198              $pwd = '';
 199              return false;
 200          }
 201      }
 202  }
 203  endif;
 204  
 205  if ( !function_exists('is_user_logged_in') ) :
 206  function is_user_logged_in() {
 207      $user = wp_get_current_user();
 208  
 209      if ( $user->id == 0 )
 210          return false;
 211  
 212      return true;
 213  }
 214  endif;
 215  
 216  if ( !function_exists('auth_redirect') ) :
 217  function auth_redirect() {
 218      // Checks if a user is logged in, if not redirects them to the login page
 219      if ( (!empty($_COOKIE[USER_COOKIE]) && 
 220                  !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) ||
 221               (empty($_COOKIE[USER_COOKIE])) ) {
 222          nocache_headers();
 223  
 224          header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
 225          exit();
 226      }
 227  }
 228  endif;
 229  
 230  if ( !function_exists('check_admin_referer') ) :
 231  function check_admin_referer($action = -1) {
 232      global $pagenow, $menu, $submenu, $parent_file, $submenu_file;;
 233      $adminurl = strtolower(get_settings('siteurl')).'/wp-admin';
 234      $referer = strtolower($_SERVER['HTTP_REFERER']);
 235      if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) &&
 236          !(-1 == $action && strstr($referer, $adminurl)) ) {
 237          if ( $referer ) 
 238              $adminurl = $referer;
 239          $title = __('WordPress Confirmation');
 240          require_once (ABSPATH . '/wp-admin/admin-header.php');
 241          // Remove extra layer of slashes.
 242          $_POST   = stripslashes_deep($_POST  );
 243          if ( $_POST ) {
 244              $q = http_build_query($_POST);
 245              $q = explode( ini_get('arg_separator.output'), $q);
 246              $html .= "\t<form method='post' action='$pagenow'>\n";
 247              foreach ( (array) $q as $a ) {
 248                  $v = substr(strstr($a, '='), 1);
 249                  $k = substr($a, 0, -(strlen($v)+1));
 250                  $html .= "\t\t<input type='hidden' name='" . wp_specialchars( urldecode($k), 1 ) . "' value='" . wp_specialchars( urldecode($v), 1 ) . "' />\n";
 251              }
 252              $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce($action) . "' />\n";
 253              $html .= "\t\t<div id='message' class='confirm fade'>\n\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\t</div>\n\t</form>\n";
 254          } else {
 255              $html .= "\t<div id='message' class='confirm fade'>\n\t<p>" . __('Are you sure you want to do this?') . "</p>\n\t<p><a href='$adminurl'>" . __('No') . "</a> <a href='" . add_query_arg( '_wpnonce', wp_create_nonce($action), $_SERVER['REQUEST_URI'] ) . "'>" . __('Yes') . "</a></p>\n\t</div>\n";
 256          }
 257          $html .= "</body>\n</html>";
 258          echo $html;
 259          include_once (ABSPATH . '/wp-admin/admin-footer.php');
 260          die();
 261      }
 262      do_action('check_admin_referer', $action);
 263  }endif;
 264  
 265  if ( !function_exists('check_ajax_referer') ) :
 266  function check_ajax_referer() {
 267      $cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie
 268      foreach ( $cookie as $tasty ) {
 269          if ( false !== strpos($tasty, USER_COOKIE) )
 270              $user = substr(strstr($tasty, '='), 1);
 271          if ( false !== strpos($tasty, PASS_COOKIE) )
 272              $pass = substr(strstr($tasty, '='), 1);
 273      }
 274      if ( !wp_login( $user, $pass, true ) )
 275          die('-1');
 276      do_action('check_ajax_referer');
 277  }
 278  endif;
 279  
 280  // Cookie safe redirect.  Works around IIS Set-Cookie bug.
 281  // http://support.microsoft.com/kb/q176113/
 282  if ( !function_exists('wp_redirect') ) :
 283  function wp_redirect($location) {
 284      global $is_IIS;
 285  
 286      $location = str_replace( array("\n", "\r"), '', $location);
 287  
 288      if ($is_IIS)
 289          header("Refresh: 0;url=$location");
 290      else
 291          header("Location: $location");
 292  }
 293  endif;
 294  
 295  if ( !function_exists('wp_get_cookie_login') ):
 296  function wp_get_cookie_login() {
 297      if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) )
 298          return false;
 299  
 300      return array('login' => $_COOKIE[USER_COOKIE],    'password' => $_COOKIE[PASS_COOKIE]);
 301  }
 302  
 303  endif;
 304  
 305  if ( !function_exists('wp_setcookie') ) :
 306  function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
 307      if ( !$already_md5 )
 308          $password = md5( md5($password) ); // Double hash the password in the cookie.
 309  
 310      if ( empty($home) )
 311          $cookiepath = COOKIEPATH;
 312      else
 313          $cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' );
 314  
 315      if ( empty($siteurl) ) {
 316          $sitecookiepath = SITECOOKIEPATH;
 317          $cookiehash = COOKIEHASH;
 318      } else {
 319          $sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' );
 320          $cookiehash = md5($siteurl);
 321      }
 322  
 323      if ( $remember )
 324          $expire = time() + 31536000;
 325      else
 326          $expire = 0;
 327  
 328      setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN);
 329      setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN);
 330  
 331      if ( $cookiepath != $sitecookiepath ) {
 332          setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN);
 333          setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN);
 334      }
 335  }
 336  endif;
 337  
 338  if ( !function_exists('wp_clearcookie') ) :
 339  function wp_clearcookie() {
 340      setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
 341      setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
 342      setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
 343      setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
 344  }
 345  endif;
 346  
 347  if ( ! function_exists('wp_notify_postauthor') ) :
 348  function wp_notify_postauthor($comment_id, $comment_type='') {
 349      global $wpdb;
 350      
 351      $comment = get_comment($comment_id);
 352      $post    = get_post($comment->comment_post_ID);
 353      $user    = get_userdata( $post->post_author );
 354  
 355      if ('' == $user->user_email) return false; // If there's no email to send the comment to
 356  
 357      $comment_author_domain = gethostbyaddr($comment->comment_author_IP);
 358  
 359      $blogname = get_settings('blogname');
 360  
 361      if ( empty( $comment_type ) ) $comment_type = 'comment';
 362  
 363      if ('comment' == $comment_type) {
 364          $notify_message  = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
 365          $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 366          $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
 367          $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
 368          $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
 369          $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
 370          $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
 371          $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
 372      } elseif ('trackback' == $comment_type) {
 373          $notify_message  = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
 374          $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 375          $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
 376          $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
 377          $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
 378          $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
 379      } elseif ('pingback' == $comment_type) {
 380          $notify_message  = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
 381          $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 382          $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
 383          $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
 384          $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
 385          $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
 386      }
 387      $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
 388      $notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/comment.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
 389      $notify_message .= sprintf( __('To mark this comment as spam, visit: %s'), get_settings('siteurl').'/wp-admin/comment.php?action=confirmdeletecomment&delete_type=spam&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
 390  
 391      $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
 392  
 393      if ( '' == $comment->comment_author ) {
 394          $from = "From: \"$blogname\" <$wp_email>";
 395          if ( '' != $comment->comment_author_email )
 396              $reply_to = "Reply-To: $comment->comment_author_email";
 397       } else {
 398          $from = "From: \"$comment->comment_author\" <$wp_email>";
 399          if ( '' != $comment->comment_author_email )
 400              $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
 401       }
 402  
 403      $message_headers = "MIME-Version: 1.0\n"
 404          . "$from\n"
 405          . "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
 406  
 407      if ( isset($reply_to) )
 408          $message_headers .= $reply_to . "\n";
 409  
 410      $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
 411      $subject = apply_filters('comment_notification_subject', $subject, $comment_id);
 412      $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
 413  
 414      @wp_mail($user->user_email, $subject, $notify_message, $message_headers);
 415     
 416      return true;
 417  }
 418  endif;
 419  
 420  /* wp_notify_moderator
 421     notifies the moderator of the blog (usually the admin)
 422     about a new comment that waits for approval
 423     always returns true
 424   */
 425  if ( !function_exists('wp_notify_moderator') ) :
 426  function wp_notify_moderator($comment_id) {
 427      global $wpdb;
 428  
 429      if( get_settings( "moderation_notify" ) == 0 )
 430          return true; 
 431      
 432      $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
 433      $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
 434  
 435      $comment_author_domain = gethostbyaddr($comment->comment_author_IP);
 436      $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
 437  
 438      $notify_message  = sprintf( __('A new comment on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n";
 439      $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
 440      $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 441      $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
 442      $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
 443      $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
 444      $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
 445      $notify_message .= sprintf( __('To approve this comment, visit: %s'),  get_settings('siteurl').'/wp-admin/comment.php?action=mailapprovecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
 446      $notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/comment.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
 447      $notify_message .= sprintf( __('To mark this comment as spam, visit: %s'), get_settings('siteurl').'/wp-admin/comment.php?action=confirmdeletecomment&delete_type=spam&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
 448      $notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n";
 449      $notify_message .= get_settings('siteurl') . "/wp-admin/moderation.php\r\n";
 450  
 451      $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_settings('blogname'), $post->post_title );
 452      $admin_email = get_settings('admin_email');
 453  
 454      $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
 455      $subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
 456  
 457      @wp_mail($admin_email, $subject, $notify_message);
 458      
 459      return true;
 460  }
 461  endif;
 462  
 463  if ( !function_exists('wp_new_user_notification') ) :
 464  function wp_new_user_notification($user_id, $plaintext_pass = '') {
 465      $user = new WP_User($user_id);
 466  
 467      $user_login = stripslashes($user->user_login);
 468      $user_email = stripslashes($user->user_email);
 469  
 470      $message  = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
 471      $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
 472      $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
 473  
 474      @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
 475  
 476      if ( empty($plaintext_pass) )
 477          return;
 478  
 479      $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
 480      $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
 481      $message .= get_settings('siteurl') . "/wp-login.php\r\n";
 482  
 483      wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
 484  
 485  }
 486  endif;
 487  
 488  if ( !function_exists('wp_verify_nonce') ) :
 489  function wp_verify_nonce($nonce, $action = -1) {
 490      $user = wp_get_current_user();
 491      $uid = $user->id;
 492  
 493      $i = ceil(time() / 43200);
 494  
 495      //Allow for expanding range, but only do one check if we can
 496      if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce )
 497          return true;
 498      return false;
 499  }
 500  endif;
 501  
 502  if ( !function_exists('wp_create_nonce') ) :
 503  function wp_create_nonce($action = -1) {
 504      $user = wp_get_current_user();
 505      $uid = $user->id;
 506  
 507      $i = ceil(time() / 43200);
 508      
 509      return substr(wp_hash($i . $action . $uid), -12, 10);
 510  }
 511  endif;
 512  
 513  if ( !function_exists('wp_salt') ) :
 514  function wp_salt() {
 515      $salt = get_option('secret');
 516      if ( empty($salt) )
 517          $salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH;
 518  
 519      return $salt;
 520  }
 521  endif;
 522  
 523  if ( !function_exists('wp_hash') ) :
 524  function wp_hash($data) {
 525      $salt = wp_salt();
 526  
 527      if ( function_exists('hash_hmac') ) {
 528          return hash_hmac('md5', $data, $salt);
 529      } else {
 530          return md5($data . $salt);
 531      }
 532  }
 533  endif;
 534  
 535  ?>

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sun Jun 11 00:10:35 2006 Courtesy of Taragana