]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/pluggable.php
Wordpress 2.3.3
[autoinstalls/wordpress.git] / wp-includes / pluggable.php
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         $show = $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($show);
78
79         if ($metavalues) {
80                 foreach ( $metavalues as $meta ) {
81                         $value = maybe_unserialize($meta->meta_value);
82                         $user->{$meta->meta_key} = $value;
83
84                         // We need to set user_level from meta, not row
85                         if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
86                                 $user->user_level = $meta->meta_value;
87                 } // end foreach
88         } //end if
89
90         // For backwards compat.
91         if ( isset($user->first_name) )
92                 $user->user_firstname = $user->first_name;
93         if ( isset($user->last_name) )
94                 $user->user_lastname = $user->last_name;
95         if ( isset($user->description) )
96                 $user->user_description = $user->description;
97
98         wp_cache_add($user_id, $user, 'users');
99         wp_cache_add($user->user_login, $user_id, 'userlogins');
100         return $user;
101 }
102 endif;
103
104 if ( !function_exists('update_user_cache') ) :
105 function update_user_cache() {
106         return true;
107 }
108 endif;
109
110 if ( !function_exists('get_userdatabylogin') ) :
111 function get_userdatabylogin($user_login) {
112         global $wpdb;
113         $user_login = sanitize_user( $user_login );
114
115         if ( empty( $user_login ) )
116                 return false;
117
118         $user_id = wp_cache_get($user_login, 'userlogins');
119         $userdata = wp_cache_get($user_id, 'users');
120
121         if ( $userdata )
122                 return $userdata;
123
124         $user_login = $wpdb->escape($user_login);
125
126         if ( !$user_ID = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'") )
127                 return false;
128
129         $user = get_userdata($user_ID);
130         return $user;
131 }
132 endif;
133
134 if ( !function_exists( 'wp_mail' ) ) :
135 function wp_mail( $to, $subject, $message, $headers = '' ) {
136         // Compact the input, apply the filters, and extract them back out
137         extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) );
138
139         global $phpmailer;
140
141         // (Re)create it, if it's gone missing
142         if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
143                 require_once ABSPATH . WPINC . '/class-phpmailer.php';
144                 require_once ABSPATH . WPINC . '/class-smtp.php';
145                 $phpmailer = new PHPMailer();
146         }
147
148         // Headers
149         if ( empty( $headers ) ) {
150                 $headers = array();
151         } elseif ( !is_array( $headers ) ) {
152                 // Explode the headers out, so this function can take both
153                 // string headers and an array of headers.
154                 $tempheaders = (array) explode( "\n", $headers );
155                 $headers = array();
156
157                 // If it's actually got contents
158                 if ( !empty( $tempheaders ) ) {
159                         // Iterate through the raw headers
160                         foreach ( $tempheaders as $header ) {
161                                 if ( strpos($header, ':') === false )
162                                         continue;
163                                 // Explode them out
164                                 list( $name, $content ) = explode( ':', trim( $header ), 2 );
165
166                                 // Cleanup crew
167                                 $name = trim( $name );
168                                 $content = trim( $content );
169
170                                 // Mainly for legacy -- process a From: header if it's there
171                                 if ( 'from' == strtolower($name) ) {
172                                         if ( strpos($content, '<' ) !== false ) {
173                                                 // So... making my life hard again?
174                                                 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
175                                                 $from_name = str_replace( '"', '', $from_name );
176                                                 $from_name = trim( $from_name );
177
178                                                 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
179                                                 $from_email = str_replace( '>', '', $from_email );
180                                                 $from_email = trim( $from_email );
181                                         } else {
182                                                 $from_name = trim( $content );
183                                         }
184                                 } elseif ( 'content-type' == strtolower($name) ) {
185                                         if ( strpos( $content,';' ) !== false ) {
186                                                 list( $type, $charset ) = explode( ';', $content );
187                                                 $content_type = trim( $type );
188                                                 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
189                                         } else {
190                                                 $content_type = trim( $content );
191                                         }
192                                 } else {
193                                         // Add it to our grand headers array
194                                         $headers[trim( $name )] = trim( $content );
195                                 }
196                         }
197                 }
198         }
199
200         // Empty out the values that may be set
201         $phpmailer->ClearAddresses();
202         $phpmailer->ClearAllRecipients();
203         $phpmailer->ClearAttachments();
204         $phpmailer->ClearBCCs();
205         $phpmailer->ClearCCs();
206         $phpmailer->ClearCustomHeaders();
207         $phpmailer->ClearReplyTos();
208
209         // From email and name
210         // If we don't have a name from the input headers
211         if ( !isset( $from_name ) ) {
212                 $from_name = 'WordPress';
213         }
214
215         // If we don't have an email from the input headers
216         if ( !isset( $from_email ) ) {
217                 // Get the site domain and get rid of www.
218                 $sitename = strtolower( $_SERVER['SERVER_NAME'] );
219                 if ( substr( $sitename, 0, 4 ) == 'www.' ) {
220                         $sitename = substr( $sitename, 4 );
221                 }
222
223                 $from_email = 'wordpress@' . $sitename;
224         }
225
226         // Set the from name and email
227         $phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
228         $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
229
230         // Set destination address
231         $phpmailer->AddAddress( $to );
232
233         // Set mail's subject and body
234         $phpmailer->Subject = $subject;
235         $phpmailer->Body = $message;
236
237         // Set to use PHP's mail()
238         $phpmailer->IsMail();
239
240         // Set Content-Type and charset
241         // If we don't have a content-type from the input headers
242         if ( !isset( $content_type ) ) {
243                 $content_type = 'text/plain';
244         }
245
246         $content_type = apply_filters( 'wp_mail_content_type', $content_type );
247
248         // Set whether it's plaintext or not, depending on $content_type
249         if ( $content_type == 'text/html' ) {
250                 $phpmailer->IsHTML( true );
251         } else {
252                 $phpmailer->IsHTML( false );
253         }
254
255         // If we don't have a charset from the input headers
256         if ( !isset( $charset ) ) {
257                 $charset = get_bloginfo( 'charset' );
258         }
259
260         // Set the content-type and charset
261         $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
262
263         // Set custom headers
264         if ( !empty( $headers ) ) {
265                 foreach ( $headers as $name => $content ) {
266                         $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
267                 }
268         }
269
270         do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
271
272         // Send!
273         $result = @$phpmailer->Send();
274
275         return $result;
276 }
277 endif;
278
279 if ( !function_exists('wp_login') ) :
280 function wp_login($username, $password, $already_md5 = false) {
281         global $wpdb, $error;
282
283         $username = sanitize_user($username);
284
285         if ( '' == $username )
286                 return false;
287
288         if ( '' == $password ) {
289                 $error = __('<strong>ERROR</strong>: The password field is empty.');
290                 return false;
291         }
292
293         $login = get_userdatabylogin($username);
294         //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
295
296         if (!$login) {
297                 $error = __('<strong>ERROR</strong>: Invalid username.');
298                 return false;
299         } else {
300                 // If the password is already_md5, it has been double hashed.
301                 // Otherwise, it is plain text.
302                 if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) {
303                         return true;
304                 } else {
305                         $error = __('<strong>ERROR</strong>: Incorrect password.');
306                         $pwd = '';
307                         return false;
308                 }
309         }
310 }
311 endif;
312
313 if ( !function_exists('is_user_logged_in') ) :
314 function is_user_logged_in() {
315         $user = wp_get_current_user();
316
317         if ( $user->id == 0 )
318                 return false;
319
320         return true;
321 }
322 endif;
323
324 if ( !function_exists('auth_redirect') ) :
325 function auth_redirect() {
326         // Checks if a user is logged in, if not redirects them to the login page
327         if ( (!empty($_COOKIE[USER_COOKIE]) &&
328                                 !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) ||
329                          (empty($_COOKIE[USER_COOKIE])) ) {
330                 nocache_headers();
331
332                 wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
333                 exit();
334         }
335 }
336 endif;
337
338 if ( !function_exists('check_admin_referer') ) :
339 function check_admin_referer($action = -1) {
340         $adminurl = strtolower(get_option('siteurl')).'/wp-admin';
341         $referer = strtolower(wp_get_referer());
342         if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) &&
343                 !(-1 == $action && strpos($referer, $adminurl) !== false)) {
344                 wp_nonce_ays($action);
345                 die();
346         }
347         do_action('check_admin_referer', $action);
348 }endif;
349
350 if ( !function_exists('check_ajax_referer') ) :
351 function check_ajax_referer() {
352         $current_name = '';
353         if ( ( $current = wp_get_current_user() ) && $current->ID )
354                 $current_name = $current->data->user_login;
355         if ( !$current_name )
356                 die('-1');
357
358         $cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie
359         foreach ( $cookie as $tasty ) {
360                 if ( false !== strpos($tasty, USER_COOKIE) )
361                         $user = substr(strstr($tasty, '='), 1);
362                 if ( false !== strpos($tasty, PASS_COOKIE) )
363                         $pass = substr(strstr($tasty, '='), 1);
364         }
365
366         if ( $current_name != $user || !wp_login( $user, $pass, true ) )
367                 die('-1');
368         do_action('check_ajax_referer');
369 }
370 endif;
371
372 // Cookie safe redirect.  Works around IIS Set-Cookie bug.
373 // http://support.microsoft.com/kb/q176113/
374 if ( !function_exists('wp_redirect') ) :
375 function wp_redirect($location, $status = 302) {
376         global $is_IIS;
377
378         $location = apply_filters('wp_redirect', $location, $status);
379
380         if ( !$location ) // allows the wp_redirect filter to cancel a redirect
381                 return false;
382
383         $location = wp_sanitize_redirect($location);
384
385         if ( $is_IIS ) {
386                 header("Refresh: 0;url=$location");
387         } else {
388                 if ( php_sapi_name() != 'cgi-fcgi' )
389                         status_header($status); // This causes problems on IIS and some FastCGI setups
390                 header("Location: $location");
391         }
392 }
393 endif;
394
395 if ( !function_exists('wp_sanitize_redirect') ) :
396 /**
397  * sanitizes a URL for use in a redirect
398  * @return string redirect-sanitized URL
399  **/
400 function wp_sanitize_redirect($location) {
401         $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
402         $location = wp_kses_no_null($location);
403
404         // remove %0d and %0a from location
405         $strip = array('%0d', '%0a');
406         $found = true;
407         while($found) {
408                 $found = false;
409                 foreach($strip as $val) {
410                         while(strpos($location, $val) !== false) {
411                                 $found = true;
412                                 $location = str_replace($val, '', $location);
413                         }
414                 }
415         }
416         return $location;
417 }
418 endif;
419
420 if ( !function_exists('wp_safe_redirect') ) :
421 /**
422  * performs a safe (local) redirect, using wp_redirect()
423  * @return void
424  **/
425 function wp_safe_redirect($location, $status = 302) {
426
427         // Need to look at the URL the way it will end up in wp_redirect()
428         $location = wp_sanitize_redirect($location);
429
430         // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
431         if ( substr($location, 0, 2) == '//' )
432                 $location = 'http:' . $location;
433
434         $lp  = parse_url($location);
435         $wpp = parse_url(get_option('home'));
436
437         $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), $lp['host']);
438
439         if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
440                 $location = get_option('siteurl') . '/wp-admin/';
441
442         wp_redirect($location, $status);
443 }
444 endif;
445
446 if ( !function_exists('wp_get_cookie_login') ):
447 function wp_get_cookie_login() {
448         if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) )
449                 return false;
450
451         return array('login' => $_COOKIE[USER_COOKIE],  'password' => $_COOKIE[PASS_COOKIE]);
452 }
453
454 endif;
455
456 if ( !function_exists('wp_setcookie') ) :
457 function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
458         if ( !$already_md5 )
459                 $password = md5( md5($password) ); // Double hash the password in the cookie.
460
461         if ( empty($home) )
462                 $cookiepath = COOKIEPATH;
463         else
464                 $cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' );
465
466         if ( empty($siteurl) ) {
467                 $sitecookiepath = SITECOOKIEPATH;
468                 $cookiehash = COOKIEHASH;
469         } else {
470                 $sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' );
471                 $cookiehash = md5($siteurl);
472         }
473
474         if ( $remember )
475                 $expire = time() + 31536000;
476         else
477                 $expire = 0;
478
479         setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN);
480         setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN);
481
482         if ( $cookiepath != $sitecookiepath ) {
483                 setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN);
484                 setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN);
485         }
486 }
487 endif;
488
489 if ( !function_exists('wp_clearcookie') ) :
490 function wp_clearcookie() {
491         setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
492         setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
493         setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
494         setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
495 }
496 endif;
497
498 if ( ! function_exists('wp_notify_postauthor') ) :
499 function wp_notify_postauthor($comment_id, $comment_type='') {
500         global $wpdb;
501
502         $comment = get_comment($comment_id);
503         $post    = get_post($comment->comment_post_ID);
504         $user    = get_userdata( $post->post_author );
505
506         if ('' == $user->user_email) return false; // If there's no email to send the comment to
507
508         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
509
510         $blogname = get_option('blogname');
511
512         if ( empty( $comment_type ) ) $comment_type = 'comment';
513
514         if ('comment' == $comment_type) {
515                 $notify_message  = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
516                 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
517                 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
518                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
519                 $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
520                 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
521                 $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
522                 $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
523         } elseif ('trackback' == $comment_type) {
524                 $notify_message  = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
525                 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
526                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
527                 $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
528                 $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
529                 $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
530         } elseif ('pingback' == $comment_type) {
531                 $notify_message  = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
532                 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
533                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
534                 $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
535                 $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
536                 $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
537         }
538         $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
539         $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
540         $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
541
542         $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
543
544         if ( '' == $comment->comment_author ) {
545                 $from = "From: \"$blogname\" <$wp_email>";
546                 if ( '' != $comment->comment_author_email )
547                         $reply_to = "Reply-To: $comment->comment_author_email";
548         } else {
549                 $from = "From: \"$comment->comment_author\" <$wp_email>";
550                 if ( '' != $comment->comment_author_email )
551                         $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
552         }
553
554         $message_headers = "$from\n"
555                 . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
556
557         if ( isset($reply_to) )
558                 $message_headers .= $reply_to . "\n";
559
560         $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
561         $subject = apply_filters('comment_notification_subject', $subject, $comment_id);
562         $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
563
564         @wp_mail($user->user_email, $subject, $notify_message, $message_headers);
565
566         return true;
567 }
568 endif;
569
570 /* wp_notify_moderator
571    notifies the moderator of the blog (usually the admin)
572    about a new comment that waits for approval
573    always returns true
574  */
575 if ( !function_exists('wp_notify_moderator') ) :
576 function wp_notify_moderator($comment_id) {
577         global $wpdb;
578
579         if( get_option( "moderation_notify" ) == 0 )
580                 return true;
581
582         $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
583         $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
584
585         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
586         $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
587
588         $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";
589         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
590         $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
591         $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
592         $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
593         $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
594         $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
595         $notify_message .= sprintf( __('Approve it: %s'),  get_option('siteurl')."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "\r\n";
596         $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
597         $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
598         $notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n";
599         $notify_message .= get_option('siteurl') . "/wp-admin/moderation.php\r\n";
600
601         $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_option('blogname'), $post->post_title );
602         $admin_email = get_option('admin_email');
603
604         $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
605         $subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
606
607         @wp_mail($admin_email, $subject, $notify_message);
608
609         return true;
610 }
611 endif;
612
613 if ( !function_exists('wp_new_user_notification') ) :
614 function wp_new_user_notification($user_id, $plaintext_pass = '') {
615         $user = new WP_User($user_id);
616
617         $user_login = stripslashes($user->user_login);
618         $user_email = stripslashes($user->user_email);
619
620         $message  = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n";
621         $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
622         $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
623
624         @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
625
626         if ( empty($plaintext_pass) )
627                 return;
628
629         $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
630         $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
631         $message .= get_option('siteurl') . "/wp-login.php\r\n";
632
633         wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
634
635 }
636 endif;
637
638 if ( !function_exists('wp_verify_nonce') ) :
639 function wp_verify_nonce($nonce, $action = -1) {
640         $user = wp_get_current_user();
641         $uid = (int) $user->id;
642
643         $i = ceil(time() / 43200);
644
645         //Allow for expanding range, but only do one check if we can
646         if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce )
647                 return true;
648         return false;
649 }
650 endif;
651
652 if ( !function_exists('wp_create_nonce') ) :
653 function wp_create_nonce($action = -1) {
654         $user = wp_get_current_user();
655         $uid = (int) $user->id;
656
657         $i = ceil(time() / 43200);
658
659         return substr(wp_hash($i . $action . $uid), -12, 10);
660 }
661 endif;
662
663 if ( !function_exists('wp_salt') ) :
664 function wp_salt() {
665         $salt = get_option('secret');
666         if ( empty($salt) )
667                 $salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH;
668
669         return $salt;
670 }
671 endif;
672
673 if ( !function_exists('wp_hash') ) :
674 function wp_hash($data) {
675         $salt = wp_salt();
676
677         if ( function_exists('hash_hmac') ) {
678                 return hash_hmac('md5', $data, $salt);
679         } else {
680                 return md5($data . $salt);
681         }
682 }
683 endif;
684
685 ?>