]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/pluggable.php
Wordpress 2.5.1-scripts
[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  * @package WordPress
7  */
8
9 if ( !function_exists('set_current_user') ) :
10 /**
11  * set_current_user() - Populates global user information for any user
12  *
13  * Set $id to null and specify a name if you do not know a user's ID
14  *
15  * @since 2.0.1
16  * @see wp_set_current_user() An alias of wp_set_current_user()
17  *
18  * @param int|null $id User ID.
19  * @param string $name Optional. The user's username
20  * @return object returns wp_set_current_user()
21  */
22 function set_current_user($id, $name = '') {
23         return wp_set_current_user($id, $name);
24 }
25 endif;
26
27 if ( !function_exists('wp_set_current_user') ) :
28 /**
29  * wp_set_current_user() - Changes the current user by ID or name
30  *
31  * Set $id to null and specify a name if you do not know a user's ID
32  *
33  * Some WordPress functionality is based on the current user and
34  * not based on the signed in user. Therefore, it opens the ability
35  * to edit and perform actions on users who aren't signed in.
36  *
37  * @since 2.0.4
38  * @global object $current_user The current user object which holds the user data.
39  * @uses do_action() Calls 'set_current_user' hook after setting the current user.
40  *
41  * @param int $id User ID
42  * @param string $name User's username
43  * @return WP_User Current user User object
44  */
45 function wp_set_current_user($id, $name = '') {
46         global $current_user;
47
48         if ( isset($current_user) && ($id == $current_user->ID) )
49                 return $current_user;
50
51         $current_user = new WP_User($id, $name);
52
53         setup_userdata($current_user->ID);
54
55         do_action('set_current_user');
56
57         return $current_user;
58 }
59 endif;
60
61 if ( !function_exists('wp_get_current_user') ) :
62 /**
63  * wp_get_current_user() - Retrieve the current user object
64  *
65  * @since 2.0.4
66  *
67  * @return WP_User Current user WP_User object
68  */
69 function wp_get_current_user() {
70         global $current_user;
71
72         get_currentuserinfo();
73
74         return $current_user;
75 }
76 endif;
77
78 if ( !function_exists('get_currentuserinfo') ) :
79 /**
80  * get_currentuserinfo() - Populate global variables with information about the currently logged in user
81  *
82  * Will set the current user, if the current user is not set. The current
83  * user will be set to the logged in person. If no user is logged in, then
84  * it will set the current user to 0, which is invalid and won't have any
85  * permissions.
86  *
87  * @since 0.71
88  * @uses $current_user Checks if the current user is set
89  * @uses wp_validate_auth_cookie() Retrieves current logged in user.
90  *
91  * @return bool|null False on XMLRPC Request and invalid auth cookie. Null when current user set
92  */
93 function get_currentuserinfo() {
94         global $current_user;
95
96         if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
97                 return false;
98
99         if ( ! empty($current_user) )
100                 return;
101
102         if ( ! $user = wp_validate_auth_cookie() ) {
103                 wp_set_current_user(0);
104                 return false;
105         }
106
107         wp_set_current_user($user);
108 }
109 endif;
110
111 if ( !function_exists('get_userdata') ) :
112 /**
113  * get_userdata() - Retrieve user info by user ID
114  *
115  * @since 0.71
116  *
117  * @param int $user_id User ID
118  * @return bool|object False on failure, User DB row object
119  */
120 function get_userdata( $user_id ) {
121         global $wpdb;
122
123         $user_id = absint($user_id);
124         if ( $user_id == 0 )
125                 return false;
126
127         $user = wp_cache_get($user_id, 'users');
128
129         if ( $user )
130                 return $user;
131
132         if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id)) )
133                 return false;
134
135         _fill_user($user);
136
137         return $user;
138 }
139 endif;
140
141 if ( !function_exists('update_user_cache') ) :
142 /**
143  * update_user_cache() - Updates a users cache when overridden by a plugin
144  *
145  * Core function does nothing.
146  *
147  * @since 1.5
148  *
149  * @return bool Only returns true
150  */
151 function update_user_cache() {
152         return true;
153 }
154 endif;
155
156 if ( !function_exists('get_userdatabylogin') ) :
157 /**
158  * get_userdatabylogin() - Retrieve user info by login name
159  *
160  * @since 0.71
161  *
162  * @param string $user_login User's username
163  * @return bool|object False on failure, User DB row object
164  */
165 function get_userdatabylogin($user_login) {
166         global $wpdb;
167         $user_login = sanitize_user( $user_login );
168
169         if ( empty( $user_login ) )
170                 return false;
171
172         $user_id = wp_cache_get($user_login, 'userlogins');
173
174         $user = false;
175         if ( false !== $user_id )
176                 $user = wp_cache_get($user_id, 'users');
177
178         if ( false !== $user )
179                 return $user;
180
181         if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_login = %s", $user_login)) )
182                 return false;
183
184         _fill_user($user);
185
186         return $user;
187 }
188 endif;
189
190 if ( !function_exists('get_user_by_email') ) :
191 /**
192  * get_user_by_email() - Retrieve user info by email
193  *
194  * @since 2.5
195  *
196  * @param string $email User's email address
197  * @return bool|object False on failure, User DB row object
198  */
199 function get_user_by_email($email) {
200         global $wpdb;
201
202         $user_id = wp_cache_get($email, 'useremail');
203
204         $user = false;
205         if ( false !== $user_id )
206                 $user = wp_cache_get($user_id, 'users');
207
208         if ( false !== $user )
209                 return $user;
210
211         if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_email = %s", $email)) )
212                 return false;
213
214         _fill_user($user);
215
216         return $user;
217 }
218 endif;
219
220 if ( !function_exists( 'wp_mail' ) ) :
221 /**
222  * wp_mail() - Function to send mail, similar to PHP's mail
223  *
224  * A true return value does not automatically mean that the
225  * user received the email successfully. It just only means
226  * that the method used was able to process the request
227  * without any errors.
228  *
229  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks
230  * allow from creating a from address like 'Name <email@address.com>'
231  * when both are set. If just 'wp_mail_from' is set, then just
232  * the email address will be used with no name.
233  *
234  * The default content type is 'text/plain' which does not
235  * allow using HTML. However, you can set the content type
236  * of the email by using the 'wp_mail_content_type' filter.
237  *
238  * The default charset is based on the charset used on the
239  * blog. The charset can be set using the 'wp_mail_charset'
240  * filter.
241  *
242  * @since 1.2.1
243  * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
244  * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
245  * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
246  * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
247  * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
248  * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
249  *              phpmailer object.
250  * @uses PHPMailer
251  * @
252  *
253  * @param string $to Email address to send message
254  * @param string $subject Email subject
255  * @param string $message Message contents
256  * @param string|array $headers Optional. Additional headers.
257  * @return bool Whether the email contents were sent successfully.
258  */
259 function wp_mail( $to, $subject, $message, $headers = '' ) {
260         // Compact the input, apply the filters, and extract them back out
261         extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) );
262
263         global $phpmailer;
264
265         // (Re)create it, if it's gone missing
266         if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
267                 require_once ABSPATH . WPINC . '/class-phpmailer.php';
268                 require_once ABSPATH . WPINC . '/class-smtp.php';
269                 $phpmailer = new PHPMailer();
270         }
271
272         // Headers
273         if ( empty( $headers ) ) {
274                 $headers = array();
275         } elseif ( !is_array( $headers ) ) {
276                 // Explode the headers out, so this function can take both
277                 // string headers and an array of headers.
278                 $tempheaders = (array) explode( "\n", $headers );
279                 $headers = array();
280
281                 // If it's actually got contents
282                 if ( !empty( $tempheaders ) ) {
283                         // Iterate through the raw headers
284                         foreach ( $tempheaders as $header ) {
285                                 if ( strpos($header, ':') === false )
286                                         continue;
287                                 // Explode them out
288                                 list( $name, $content ) = explode( ':', trim( $header ), 2 );
289
290                                 // Cleanup crew
291                                 $name = trim( $name );
292                                 $content = trim( $content );
293
294                                 // Mainly for legacy -- process a From: header if it's there
295                                 if ( 'from' == strtolower($name) ) {
296                                         if ( strpos($content, '<' ) !== false ) {
297                                                 // So... making my life hard again?
298                                                 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
299                                                 $from_name = str_replace( '"', '', $from_name );
300                                                 $from_name = trim( $from_name );
301
302                                                 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
303                                                 $from_email = str_replace( '>', '', $from_email );
304                                                 $from_email = trim( $from_email );
305                                         } else {
306                                                 $from_name = trim( $content );
307                                         }
308                                 } elseif ( 'content-type' == strtolower($name) ) {
309                                         if ( strpos( $content,';' ) !== false ) {
310                                                 list( $type, $charset ) = explode( ';', $content );
311                                                 $content_type = trim( $type );
312                                                 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
313                                         } else {
314                                                 $content_type = trim( $content );
315                                         }
316                                 } else {
317                                         // Add it to our grand headers array
318                                         $headers[trim( $name )] = trim( $content );
319                                 }
320                         }
321                 }
322         }
323
324         // Empty out the values that may be set
325         $phpmailer->ClearAddresses();
326         $phpmailer->ClearAllRecipients();
327         $phpmailer->ClearAttachments();
328         $phpmailer->ClearBCCs();
329         $phpmailer->ClearCCs();
330         $phpmailer->ClearCustomHeaders();
331         $phpmailer->ClearReplyTos();
332
333         // From email and name
334         // If we don't have a name from the input headers
335         if ( !isset( $from_name ) ) {
336                 $from_name = 'WordPress';
337         }
338
339         // If we don't have an email from the input headers
340         if ( !isset( $from_email ) ) {
341                 // Get the site domain and get rid of www.
342                 $sitename = strtolower( $_SERVER['SERVER_NAME'] );
343                 if ( substr( $sitename, 0, 4 ) == 'www.' ) {
344                         $sitename = substr( $sitename, 4 );
345                 }
346
347                 $from_email = 'wordpress@' . $sitename;
348         }
349
350         // Set the from name and email
351         $phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
352         $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
353
354         // Set destination address
355         $phpmailer->AddAddress( $to );
356
357         // Set mail's subject and body
358         $phpmailer->Subject = $subject;
359         $phpmailer->Body = $message;
360
361         // Set to use PHP's mail()
362         $phpmailer->IsMail();
363
364         // Set Content-Type and charset
365         // If we don't have a content-type from the input headers
366         if ( !isset( $content_type ) ) {
367                 $content_type = 'text/plain';
368         }
369
370         $content_type = apply_filters( 'wp_mail_content_type', $content_type );
371
372         // Set whether it's plaintext or not, depending on $content_type
373         if ( $content_type == 'text/html' ) {
374                 $phpmailer->IsHTML( true );
375         } else {
376                 $phpmailer->IsHTML( false );
377         }
378
379         // If we don't have a charset from the input headers
380         if ( !isset( $charset ) ) {
381                 $charset = get_bloginfo( 'charset' );
382         }
383
384         // Set the content-type and charset
385         $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
386
387         // Set custom headers
388         if ( !empty( $headers ) ) {
389                 foreach ( $headers as $name => $content ) {
390                         $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
391                 }
392         }
393
394         do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
395
396         // Send!
397         $result = @$phpmailer->Send();
398
399         return $result;
400 }
401 endif;
402
403 /**
404  * wp_authenticate() - Checks a user's login information and logs them in if it checks out
405  * @since 2.5
406  *
407  * @param string $username User's username
408  * @param string $password User's password
409  * @return WP_Error|WP_User WP_User object if login successful, otherwise WP_Error object.
410  */
411 if ( !function_exists('wp_authenticate') ) :
412 function wp_authenticate($username, $password) {
413         $username = sanitize_user($username);
414
415         if ( '' == $username )
416                 return new WP_Error('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
417
418         if ( '' == $password )
419                 return new WP_Error('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
420
421         $user = get_userdatabylogin($username);
422
423         if ( !$user || ($user->user_login != $username) ) {
424                 do_action( 'wp_login_failed', $username );
425                 return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Invalid username.'));
426         }
427
428         $user = apply_filters('wp_authenticate_user', $user, $password);
429         if ( is_wp_error($user) ) {
430                 do_action( 'wp_login_failed', $username );
431                 return $user;
432         }
433
434         if ( !wp_check_password($password, $user->user_pass, $user->ID) ) {
435                 do_action( 'wp_login_failed', $username );
436                 return new WP_Error('incorrect_password', __('<strong>ERROR</strong>: Incorrect password.'));
437         }
438
439         return new WP_User($user->ID);
440 }
441 endif;
442
443 /**
444  * wp_logout() - Log the current user out
445  * @since 2.5
446  *
447  */
448 if ( !function_exists('wp_logout') ) :
449 function wp_logout() {
450         wp_clear_auth_cookie();
451         do_action('wp_logout');
452 }
453 endif;
454
455 if ( !function_exists('wp_validate_auth_cookie') ) :
456 /**
457  * wp_validate_auth_cookie() - Validates authentication cookie
458  *
459  * The checks include making sure that the authentication cookie
460  * is set and pulling in the contents (if $cookie is not used).
461  *
462  * Makes sure the cookie is not expired. Verifies the hash in
463  * cookie is what is should be and compares the two.
464  *
465  * @since 2.5
466  *
467  * @param string $cookie Optional. If used, will validate contents instead of cookie's
468  * @return bool|int False if invalid cookie, User ID if valid.
469  */
470 function wp_validate_auth_cookie($cookie = '') {
471         if ( empty($cookie) ) {
472                 if ( empty($_COOKIE[AUTH_COOKIE]) )
473                         return false;
474                 $cookie = $_COOKIE[AUTH_COOKIE];
475         }
476
477         $cookie_elements = explode('|', $cookie);
478         if ( count($cookie_elements) != 3 )
479                 return false;
480
481         list($username, $expiration, $hmac) = $cookie_elements;
482
483         $expired = $expiration;
484
485         // Allow a grace period for POST and AJAX requests
486         if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] )
487                 $expired += 3600;
488
489         // Quick check to see if an honest cookie has expired
490         if ( $expired < time() )
491                 return false;
492
493         $key = wp_hash($username . '|' . $expiration);
494         $hash = hash_hmac('md5', $username . '|' . $expiration, $key);
495
496         if ( $hmac != $hash )
497                 return false;
498
499         $user = get_userdatabylogin($username);
500         if ( ! $user )
501                 return false;
502
503         return $user->ID;
504 }
505 endif;
506
507 if ( !function_exists('wp_generate_auth_cookie') ) :
508 /**
509  * wp_generate_auth_cookie() - Generate authentication cookie contents
510  *
511  * @since 2.5
512  * @uses apply_filters() Calls 'auth_cookie' hook on $cookie contents, User ID
513  *              and expiration of cookie.
514  *
515  * @param int $user_id User ID
516  * @param int $expiration Cookie expiration in seconds
517  * @return string Authentication cookie contents
518  */
519 function wp_generate_auth_cookie($user_id, $expiration) {
520         $user = get_userdata($user_id);
521
522         $key = wp_hash($user->user_login . '|' . $expiration);
523         $hash = hash_hmac('md5', $user->user_login . '|' . $expiration, $key);
524
525         $cookie = $user->user_login . '|' . $expiration . '|' . $hash;
526
527         return apply_filters('auth_cookie', $cookie, $user_id, $expiration);
528 }
529 endif;
530
531 if ( !function_exists('wp_set_auth_cookie') ) :
532 /**
533  * wp_set_auth_cookie() - Sets the authentication cookies based User ID
534  *
535  * The $remember parameter increases the time that the cookie will
536  * be kept. The default the cookie is kept without remembering is
537  * two days. When $remember is set, the cookies will be kept for
538  * 14 days or two weeks.
539  *
540  * @since 2.5
541  *
542  * @param int $user_id User ID
543  * @param bool $remember Whether to remember the user or not
544  */
545 function wp_set_auth_cookie($user_id, $remember = false) {
546         if ( $remember ) {
547                 $expiration = $expire = time() + 1209600;
548         } else {
549                 $expiration = time() + 172800;
550                 $expire = 0;
551         }
552
553         $cookie = wp_generate_auth_cookie($user_id, $expiration);
554
555         do_action('set_auth_cookie', $cookie, $expire);
556
557         setcookie(AUTH_COOKIE, $cookie, $expire, COOKIEPATH, COOKIE_DOMAIN);
558         if ( COOKIEPATH != SITECOOKIEPATH )
559                 setcookie(AUTH_COOKIE, $cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN);
560 }
561 endif;
562
563 if ( !function_exists('wp_clear_auth_cookie') ) :
564 /**
565  * wp_clear_auth_cookie() - Deletes all of the cookies associated with authentication
566  *
567  * @since 2.5
568  */
569 function wp_clear_auth_cookie() {
570         setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
571         setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
572
573         // Old cookies
574         setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
575         setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
576         setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
577         setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
578 }
579 endif;
580
581 if ( !function_exists('is_user_logged_in') ) :
582 /**
583  * is_user_logged_in() - Checks if the current visitor is a logged in user
584  *
585  * @since 2.0.0
586  *
587  * @return bool True if user is logged in, false if not logged in.
588  */
589 function is_user_logged_in() {
590         $user = wp_get_current_user();
591
592         if ( $user->id == 0 )
593                 return false;
594
595         return true;
596 }
597 endif;
598
599 if ( !function_exists('auth_redirect') ) :
600 /**
601  * auth_redirect() - Checks if a user is logged in, if not it redirects them to the login page
602  *
603  * @since 1.5
604  */
605 function auth_redirect() {
606         // Checks if a user is logged in, if not redirects them to the login page
607         if ( (!empty($_COOKIE[AUTH_COOKIE]) &&
608                                 !wp_validate_auth_cookie($_COOKIE[AUTH_COOKIE])) ||
609                         (empty($_COOKIE[AUTH_COOKIE])) ) {
610                 nocache_headers();
611
612                 wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
613                 exit();
614         }
615 }
616 endif;
617
618 if ( !function_exists('check_admin_referer') ) :
619 /**
620  * check_admin_referer() - Makes sure that a user was referred from another admin page, to avoid security exploits
621  *
622  * @since 1.2.0
623  * @uses do_action() Calls 'check_admin_referer' on $action.
624  *
625  * @param string $action Action nonce
626  * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5)
627  */
628 function check_admin_referer($action = -1, $query_arg = '_wpnonce') {
629         $adminurl = strtolower(get_option('siteurl')).'/wp-admin';
630         $referer = strtolower(wp_get_referer());
631         $result = wp_verify_nonce($_REQUEST[$query_arg], $action);
632         if ( !$result && !(-1 == $action && strpos($referer, $adminurl) !== false) ) {
633                 wp_nonce_ays($action);
634                 die();
635         }
636         do_action('check_admin_referer', $action, $result);
637         return $result;
638 }endif;
639
640 if ( !function_exists('check_ajax_referer') ) :
641 /**
642  * check_ajax_referer() - Verifies the AJAX request to prevent processing requests external of the blog.
643  *
644  * @since 2.0.4
645  *
646  * @param string $action Action nonce
647  * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5)
648  */
649 function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
650         if ( $query_arg )
651                 $nonce = $_REQUEST[$query_arg];
652         else
653                 $nonce = $_REQUEST['_ajax_nonce'] ? $_REQUEST['_ajax_nonce'] : $_REQUEST['_wpnonce'];
654
655         $result = wp_verify_nonce( $nonce, $action );
656
657         if ( $die && false == $result )
658                 die('-1');
659
660         do_action('check_ajax_referer', $action, $result);
661
662         return $result;
663 }
664 endif;
665
666 if ( !function_exists('wp_redirect') ) :
667 /**
668  * wp_redirect() - Redirects to another page, with a workaround for the IIS Set-Cookie bug
669  *
670  * @link http://support.microsoft.com/kb/q176113/
671  * @since 1.5.1
672  * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
673  *
674  * @param string $location The path to redirect to
675  * @param int $status Status code to use
676  * @return bool False if $location is not set
677  */
678 function wp_redirect($location, $status = 302) {
679         global $is_IIS;
680
681         $location = apply_filters('wp_redirect', $location, $status);
682         $status = apply_filters('wp_redirect_status', $status, $location);
683         
684         if ( !$location ) // allows the wp_redirect filter to cancel a redirect
685                 return false;
686
687         $location = wp_sanitize_redirect($location);
688
689         if ( $is_IIS ) {
690                 header("Refresh: 0;url=$location");
691         } else {
692                 if ( php_sapi_name() != 'cgi-fcgi' )
693                         status_header($status); // This causes problems on IIS and some FastCGI setups
694                 header("Location: $location");
695         }
696 }
697 endif;
698
699 if ( !function_exists('wp_sanitize_redirect') ) :
700 /**
701  * wp_sanitize_redirect() - Sanitizes a URL for use in a redirect
702  *
703  * @since 2.3
704  *
705  * @return string redirect-sanitized URL
706  **/
707 function wp_sanitize_redirect($location) {
708         $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
709         $location = wp_kses_no_null($location);
710
711         // remove %0d and %0a from location
712         $strip = array('%0d', '%0a');
713         $found = true;
714         while($found) {
715                 $found = false;
716                 foreach($strip as $val) {
717                         while(strpos($location, $val) !== false) {
718                                 $found = true;
719                                 $location = str_replace($val, '', $location);
720                         }
721                 }
722         }
723         return $location;
724 }
725 endif;
726
727 if ( !function_exists('wp_safe_redirect') ) :
728 /**
729  * wp_safe_redirect() - Performs a safe (local) redirect, using wp_redirect()
730  *
731  * Checks whether the $location is using an allowed host, if it has an absolute
732  * path. A plugin can therefore set or remove allowed host(s) to or from the list.
733  *
734  * If the host is not allowed, then the redirect is to wp-admin on the siteurl
735  * instead. This prevents malicious redirects which redirect to another host, but
736  * only used in a few places.
737  *
738  * @since 2.3
739  * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
740  *              WordPress host string and $location host string.
741  *
742  * @return void Does not return anything
743  **/
744 function wp_safe_redirect($location, $status = 302) {
745
746         // Need to look at the URL the way it will end up in wp_redirect()
747         $location = wp_sanitize_redirect($location);
748
749         // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
750         if ( substr($location, 0, 2) == '//' )
751                 $location = 'http:' . $location;
752
753         $lp  = parse_url($location);
754         $wpp = parse_url(get_option('home'));
755
756         $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
757
758         if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
759                 $location = get_option('siteurl') . '/wp-admin/';
760
761         wp_redirect($location, $status);
762 }
763 endif;
764
765 if ( ! function_exists('wp_notify_postauthor') ) :
766 /**
767  * wp_notify_postauthor() - Notify an author of a comment/trackback/pingback to one of their posts
768  *
769  * @since 1.0.0
770  *
771  * @param int $comment_id Comment ID
772  * @param string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback'
773  * @return bool False if user email does not exist. True on completion.
774  */
775 function wp_notify_postauthor($comment_id, $comment_type='') {
776         $comment = get_comment($comment_id);
777         $post    = get_post($comment->comment_post_ID);
778         $user    = get_userdata( $post->post_author );
779
780         if ('' == $user->user_email) return false; // If there's no email to send the comment to
781
782         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
783
784         $blogname = get_option('blogname');
785
786         if ( empty( $comment_type ) ) $comment_type = 'comment';
787
788         if ('comment' == $comment_type) {
789                 $notify_message  = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
790                 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
791                 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
792                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
793                 $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
794                 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
795                 $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
796                 $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
797         } elseif ('trackback' == $comment_type) {
798                 $notify_message  = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
799                 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
800                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
801                 $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
802                 $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
803                 $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
804         } elseif ('pingback' == $comment_type) {
805                 $notify_message  = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
806                 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
807                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
808                 $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
809                 $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
810                 $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
811         }
812         $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
813         $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
814         $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
815
816         $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
817
818         if ( '' == $comment->comment_author ) {
819                 $from = "From: \"$blogname\" <$wp_email>";
820                 if ( '' != $comment->comment_author_email )
821                         $reply_to = "Reply-To: $comment->comment_author_email";
822         } else {
823                 $from = "From: \"$comment->comment_author\" <$wp_email>";
824                 if ( '' != $comment->comment_author_email )
825                         $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
826         }
827
828         $message_headers = "$from\n"
829                 . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
830
831         if ( isset($reply_to) )
832                 $message_headers .= $reply_to . "\n";
833
834         $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
835         $subject = apply_filters('comment_notification_subject', $subject, $comment_id);
836         $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
837
838         @wp_mail($user->user_email, $subject, $notify_message, $message_headers);
839
840         return true;
841 }
842 endif;
843
844 if ( !function_exists('wp_notify_moderator') ) :
845 /**
846  * wp_notify_moderator() - Notifies the moderator of the blog about a new comment that is awaiting approval
847  *
848  * @since 1.0
849  * @uses $wpdb
850  *
851  * @param int $comment_id Comment ID
852  * @return bool Always returns true
853  */
854 function wp_notify_moderator($comment_id) {
855         global $wpdb;
856
857         if( get_option( "moderation_notify" ) == 0 )
858                 return true;
859
860         $comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID=%d LIMIT 1", $comment_id));
861         $post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID=%d LIMIT 1", $comment->comment_post_ID));
862
863         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
864         $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
865
866         switch ($comment->comment_type)
867         {
868                 case 'trackback':
869                         $notify_message  = sprintf( __('A new trackback on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n";
870                         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
871                         $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
872                         $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
873                         $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
874                         break;
875                 case 'pingback':
876                         $notify_message  = sprintf( __('A new pingback on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n";
877                         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
878                         $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
879                         $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
880                         $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
881                         break;
882                 default: //Comments
883                         $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";
884                         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
885                         $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
886                         $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
887                         $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
888                         $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
889                         $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
890                         break;
891         }
892
893         $notify_message .= sprintf( __('Approve it: %s'),  get_option('siteurl')."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "\r\n";
894         $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
895         $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
896
897         $strCommentsPending = sprintf( __ngettext('%s comment', '%s comments', $comments_waiting), $comments_waiting );
898         $notify_message .= sprintf( __('Currently %s are waiting for approval. Please visit the moderation panel:'), $strCommentsPending ) . "\r\n";
899         $notify_message .= get_option('siteurl') . "/wp-admin/edit-comments.php?comment_status=moderated\r\n";
900
901         $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_option('blogname'), $post->post_title );
902         $admin_email = get_option('admin_email');
903
904         $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
905         $subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
906
907         @wp_mail($admin_email, $subject, $notify_message);
908
909         return true;
910 }
911 endif;
912
913 if ( !function_exists('wp_new_user_notification') ) :
914 /**
915  * wp_new_user_notification() - Notify the blog admin of a new user, normally via email
916  *
917  * @since 2.0
918  *
919  * @param int $user_id User ID
920  * @param string $plaintext_pass Optional. The user's plaintext password
921  */
922 function wp_new_user_notification($user_id, $plaintext_pass = '') {
923         $user = new WP_User($user_id);
924
925         $user_login = stripslashes($user->user_login);
926         $user_email = stripslashes($user->user_email);
927
928         $message  = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n";
929         $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
930         $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
931
932         @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
933
934         if ( empty($plaintext_pass) )
935                 return;
936
937         $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
938         $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
939         $message .= get_option('siteurl') . "/wp-login.php\r\n";
940
941         wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
942
943 }
944 endif;
945
946 if ( !function_exists('wp_nonce_tick') ) :
947 /**
948  * wp_nonce_tick() - Get the time-dependent variable for nonce creation
949  *
950  * A nonce has a lifespan of two ticks. Nonces in their second tick may be updated, e.g. by autosave.
951  *
952  * @since 2.5
953  *
954  * @return int
955  */
956 function wp_nonce_tick() {
957         $nonce_life = apply_filters('nonce_life', 86400);
958
959         return ceil(time() / ( $nonce_life / 2 ));
960 }
961 endif;
962
963 if ( !function_exists('wp_verify_nonce') ) :
964 /**
965  * wp_verify_nonce() - Verify that correct nonce was used with time limit
966  *
967  * The user is given an amount of time to use the token, so therefore, since
968  * the UID and $action remain the same, the independent variable is the time.
969  *
970  * @since 2.0.4
971  *
972  * @param string $nonce Nonce that was used in the form to verify
973  * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
974  * @return bool Whether the nonce check passed or failed.
975  */
976 function wp_verify_nonce($nonce, $action = -1) {
977         $user = wp_get_current_user();
978         $uid = (int) $user->id;
979
980         $i = wp_nonce_tick();
981
982         // Nonce generated 0-12 hours ago
983         if ( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce )
984                 return 1;
985         // Nonce generated 12-24 hours ago
986         if ( substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce )
987                 return 2;
988         // Invalid nonce
989         return false;
990 }
991 endif;
992
993 if ( !function_exists('wp_create_nonce') ) :
994 /**
995  * wp_create_nonce() - Creates a random, one time use token
996  *
997  * @since 2.0.4
998  *
999  * @param string|int $action Scalar value to add context to the nonce.
1000  * @return string The one use form token
1001  */
1002 function wp_create_nonce($action = -1) {
1003         $user = wp_get_current_user();
1004         $uid = (int) $user->id;
1005
1006         $i = wp_nonce_tick();
1007
1008         return substr(wp_hash($i . $action . $uid), -12, 10);
1009 }
1010 endif;
1011
1012 if ( !function_exists('wp_salt') ) :
1013 /**
1014  * wp_salt() - Get salt to add to hashes to help prevent attacks
1015  *
1016  * You can set the salt by defining two areas. One is in the database and
1017  * the other is in your wp-config.php file. The database location is defined
1018  * in the option named 'secret', but most likely will not need to be changed.
1019  *
1020  * The second, located in wp-config.php, is a constant named 'SECRET_KEY', but
1021  * is not required. If the constant is not defined then the database constants
1022  * will be used, since they are most likely given to be unique. However, given
1023  * that the salt will be added to the password and can be seen, the constant
1024  * is recommended to be set manually.
1025  *
1026  * <code>
1027  * define('SECRET_KEY', 'mAry1HadA15|\/|b17w55w1t3asSn09w');
1028  * </code>
1029  *
1030  * Attention: Do not use above example!
1031  *
1032  * Salting passwords helps against tools which has stored hashed values
1033  * of common dictionary strings. The added values makes it harder to crack
1034  * if given salt string is not weak.
1035  *
1036  * Salting only helps if the string is not predictable and should be
1037  * made up of various characters. Think of the salt as a password for
1038  * securing your passwords, but common among all of your passwords.
1039  * Therefore the salt should be as long as possible as as difficult as
1040  * possible, because you will not have to remember it.
1041  *
1042  * @since 2.5
1043  *
1044  * @return string Salt value from either 'SECRET_KEY' or 'secret' option
1045  */
1046 function wp_salt() {
1047         global $wp_default_secret_key;
1048         $secret_key = '';
1049         if ( defined('SECRET_KEY') && ('' != SECRET_KEY) && ( $wp_default_secret_key != SECRET_KEY) )
1050                 $secret_key = SECRET_KEY;
1051
1052         if ( defined('SECRET_SALT') ) {
1053                 $salt = SECRET_SALT;
1054         } else {
1055                 $salt = get_option('secret');
1056                 if ( empty($salt) ) {
1057                         $salt = wp_generate_password();
1058                         update_option('secret', $salt);
1059                 }
1060         }
1061
1062         return apply_filters('salt', $secret_key . $salt);
1063 }
1064 endif;
1065
1066 if ( !function_exists('wp_hash') ) :
1067 /**
1068  * wp_hash() - Get hash of given string
1069  *
1070  * @since 2.0.4
1071  * @uses wp_salt() Get WordPress salt
1072  *
1073  * @param string $data Plain text to hash
1074  * @return string Hash of $data
1075  */
1076 function wp_hash($data) {
1077         $salt = wp_salt();
1078
1079         return hash_hmac('md5', $data, $salt);
1080 }
1081 endif;
1082
1083 if ( !function_exists('wp_hash_password') ) :
1084 /**
1085  * wp_hash_password() - Create a hash (encrypt) of a plain text password
1086  *
1087  * For integration with other applications, this function can be
1088  * overwritten to instead use the other package password checking
1089  * algorithm.
1090  *
1091  * @since 2.5
1092  * @global object $wp_hasher PHPass object
1093  * @uses PasswordHash::HashPassword
1094  *
1095  * @param string $password Plain text user password to hash
1096  * @return string The hash string of the password
1097  */
1098 function wp_hash_password($password) {
1099         global $wp_hasher;
1100
1101         if ( empty($wp_hasher) ) {
1102                 require_once( ABSPATH . 'wp-includes/class-phpass.php');
1103                 // By default, use the portable hash from phpass
1104                 $wp_hasher = new PasswordHash(8, TRUE);
1105         }
1106
1107         return $wp_hasher->HashPassword($password);
1108 }
1109 endif;
1110
1111 if ( !function_exists('wp_check_password') ) :
1112 /**
1113  * wp_check_password() - Checks the plaintext password against the encrypted Password
1114  *
1115  * Maintains compatibility between old version and the new cookie
1116  * authentication protocol using PHPass library. The $hash parameter
1117  * is the encrypted password and the function compares the plain text
1118  * password when encypted similarly against the already encrypted
1119  * password to see if they match.
1120  *
1121  * For integration with other applications, this function can be
1122  * overwritten to instead use the other package password checking
1123  * algorithm.
1124  *
1125  * @since 2.5
1126  * @global object $wp_hasher PHPass object used for checking the password
1127  *      against the $hash + $password
1128  * @uses PasswordHash::CheckPassword
1129  *
1130  * @param string $password Plaintext user's password
1131  * @param string $hash Hash of the user's password to check against.
1132  * @return bool False, if the $password does not match the hashed password
1133  */
1134 function wp_check_password($password, $hash, $user_id = '') {
1135         global $wp_hasher;
1136
1137         // If the hash is still md5...
1138         if ( strlen($hash) <= 32 ) {
1139                 $check = ( $hash == md5($password) );
1140                 if ( $check && $user_id ) {
1141                         // Rehash using new hash.
1142                         wp_set_password($password, $user_id);
1143                         $hash = wp_hash_password($password);
1144                 }
1145
1146                 return apply_filters('check_password', $check, $password, $hash, $user_id);
1147         }
1148
1149         // If the stored hash is longer than an MD5, presume the
1150         // new style phpass portable hash.
1151         if ( empty($wp_hasher) ) {
1152                 require_once( ABSPATH . 'wp-includes/class-phpass.php');
1153                 // By default, use the portable hash from phpass
1154                 $wp_hasher = new PasswordHash(8, TRUE);
1155         }
1156
1157         $check = $wp_hasher->CheckPassword($password, $hash);
1158
1159         return apply_filters('check_password', $check, $password, $hash, $user_id);
1160 }
1161 endif;
1162
1163 if ( !function_exists('wp_generate_password') ) :
1164 /**
1165  * wp_generate_password() - Generates a random password drawn from the defined set of characters
1166  *
1167  * @since 2.5
1168  *
1169  * @return string The random password
1170  **/
1171 function wp_generate_password($length = 12) {
1172         $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()";
1173         $password = '';
1174         for ( $i = 0; $i < $length; $i++ )
1175                 $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
1176         return $password;
1177 }
1178 endif;
1179
1180 if ( !function_exists('wp_set_password') ) :
1181 /**
1182  * wp_set_password() - Updates the user's password with a new encrypted one
1183  *
1184  * For integration with other applications, this function can be
1185  * overwritten to instead use the other package password checking
1186  * algorithm.
1187  *
1188  * @since 2.5
1189  * @uses $wpdb WordPress database object for queries
1190  * @uses wp_hash_password() Used to encrypt the user's password before passing to the database
1191  *
1192  * @param string $password The plaintext new user password
1193  * @param int $user_id User ID
1194  */
1195 function wp_set_password( $password, $user_id ) {
1196         global $wpdb;
1197
1198         $hash = wp_hash_password($password);
1199         $query = $wpdb->prepare("UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $hash, $user_id);
1200         $wpdb->query($query);
1201         wp_cache_delete($user_id, 'users');
1202 }
1203 endif;
1204
1205 if ( !function_exists( 'get_avatar' ) ) :
1206 /**
1207  * get_avatar() - Get avatar for a user
1208  *
1209  * Retrieve the avatar for a user provided a user ID or email address
1210  *
1211  * @since 2.5
1212  * @param int|string|object $id_or_email A user ID,  email address, or comment object
1213  * @param int $size Size of the avatar image
1214  * @param string $default URL to a default image to use if no avatar is available
1215  * @return string <img> tag for the user's avatar
1216 */
1217 function get_avatar( $id_or_email, $size = '96', $default = '' ) {
1218         if ( ! get_option('show_avatars') )
1219                 return false;
1220
1221         if ( !is_numeric($size) )
1222                 $size = '96';
1223
1224         $email = '';
1225         if ( is_numeric($id_or_email) ) {
1226                 $id = (int) $id_or_email;
1227                 $user = get_userdata($id);
1228                 if ( $user )
1229                         $email = $user->user_email;
1230         } elseif ( is_object($id_or_email) ) {
1231                 if ( !empty($id_or_email->user_id) ) {
1232                         $id = (int) $id_or_email->user_id;
1233                         $user = get_userdata($id);
1234                         if ( $user)
1235                                 $email = $user->user_email;
1236                 } elseif ( !empty($id_or_email->comment_author_email) ) {
1237                         $email = $id_or_email->comment_author_email;
1238                 }
1239         } else {
1240                 $email = $id_or_email;
1241         }
1242
1243         if ( empty($default) )
1244                 $default = "http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=$size"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
1245
1246         if ( !empty($email) ) {
1247                 $out = 'http://www.gravatar.com/avatar/';
1248                 $out .= md5( strtolower( $email ) );
1249                 $out .= '?s='.$size;
1250                 $out .= '&amp;d=' . urlencode( $default );
1251
1252                 $rating = get_option('avatar_rating');
1253                 if ( !empty( $rating ) )
1254                         $out .= "&amp;r={$rating}";
1255
1256                 $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />";
1257         } else {
1258                 $avatar = "<img alt='' src='{$default}' class='avatar avatar-{$size} avatar-default' height='{$size}' width='{$size}' />";
1259         }
1260
1261         return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default);
1262 }
1263 endif;
1264
1265 if ( !function_exists('wp_setcookie') ) :
1266 /**
1267  * wp_setcookie() - Sets a cookie for a user who just logged in
1268  *
1269  * @since 1.5
1270  * @deprecated Use wp_set_auth_cookie()
1271  * @see wp_set_auth_cookie()
1272  *
1273  * @param string  $username The user's username
1274  * @param string  $password Optional. The user's password
1275  * @param bool $already_md5 Optional. Whether the password has already been through MD5
1276  * @param string $home Optional. Will be used instead of COOKIEPATH if set
1277  * @param string $siteurl Optional. Will be used instead of SITECOOKIEPATH if set
1278  * @param bool $remember Optional. Remember that the user is logged in
1279  */
1280 function wp_setcookie($username, $password = '', $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
1281         _deprecated_function( __FUNCTION__, '2.5', 'wp_set_auth_cookie()' );
1282         $user = get_userdatabylogin($username);
1283         wp_set_auth_cookie($user->ID, $remember);
1284 }
1285 endif;
1286
1287 if ( !function_exists('wp_clearcookie') ) :
1288 /**
1289  * wp_clearcookie() - Clears the authentication cookie, logging the user out
1290  *
1291  * @since 1.5
1292  * @deprecated Use wp_clear_auth_cookie()
1293  * @see wp_clear_auth_cookie()
1294  */
1295 function wp_clearcookie() {
1296         _deprecated_function( __FUNCTION__, '2.5', 'wp_clear_auth_cookie()' );
1297         wp_clear_auth_cookie();
1298 }
1299 endif;
1300
1301 if ( !function_exists('wp_get_cookie_login') ):
1302 /**
1303  * wp_get_cookie_login() - Gets the user cookie login
1304  *
1305  * This function is deprecated and should no longer be extended as it won't
1306  * be used anywhere in WordPress. Also, plugins shouldn't use it either.
1307  *
1308  * @since 2.0.4
1309  * @deprecated No alternative
1310  *
1311  * @return bool Always returns false
1312  */
1313 function wp_get_cookie_login() {
1314         _deprecated_function( __FUNCTION__, '2.5', '' );
1315         return false;
1316 }
1317 endif;
1318
1319 if ( !function_exists('wp_login') ) :
1320 /**
1321  * wp_login() - Checks a users login information and logs them in if it checks out
1322  *
1323  * Use the global $error to get the reason why the login failed.
1324  * If the username is blank, no error will be set, so assume
1325  * blank username on that case.
1326  *
1327  * Plugins extending this function should also provide the global
1328  * $error and set what the error is, so that those checking the
1329  * global for why there was a failure can utilize it later.
1330  *
1331  * @since 1.2.2
1332  * @deprecated Use wp_signon()
1333  * @global string $error Error when false is returned
1334  *
1335  * @param string $username User's username
1336  * @param string $password User's password
1337  * @param bool $deprecated Not used
1338  * @return bool False on login failure, true on successful check
1339  */
1340 function wp_login($username, $password, $deprecated = '') {
1341         global $error;
1342
1343         $user = wp_authenticate($username, $password);
1344
1345         if ( ! is_wp_error($user) )
1346                 return true;
1347
1348         $error = $user->get_error_message();
1349         return false;
1350 }
1351 endif;
1352
1353 ?>