if ( ! empty($current_user) )
return;
- if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ||
+ if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ||
!wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) {
wp_set_current_user(0);
return false;
return false;
$user = wp_cache_get($user_id, 'users');
-
+
if ( $user )
return $user;
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id' LIMIT 1") )
return false;
- $wpdb->hide_errors();
+ $show = $wpdb->hide_errors();
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
- $wpdb->show_errors();
+ $wpdb->show_errors($show);
if ($metavalues) {
foreach ( $metavalues as $meta ) {
$user->user_lastname = $user->last_name;
if ( isset($user->description) )
$user->user_description = $user->description;
-
+
wp_cache_add($user_id, $user, 'users');
- wp_cache_add($user->user_login, $user, 'userlogins');
-
+ wp_cache_add($user->user_login, $user_id, 'userlogins');
return $user;
}
endif;
if ( empty( $user_login ) )
return false;
-
- $userdata = wp_cache_get($user_login, 'userlogins');
+
+ $user_id = wp_cache_get($user_login, 'userlogins');
+ $userdata = wp_cache_get($user_id, 'users');
+
if ( $userdata )
return $userdata;
$user_login = $wpdb->escape($user_login);
- if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") )
+ if ( !$user_ID = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'") )
return false;
- $wpdb->hide_errors();
- $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
- $wpdb->show_errors();
+ $user = get_userdata($user_ID);
+ return $user;
+}
+endif;
- if ($metavalues) {
- foreach ( $metavalues as $meta ) {
- $value = maybe_unserialize($meta->meta_value);
- $user->{$meta->meta_key} = $value;
+if ( !function_exists( 'wp_mail' ) ) :
+function wp_mail( $to, $subject, $message, $headers = '' ) {
+ // Compact the input, apply the filters, and extract them back out
+ extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) );
- // We need to set user_level from meta, not row
- if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
- $user->user_level = $meta->meta_value;
+ global $phpmailer;
+
+ // (Re)create it, if it's gone missing
+ if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
+ require_once ABSPATH . WPINC . '/class-phpmailer.php';
+ require_once ABSPATH . WPINC . '/class-smtp.php';
+ $phpmailer = new PHPMailer();
+ }
+
+ // Headers
+ if ( empty( $headers ) ) {
+ $headers = array();
+ } elseif ( !is_array( $headers ) ) {
+ // Explode the headers out, so this function can take both
+ // string headers and an array of headers.
+ $tempheaders = (array) explode( "\n", $headers );
+ $headers = array();
+
+ // If it's actually got contents
+ if ( !empty( $tempheaders ) ) {
+ // Iterate through the raw headers
+ foreach ( $tempheaders as $header ) {
+ if ( strpos($header, ':') === false )
+ continue;
+ // Explode them out
+ list( $name, $content ) = explode( ':', trim( $header ), 2 );
+
+ // Cleanup crew
+ $name = trim( $name );
+ $content = trim( $content );
+
+ // Mainly for legacy -- process a From: header if it's there
+ if ( 'from' == strtolower($name) ) {
+ if ( strpos($content, '<' ) !== false ) {
+ // So... making my life hard again?
+ $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
+ $from_name = str_replace( '"', '', $from_name );
+ $from_name = trim( $from_name );
+
+ $from_email = substr( $content, strpos( $content, '<' ) + 1 );
+ $from_email = str_replace( '>', '', $from_email );
+ $from_email = trim( $from_email );
+ } else {
+ $from_name = trim( $content );
+ }
+ } elseif ( 'content-type' == strtolower($name) ) {
+ if ( strpos( $content,';' ) !== false ) {
+ list( $type, $charset ) = explode( ';', $content );
+ $content_type = trim( $type );
+ $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
+ } else {
+ $content_type = trim( $content );
+ }
+ } else {
+ // Add it to our grand headers array
+ $headers[trim( $name )] = trim( $content );
+ }
+ }
}
}
- // For backwards compat.
- if ( isset($user->first_name) )
- $user->user_firstname = $user->first_name;
- if ( isset($user->last_name) )
- $user->user_lastname = $user->last_name;
- if ( isset($user->description) )
- $user->user_description = $user->description;
+ // Empty out the values that may be set
+ $phpmailer->ClearAddresses();
+ $phpmailer->ClearAllRecipients();
+ $phpmailer->ClearAttachments();
+ $phpmailer->ClearBCCs();
+ $phpmailer->ClearCCs();
+ $phpmailer->ClearCustomHeaders();
+ $phpmailer->ClearReplyTos();
+
+ // From email and name
+ // If we don't have a name from the input headers
+ if ( !isset( $from_name ) ) {
+ $from_name = 'WordPress';
+ }
- wp_cache_add($user->ID, $user, 'users');
- wp_cache_add($user->user_login, $user, 'userlogins');
+ // If we don't have an email from the input headers
+ if ( !isset( $from_email ) ) {
+ // Get the site domain and get rid of www.
+ $sitename = strtolower( $_SERVER['SERVER_NAME'] );
+ if ( substr( $sitename, 0, 4 ) == 'www.' ) {
+ $sitename = substr( $sitename, 4 );
+ }
- return $user;
+ $from_email = 'wordpress@' . $sitename;
+ }
-}
-endif;
+ // Set the from name and email
+ $phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
+ $phpmailer->Sender = apply_filters( 'wp_mail_from', $from_email );
+ $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
+
+ // Set destination address
+ $phpmailer->AddAddress( $to );
+
+ // Set mail's subject and body
+ $phpmailer->Subject = $subject;
+ $phpmailer->Body = $message;
+
+ // Set to use PHP's mail()
+ $phpmailer->IsMail();
+
+ // Set Content-Type and charset
+ // If we don't have a content-type from the input headers
+ if ( !isset( $content_type ) ) {
+ $content_type = 'text/plain';
+ }
+
+ $content_type = apply_filters( 'wp_mail_content_type', $content_type );
+
+ // Set whether it's plaintext or not, depending on $content_type
+ if ( $content_type == 'text/html' ) {
+ $phpmailer->IsHTML( true );
+ } else {
+ $phpmailer->IsHTML( false );
+ }
-if ( !function_exists('wp_mail') ) :
-function wp_mail($to, $subject, $message, $headers = '') {
- if( $headers == '' ) {
- $headers = "MIME-Version: 1.0\n" .
- "From: wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n" .
- "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
+ // If we don't have a charset from the input headers
+ if ( !isset( $charset ) ) {
+ $charset = get_bloginfo( 'charset' );
}
- return @mail($to, $subject, $message, $headers);
+ // Set the content-type and charset
+ $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
+
+ // Set custom headers
+ if ( !empty( $headers ) ) {
+ foreach ( $headers as $name => $content ) {
+ $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
+ }
+ }
+
+ do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
+
+ // Send!
+ $result = @$phpmailer->Send();
+
+ return $result;
}
endif;
function wp_login($username, $password, $already_md5 = false) {
global $wpdb, $error;
+ $username = sanitize_user($username);
+
if ( '' == $username )
return false;
if ( '' == $password ) {
- $error = __('<strong>Error</strong>: The password field is empty.');
+ $error = __('<strong>ERROR</strong>: The password field is empty.');
return false;
}
//$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
if (!$login) {
- $error = __('<strong>Error</strong>: Wrong username.');
+ $error = __('<strong>ERROR</strong>: Invalid username.');
return false;
} else {
// If the password is already_md5, it has been double hashed.
if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) {
return true;
} else {
- $error = __('<strong>Error</strong>: Incorrect password.');
+ $error = __('<strong>ERROR</strong>: Incorrect password.');
$pwd = '';
return false;
}
if ( !function_exists('is_user_logged_in') ) :
function is_user_logged_in() {
$user = wp_get_current_user();
-
+
if ( $user->id == 0 )
return false;
if ( !function_exists('auth_redirect') ) :
function auth_redirect() {
// Checks if a user is logged in, if not redirects them to the login page
- if ( (!empty($_COOKIE[USER_COOKIE]) &&
+ if ( (!empty($_COOKIE[USER_COOKIE]) &&
!wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) ||
(empty($_COOKIE[USER_COOKIE])) ) {
nocache_headers();
-
- wp_redirect(get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
+
+ wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
exit();
}
}
if ( !function_exists('check_admin_referer') ) :
function check_admin_referer($action = -1) {
- $adminurl = strtolower(get_settings('siteurl')).'/wp-admin';
+ $adminurl = strtolower(get_option('siteurl')).'/wp-admin';
$referer = strtolower(wp_get_referer());
if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) &&
- !(-1 == $action && strstr($referer, $adminurl)) ) {
+ !(-1 == $action && strpos($referer, $adminurl) !== false)) {
wp_nonce_ays($action);
die();
}
do_action('check_admin_referer', $action);
-}
-endif;
+}endif;
if ( !function_exists('check_ajax_referer') ) :
function check_ajax_referer() {
+ $current_name = '';
+ if ( ( $current = wp_get_current_user() ) && $current->ID )
+ $current_name = $current->data->user_login;
+ if ( !$current_name )
+ die('-1');
+
$cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie
foreach ( $cookie as $tasty ) {
if ( false !== strpos($tasty, USER_COOKIE) )
- $user = urldecode(substr(strstr($tasty, '='), 1)); // Nasty double encoding
+ $user = substr(strstr($tasty, '='), 1);
if ( false !== strpos($tasty, PASS_COOKIE) )
- $pass = urldecode(substr(strstr($tasty, '='), 1));
+ $pass = substr(strstr($tasty, '='), 1);
}
- if ( wp_login( $user, $pass, true ) )
- return true;
- return false;
+
+ if ( $current_name != $user || !wp_login( $user, $pass, true ) )
+ die('-1');
+ do_action('check_ajax_referer');
}
endif;
function wp_redirect($location, $status = 302) {
global $is_IIS;
- $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
+ $location = apply_filters('wp_redirect', $location, $status);
- $strip = array('%0d', '%0a');
- $location = str_replace($strip, '', $location);
+ if ( !$location ) // allows the wp_redirect filter to cancel a redirect
+ return false;
+
+ $location = wp_sanitize_redirect($location);
if ( $is_IIS ) {
header("Refresh: 0;url=$location");
}
endif;
+if ( !function_exists('wp_sanitize_redirect') ) :
+/**
+ * sanitizes a URL for use in a redirect
+ * @return string redirect-sanitized URL
+ **/
+function wp_sanitize_redirect($location) {
+ $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
+ $location = wp_kses_no_null($location);
+
+ // remove %0d and %0a from location
+ $strip = array('%0d', '%0a');
+ $found = true;
+ while($found) {
+ $found = false;
+ foreach($strip as $val) {
+ while(strpos($location, $val) !== false) {
+ $found = true;
+ $location = str_replace($val, '', $location);
+ }
+ }
+ }
+ return $location;
+}
+endif;
+
+if ( !function_exists('wp_safe_redirect') ) :
+/**
+ * performs a safe (local) redirect, using wp_redirect()
+ * @return void
+ **/
+function wp_safe_redirect($location, $status = 302) {
+
+ // Need to look at the URL the way it will end up in wp_redirect()
+ $location = wp_sanitize_redirect($location);
+
+ // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
+ if ( substr($location, 0, 2) == '//' )
+ $location = 'http:' . $location;
+
+ $lp = parse_url($location);
+ $wpp = parse_url(get_option('home'));
+
+ $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), $lp['host']);
+
+ if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
+ $location = get_option('siteurl') . '/wp-admin/';
+
+ wp_redirect($location, $status);
+}
+endif;
+
if ( !function_exists('wp_get_cookie_login') ):
function wp_get_cookie_login() {
if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) )
if ( ! function_exists('wp_notify_postauthor') ) :
function wp_notify_postauthor($comment_id, $comment_type='') {
global $wpdb;
-
+
$comment = get_comment($comment_id);
$post = get_post($comment->comment_post_ID);
$user = get_userdata( $post->post_author );
$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
- $blogname = get_settings('blogname');
-
+ $blogname = get_option('blogname');
+
if ( empty( $comment_type ) ) $comment_type = 'comment';
-
+
if ('comment' == $comment_type) {
$notify_message = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
- $notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
+ $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
$notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
$notify_message .= __('You can see all comments on this post here: ') . "\r\n";
} elseif ('trackback' == $comment_type) {
$notify_message = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
$notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
- $notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
+ $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
$notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
$notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
$subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
} elseif ('pingback' == $comment_type) {
$notify_message = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
$notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
- $notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
+ $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
$notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
$notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
$subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
}
$notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
- $notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/post.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
+ $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
+ $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
$wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$from = "From: \"$blogname\" <$wp_email>";
if ( '' != $comment->comment_author_email )
$reply_to = "Reply-To: $comment->comment_author_email";
- } else {
+ } else {
$from = "From: \"$comment->comment_author\" <$wp_email>";
if ( '' != $comment->comment_author_email )
$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
- }
+ }
- $message_headers = "MIME-Version: 1.0\n"
- . "$from\n"
- . "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
+ $message_headers = "$from\n"
+ . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
if ( isset($reply_to) )
$message_headers .= $reply_to . "\n";
$message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
@wp_mail($user->user_email, $subject, $notify_message, $message_headers);
-
+
return true;
}
endif;
function wp_notify_moderator($comment_id) {
global $wpdb;
- if( get_settings( "moderation_notify" ) == 0 )
- return true;
-
+ if( get_option( "moderation_notify" ) == 0 )
+ return true;
+
$comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
$notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
- $notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
+ $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
$notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
- $notify_message .= sprintf( __('To approve this comment, visit: %s'), get_settings('siteurl').'/wp-admin/post.php?action=mailapprovecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
- $notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/post.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
+ $notify_message .= sprintf( __('Approve it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "\r\n";
+ $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
+ $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
$notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n";
- $notify_message .= get_settings('siteurl') . "/wp-admin/moderation.php\r\n";
+ $notify_message .= get_option('siteurl') . "/wp-admin/moderation.php\r\n";
- $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_settings('blogname'), $post->post_title );
- $admin_email = get_settings('admin_email');
+ $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_option('blogname'), $post->post_title );
+ $admin_email = get_option('admin_email');
$notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
$subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
@wp_mail($admin_email, $subject, $notify_message);
-
+
return true;
}
endif;
if ( !function_exists('wp_new_user_notification') ) :
function wp_new_user_notification($user_id, $plaintext_pass = '') {
$user = new WP_User($user_id);
-
+
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
-
- $message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
+
+ $message = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
-
- @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
+
+ @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
if ( empty($plaintext_pass) )
return;
$message = sprintf(__('Username: %s'), $user_login) . "\r\n";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
- $message .= get_settings('siteurl') . "/wp-login.php\r\n";
-
- wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
-
+ $message .= get_option('siteurl') . "/wp-login.php\r\n";
+
+ wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
+
}
endif;
$uid = (int) $user->id;
$i = ceil(time() / 43200);
-
+
return substr(wp_hash($i . $action . $uid), -12, 10);
}
endif;
}
endif;
-?>
\ No newline at end of file
+?>