2005-04-20 05:37:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/* These functions can be replaced via plugins. They are loaded after
|
|
|
|
plugins are loaded. */
|
|
|
|
|
2006-01-13 20:19:09 +01:00
|
|
|
if ( !function_exists('set_current_user') ) :
|
|
|
|
function set_current_user($id, $name = '') {
|
2006-02-22 20:08:55 +01:00
|
|
|
return wp_set_current_user($id, $name);
|
|
|
|
}
|
|
|
|
endif;
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-02-22 20:08:55 +01:00
|
|
|
if ( !function_exists('wp_set_current_user') ) :
|
|
|
|
function wp_set_current_user($id, $name = '') {
|
|
|
|
global $current_user;
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-02-22 20:08:55 +01:00
|
|
|
if ( isset($current_user) && ($id == $current_user->ID) )
|
|
|
|
return $current_user;
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-02-22 20:08:55 +01:00
|
|
|
$current_user = new WP_User($id, $name);
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-02-22 20:08:55 +01:00
|
|
|
setup_userdata($current_user->ID);
|
2006-01-13 20:19:09 +01:00
|
|
|
|
|
|
|
do_action('set_current_user');
|
|
|
|
|
|
|
|
return $current_user;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-05-31 08:27:10 +02:00
|
|
|
if ( !function_exists('wp_get_current_user') ) :
|
2006-02-22 20:08:55 +01:00
|
|
|
function wp_get_current_user() {
|
|
|
|
global $current_user;
|
|
|
|
|
|
|
|
get_currentuserinfo();
|
|
|
|
|
|
|
|
return $current_user;
|
|
|
|
}
|
|
|
|
endif;
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
if ( !function_exists('get_currentuserinfo') ) :
|
|
|
|
function get_currentuserinfo() {
|
2006-02-22 20:08:55 +01:00
|
|
|
global $current_user;
|
2005-06-13 02:05:41 +02:00
|
|
|
|
2006-01-13 20:19:09 +01:00
|
|
|
if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
|
|
|
return false;
|
|
|
|
|
2006-02-22 20:08:55 +01:00
|
|
|
if ( ! empty($current_user) )
|
|
|
|
return;
|
|
|
|
|
2007-12-16 18:41:59 +01:00
|
|
|
if ( ! $user = wp_validate_auth_cookie() ) {
|
2006-02-22 20:08:55 +01:00
|
|
|
wp_set_current_user(0);
|
2005-06-13 02:05:41 +02:00
|
|
|
return false;
|
2005-12-13 04:46:40 +01:00
|
|
|
}
|
2006-02-22 20:08:55 +01:00
|
|
|
|
2007-12-16 18:41:59 +01:00
|
|
|
wp_set_current_user($user);
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('get_userdata') ) :
|
2005-06-12 22:49:13 +02:00
|
|
|
function get_userdata( $user_id ) {
|
2005-11-07 22:56:03 +01:00
|
|
|
global $wpdb;
|
2007-11-27 23:14:53 +01:00
|
|
|
|
2007-10-02 20:45:47 +02:00
|
|
|
$user_id = abs(intval($user_id));
|
2005-06-12 22:49:13 +02:00
|
|
|
if ( $user_id == 0 )
|
|
|
|
return false;
|
2005-07-12 17:53:13 +02:00
|
|
|
|
2005-11-07 22:56:03 +01:00
|
|
|
$user = wp_cache_get($user_id, 'users');
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2007-11-27 23:14:53 +01:00
|
|
|
if ( '0' === $user )
|
|
|
|
return false;
|
|
|
|
else if ( $user )
|
2005-11-07 22:56:03 +01:00
|
|
|
return $user;
|
2005-06-12 22:49:13 +02:00
|
|
|
|
2007-11-27 23:14:53 +01:00
|
|
|
if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id)) ) {
|
|
|
|
wp_cache_add($user_id, 0, 'users');
|
2005-11-07 22:56:03 +01:00
|
|
|
return false;
|
2007-11-27 23:14:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_fill_user($user);
|
2005-06-12 22:49:13 +02:00
|
|
|
|
2005-11-07 22:56:03 +01:00
|
|
|
return $user;
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-07-12 17:53:13 +02:00
|
|
|
if ( !function_exists('update_user_cache') ) :
|
|
|
|
function update_user_cache() {
|
2005-11-17 19:15:59 +01:00
|
|
|
return true;
|
2005-07-12 17:53:13 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !function_exists('get_userdatabylogin') ) :
|
|
|
|
function get_userdatabylogin($user_login) {
|
2005-11-17 19:15:59 +01:00
|
|
|
global $wpdb;
|
2005-06-13 01:14:52 +02:00
|
|
|
$user_login = sanitize_user( $user_login );
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-06-12 22:49:13 +02:00
|
|
|
if ( empty( $user_login ) )
|
|
|
|
return false;
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2007-02-02 01:00:36 +01:00
|
|
|
$user_id = wp_cache_get($user_login, 'userlogins');
|
2007-11-27 23:14:53 +01:00
|
|
|
if ( '0' === $user_id )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$user = false;
|
|
|
|
if ( false !== $user_id )
|
|
|
|
$user = wp_cache_get($user_id, 'users');
|
2007-02-02 01:00:36 +01:00
|
|
|
|
2007-11-27 23:14:53 +01:00
|
|
|
if ( false !== $user )
|
|
|
|
return $user;
|
2005-06-12 22:49:13 +02:00
|
|
|
|
2007-11-27 23:14:53 +01:00
|
|
|
if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_login = %s", $user_login)) ) {
|
|
|
|
wp_cache_add($user_login, 0, 'userlogins');
|
2005-11-17 19:15:59 +01:00
|
|
|
return false;
|
2007-11-27 23:14:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_fill_user($user);
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('get_user_by_email') ) :
|
|
|
|
function get_user_by_email($email) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$user_id = wp_cache_get($email, 'useremail');
|
|
|
|
|
|
|
|
if ( '0' === $user_id )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$user = false;
|
|
|
|
if ( false !== $user_id )
|
|
|
|
$user = wp_cache_get($user_id, 'users');
|
|
|
|
|
|
|
|
if ( false !== $user )
|
|
|
|
return $user;
|
|
|
|
|
|
|
|
if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_email = %s", $email)) ) {
|
|
|
|
wp_cache_add($email, 0, 'useremail');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_fill_user($user);
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-11-17 19:15:59 +01:00
|
|
|
return $user;
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
if ( !function_exists( 'wp_mail' ) ) :
|
|
|
|
function wp_mail( $to, $subject, $message, $headers = '' ) {
|
2007-09-11 22:49:28 +02:00
|
|
|
// Compact the input, apply the filters, and extract them back out
|
|
|
|
extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) );
|
|
|
|
|
2007-02-25 21:23:25 +01:00
|
|
|
global $phpmailer;
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// (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';
|
2007-02-25 21:23:25 +01:00
|
|
|
$phpmailer = new PHPMailer();
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-26 21:11:23 +02:00
|
|
|
// Headers
|
2007-06-02 05:18:24 +02:00
|
|
|
if ( empty( $headers ) ) {
|
2007-06-26 21:11:23 +02:00
|
|
|
$headers = array();
|
2007-06-02 05:18:24 +02:00
|
|
|
} elseif ( !is_array( $headers ) ) {
|
2007-09-04 01:32:58 +02:00
|
|
|
// Explode the headers out, so this function can take both
|
2007-06-02 05:18:24 +02:00
|
|
|
// string headers and an array of headers.
|
|
|
|
$tempheaders = (array) explode( "\n", $headers );
|
|
|
|
$headers = array();
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// If it's actually got contents
|
|
|
|
if ( !empty( $tempheaders ) ) {
|
|
|
|
// Iterate through the raw headers
|
|
|
|
foreach ( $tempheaders as $header ) {
|
2007-06-26 22:18:56 +02:00
|
|
|
if ( strpos($header, ':') === false )
|
|
|
|
continue;
|
2007-06-02 05:18:24 +02:00
|
|
|
// Explode them out
|
|
|
|
list( $name, $content ) = explode( ':', trim( $header ), 2 );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Cleanup crew
|
|
|
|
$name = trim( $name );
|
|
|
|
$content = trim( $content );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Mainly for legacy -- process a From: header if it's there
|
2007-06-26 20:28:56 +02:00
|
|
|
if ( 'from' == strtolower($name) ) {
|
2007-06-26 20:06:17 +02:00
|
|
|
if ( strpos($content, '<' ) !== false ) {
|
2007-06-02 05:18:24 +02:00
|
|
|
// So... making my life hard again?
|
2007-06-26 20:06:17 +02:00
|
|
|
$from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
|
2007-06-02 05:18:24 +02:00
|
|
|
$from_name = str_replace( '"', '', $from_name );
|
|
|
|
$from_name = trim( $from_name );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-26 20:06:17 +02:00
|
|
|
$from_email = substr( $content, strpos( $content, '<' ) + 1 );
|
2007-06-02 05:18:24 +02:00
|
|
|
$from_email = str_replace( '>', '', $from_email );
|
|
|
|
$from_email = trim( $from_email );
|
|
|
|
} else {
|
|
|
|
$from_name = trim( $content );
|
|
|
|
}
|
2007-06-26 20:28:56 +02:00
|
|
|
} elseif ( 'content-type' == strtolower($name) ) {
|
2007-06-26 20:06:17 +02:00
|
|
|
if ( strpos( $content,';' ) !== false ) {
|
2007-06-02 05:18:24 +02:00
|
|
|
list( $type, $charset ) = explode( ';', $content );
|
2007-06-26 22:18:56 +02:00
|
|
|
$content_type = trim( $type );
|
2007-06-02 05:18:24 +02:00
|
|
|
$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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Empty out the values that may be set
|
2007-02-25 21:23:25 +01:00
|
|
|
$phpmailer->ClearAddresses();
|
|
|
|
$phpmailer->ClearAllRecipients();
|
2007-06-02 05:18:24 +02:00
|
|
|
$phpmailer->ClearAttachments();
|
|
|
|
$phpmailer->ClearBCCs();
|
|
|
|
$phpmailer->ClearCCs();
|
2007-02-25 21:23:25 +01:00
|
|
|
$phpmailer->ClearCustomHeaders();
|
2007-06-02 05:18:24 +02:00
|
|
|
$phpmailer->ClearReplyTos();
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// From email and name
|
|
|
|
// If we don't have a name from the input headers
|
|
|
|
if ( !isset( $from_name ) ) {
|
|
|
|
$from_name = 'WordPress';
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// 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 );
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
$from_email = 'wordpress@' . $sitename;
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Set the from name and email
|
|
|
|
$phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
|
2007-10-17 22:17:01 +02:00
|
|
|
$phpmailer->Sender = apply_filters( 'wp_mail_from', $from_email );
|
2007-06-02 05:18:24 +02:00
|
|
|
$phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Set destination address
|
|
|
|
$phpmailer->AddAddress( $to );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Set mail's subject and body
|
2007-02-25 21:23:25 +01:00
|
|
|
$phpmailer->Subject = $subject;
|
2007-06-02 05:18:24 +02:00
|
|
|
$phpmailer->Body = $message;
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Set to use PHP's mail()
|
|
|
|
$phpmailer->IsMail();
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// 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';
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-26 22:18:56 +02:00
|
|
|
$content_type = apply_filters( 'wp_mail_content_type', $content_type );
|
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Set whether it's plaintext or not, depending on $content_type
|
|
|
|
if ( $content_type == 'text/html' ) {
|
|
|
|
$phpmailer->IsHTML( true );
|
|
|
|
} else {
|
|
|
|
$phpmailer->IsHTML( false );
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// If we don't have a charset from the input headers
|
|
|
|
if ( !isset( $charset ) ) {
|
|
|
|
$charset = get_bloginfo( 'charset' );
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Set the content-type and charset
|
|
|
|
$phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Set custom headers
|
|
|
|
if ( !empty( $headers ) ) {
|
|
|
|
foreach ( $headers as $name => $content ) {
|
|
|
|
$phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
|
2007-02-25 21:23:25 +01:00
|
|
|
}
|
|
|
|
}
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-06-02 05:18:24 +02:00
|
|
|
// Send!
|
2007-02-25 21:23:25 +01:00
|
|
|
$result = @$phpmailer->Send();
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-02-25 21:23:25 +01:00
|
|
|
return $result;
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_login') ) :
|
2008-01-04 20:36:34 +01:00
|
|
|
function wp_login($username, $password, $deprecated = '') {
|
|
|
|
global $error;
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2007-06-12 20:11:06 +02:00
|
|
|
$username = sanitize_user($username);
|
|
|
|
|
2005-11-17 01:51:34 +01:00
|
|
|
if ( '' == $username )
|
2005-04-20 05:37:23 +02:00
|
|
|
return false;
|
|
|
|
|
2005-11-17 01:51:34 +01:00
|
|
|
if ( '' == $password ) {
|
2006-10-04 18:47:50 +02:00
|
|
|
$error = __('<strong>ERROR</strong>: The password field is empty.');
|
2005-04-20 05:37:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-12-17 07:02:45 +01:00
|
|
|
$user = get_userdatabylogin($username);
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2007-12-17 07:02:45 +01:00
|
|
|
if ( !$user || ($user->user_login != $username) ) {
|
2006-10-04 18:47:50 +02:00
|
|
|
$error = __('<strong>ERROR</strong>: Invalid username.');
|
2005-04-20 05:37:23 +02:00
|
|
|
return false;
|
2007-12-02 06:14:11 +01:00
|
|
|
}
|
|
|
|
|
2007-12-17 07:02:45 +01:00
|
|
|
if ( !wp_check_password($password, $user->user_pass) ) {
|
2007-12-16 18:41:59 +01:00
|
|
|
$error = __('<strong>ERROR</strong>: Incorrect password.');
|
|
|
|
return false;
|
|
|
|
}
|
2007-12-02 06:14:11 +01:00
|
|
|
|
2007-12-16 18:41:59 +01:00
|
|
|
// If using old md5 password, rehash.
|
2007-12-17 07:02:45 +01:00
|
|
|
if ( strlen($user->user_pass) <= 32 )
|
|
|
|
wp_set_password($password, $user->ID);
|
2007-12-16 18:41:59 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_validate_auth_cookie') ) :
|
|
|
|
function wp_validate_auth_cookie($cookie = '') {
|
|
|
|
if ( empty($cookie) ) {
|
|
|
|
if ( empty($_COOKIE[AUTH_COOKIE]) )
|
|
|
|
return false;
|
|
|
|
$cookie = $_COOKIE[AUTH_COOKIE];
|
|
|
|
}
|
|
|
|
|
|
|
|
list($username, $expiration, $hmac) = explode('|', $cookie);
|
|
|
|
|
|
|
|
$expired = $expiration;
|
|
|
|
|
2007-12-23 01:58:06 +01:00
|
|
|
// Allow a grace period for POST and AJAX requests
|
|
|
|
if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] )
|
2007-12-16 18:41:59 +01:00
|
|
|
$expired += 3600;
|
|
|
|
|
|
|
|
if ( $expired < time() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$key = wp_hash($username . $expiration);
|
|
|
|
$hash = hash_hmac('md5', $username . $expiration, $key);
|
|
|
|
|
|
|
|
if ( $hmac != $hash )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$user = get_userdatabylogin($username);
|
|
|
|
if ( ! $user )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return $user->ID;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2007-12-31 18:50:32 +01:00
|
|
|
if ( !function_exists('wp_generate_auth_cookie') ) :
|
|
|
|
function wp_generate_auth_cookie($user_id, $expiration) {
|
|
|
|
$user = get_userdata($user_id);
|
|
|
|
|
|
|
|
$key = wp_hash($user->user_login . $expiration);
|
|
|
|
$hash = hash_hmac('md5', $user->user_login . $expiration, $key);
|
|
|
|
|
|
|
|
$cookie = $user->user_login . '|' . $expiration . '|' . $hash;
|
|
|
|
|
|
|
|
return apply_filters('auth_cookie', $cookie, $user_id, $expiration);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2007-12-16 18:41:59 +01:00
|
|
|
if ( !function_exists('wp_set_auth_cookie') ) :
|
|
|
|
function wp_set_auth_cookie($user_id, $remember = false) {
|
|
|
|
if ( $remember ) {
|
|
|
|
$expiration = $expire = time() + 1209600;
|
2007-12-02 06:14:11 +01:00
|
|
|
} else {
|
2007-12-16 18:41:59 +01:00
|
|
|
$expiration = time() + 172800;
|
|
|
|
$expire = 0;
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
2007-12-02 06:14:11 +01:00
|
|
|
|
2007-12-31 18:50:32 +01:00
|
|
|
$cookie = wp_generate_auth_cookie($user_id, $expiration);
|
2007-12-16 18:41:59 +01:00
|
|
|
|
2007-12-24 09:01:55 +01:00
|
|
|
do_action('set_auth_cookie', $cookie, $expire);
|
|
|
|
|
2007-12-16 18:41:59 +01:00
|
|
|
setcookie(AUTH_COOKIE, $cookie, $expire, COOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
if ( COOKIEPATH != SITECOOKIEPATH )
|
|
|
|
setcookie(AUTH_COOKIE, $cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_clear_auth_cookie') ) :
|
|
|
|
function wp_clear_auth_cookie() {
|
|
|
|
setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
|
|
|
|
// Old cookies
|
|
|
|
setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-12-15 17:31:41 +01:00
|
|
|
if ( !function_exists('is_user_logged_in') ) :
|
|
|
|
function is_user_logged_in() {
|
2006-02-22 20:08:55 +01:00
|
|
|
$user = wp_get_current_user();
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2006-02-22 20:08:55 +01:00
|
|
|
if ( $user->id == 0 )
|
2005-12-15 17:31:41 +01:00
|
|
|
return false;
|
2006-02-22 20:08:55 +01:00
|
|
|
|
2005-12-15 17:31:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !function_exists('auth_redirect') ) :
|
|
|
|
function auth_redirect() {
|
|
|
|
// Checks if a user is logged in, if not redirects them to the login page
|
2007-12-16 18:41:59 +01:00
|
|
|
if ( (!empty($_COOKIE[AUTH_COOKIE]) &&
|
|
|
|
!wp_validate_auth_cookie($_COOKIE[AUTH_COOKIE])) ||
|
|
|
|
(empty($_COOKIE[AUTH_COOKIE])) ) {
|
2005-06-09 02:17:43 +02:00
|
|
|
nocache_headers();
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2006-08-30 23:46:31 +02:00
|
|
|
wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
|
2005-04-20 05:37:23 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-01-30 00:06:58 +01:00
|
|
|
if ( !function_exists('check_admin_referer') ) :
|
2006-05-03 00:08:34 +02:00
|
|
|
function check_admin_referer($action = -1) {
|
2006-08-30 23:46:31 +02:00
|
|
|
$adminurl = strtolower(get_option('siteurl')).'/wp-admin';
|
2006-06-24 07:38:37 +02:00
|
|
|
$referer = strtolower(wp_get_referer());
|
2006-05-17 02:28:26 +02:00
|
|
|
if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) &&
|
2007-03-07 07:17:15 +01:00
|
|
|
!(-1 == $action && strpos($referer, $adminurl) !== false)) {
|
2006-06-27 10:06:00 +02:00
|
|
|
wp_nonce_ays($action);
|
2006-05-18 08:49:22 +02:00
|
|
|
die();
|
2006-05-03 00:08:34 +02:00
|
|
|
}
|
2006-05-04 11:23:17 +02:00
|
|
|
do_action('check_admin_referer', $action);
|
2006-05-03 00:08:34 +02:00
|
|
|
}endif;
|
2006-03-29 03:51:55 +02:00
|
|
|
|
|
|
|
if ( !function_exists('check_ajax_referer') ) :
|
2007-10-10 00:49:42 +02:00
|
|
|
function check_ajax_referer( $action = -1 ) {
|
|
|
|
$nonce = $_REQUEST['_ajax_nonce'] ? $_REQUEST['_ajax_nonce'] : $_REQUEST['_wpnonce'];
|
|
|
|
if ( !wp_verify_nonce( $nonce, $action ) ) {
|
2007-12-17 22:12:28 +01:00
|
|
|
$current_id = '';
|
2007-10-10 00:49:42 +02:00
|
|
|
if ( ( $current = wp_get_current_user() ) && $current->ID )
|
2007-12-17 22:12:28 +01:00
|
|
|
$current_id = $current->ID;
|
|
|
|
if ( !$current_id )
|
2007-10-10 00:49:42 +02:00
|
|
|
die('-1');
|
|
|
|
|
2007-12-16 18:41:59 +01:00
|
|
|
$auth_cookie = '';
|
2007-10-10 00:49:42 +02:00
|
|
|
$cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie
|
|
|
|
foreach ( $cookie as $tasty ) {
|
2007-12-16 18:41:59 +01:00
|
|
|
if ( false !== strpos($tasty, AUTH_COOKIE) )
|
|
|
|
$auth_cookie = substr(strstr($tasty, '='), 1);
|
2007-10-10 00:49:42 +02:00
|
|
|
}
|
2007-09-19 21:32:34 +02:00
|
|
|
|
2007-12-17 22:12:28 +01:00
|
|
|
if ( empty($auth_cookie) )
|
|
|
|
die('-1');
|
|
|
|
|
|
|
|
if ( ! $user_id = wp_validate_auth_cookie( $auth_cookie ) )
|
|
|
|
die('-1');
|
|
|
|
|
|
|
|
if ( $current_id != $user_id )
|
2007-10-10 00:49:42 +02:00
|
|
|
die('-1');
|
|
|
|
}
|
2006-03-29 03:51:55 +02:00
|
|
|
do_action('check_ajax_referer');
|
|
|
|
}
|
|
|
|
endif;
|
2006-01-30 00:06:58 +01:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
// Cookie safe redirect. Works around IIS Set-Cookie bug.
|
|
|
|
// http://support.microsoft.com/kb/q176113/
|
|
|
|
if ( !function_exists('wp_redirect') ) :
|
2006-09-26 02:55:21 +02:00
|
|
|
function wp_redirect($location, $status = 302) {
|
2005-04-20 05:37:23 +02:00
|
|
|
global $is_IIS;
|
|
|
|
|
2006-10-19 00:02:30 +02:00
|
|
|
$location = apply_filters('wp_redirect', $location, $status);
|
|
|
|
|
|
|
|
if ( !$location ) // allows the wp_redirect filter to cancel a redirect
|
2007-09-04 01:32:58 +02:00
|
|
|
return false;
|
2006-10-19 00:02:30 +02:00
|
|
|
|
2007-09-19 05:47:37 +02:00
|
|
|
$location = wp_sanitize_redirect($location);
|
|
|
|
|
|
|
|
if ( $is_IIS ) {
|
|
|
|
header("Refresh: 0;url=$location");
|
|
|
|
} else {
|
|
|
|
if ( php_sapi_name() != 'cgi-fcgi' )
|
|
|
|
status_header($status); // This causes problems on IIS and some FastCGI setups
|
|
|
|
header("Location: $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) {
|
2007-08-30 20:13:48 +02:00
|
|
|
$location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
|
2006-07-06 02:28:37 +02:00
|
|
|
$location = wp_kses_no_null($location);
|
2006-06-30 02:43:23 +02:00
|
|
|
|
2007-08-30 19:46:09 +02:00
|
|
|
// remove %0d and %0a from location
|
2006-06-30 02:43:23 +02:00
|
|
|
$strip = array('%0d', '%0a');
|
2007-08-30 19:46:09 +02:00
|
|
|
$found = true;
|
|
|
|
while($found) {
|
|
|
|
$found = false;
|
|
|
|
foreach($strip as $val) {
|
|
|
|
while(strpos($location, $val) !== false) {
|
|
|
|
$found = true;
|
|
|
|
$location = str_replace($val, '', $location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-19 05:47:37 +02:00
|
|
|
return $location;
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2007-09-19 00:23:16 +02:00
|
|
|
if ( !function_exists('wp_safe_redirect') ) :
|
|
|
|
/**
|
|
|
|
* performs a safe (local) redirect, using wp_redirect()
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function wp_safe_redirect($location, $status = 302) {
|
2007-09-19 05:47:37 +02:00
|
|
|
|
|
|
|
// 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'));
|
|
|
|
|
2007-09-20 23:53:42 +02:00
|
|
|
$allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), $lp['host']);
|
2007-09-19 06:14:53 +02:00
|
|
|
|
2007-10-10 21:25:23 +02:00
|
|
|
if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
|
2007-09-19 05:47:37 +02:00
|
|
|
$location = get_option('siteurl') . '/wp-admin/';
|
2007-09-19 00:23:16 +02:00
|
|
|
|
|
|
|
wp_redirect($location, $status);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( ! function_exists('wp_notify_postauthor') ) :
|
|
|
|
function wp_notify_postauthor($comment_id, $comment_type='') {
|
2005-11-08 00:15:21 +01:00
|
|
|
$comment = get_comment($comment_id);
|
|
|
|
$post = get_post($comment->comment_post_ID);
|
2005-11-07 09:58:37 +01:00
|
|
|
$user = get_userdata( $post->post_author );
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
if ('' == $user->user_email) return false; // If there's no email to send the comment to
|
|
|
|
|
2006-10-04 05:05:54 +02:00
|
|
|
$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2006-08-30 23:46:31 +02:00
|
|
|
$blogname = get_option('blogname');
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( empty( $comment_type ) ) $comment_type = 'comment';
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
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";
|
2006-08-30 18:40:17 +02:00
|
|
|
$notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
$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";
|
|
|
|
$subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
|
|
|
|
} 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";
|
2006-08-30 18:40:17 +02:00
|
|
|
$notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
$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";
|
2006-08-30 18:40:17 +02:00
|
|
|
$notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
|
2005-12-02 23:37:02 +01:00
|
|
|
$notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
$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";
|
2007-02-15 06:51:59 +01:00
|
|
|
$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";
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2005-11-25 23:57:26 +01:00
|
|
|
$wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
|
2005-11-11 01:07:39 +01:00
|
|
|
|
|
|
|
if ( '' == $comment->comment_author ) {
|
2005-11-25 23:57:26 +01:00
|
|
|
$from = "From: \"$blogname\" <$wp_email>";
|
2005-11-11 01:07:39 +01:00
|
|
|
if ( '' != $comment->comment_author_email )
|
|
|
|
$reply_to = "Reply-To: $comment->comment_author_email";
|
2006-11-19 08:56:05 +01:00
|
|
|
} else {
|
2005-11-25 23:57:26 +01:00
|
|
|
$from = "From: \"$comment->comment_author\" <$wp_email>";
|
2005-11-11 01:07:39 +01:00
|
|
|
if ( '' != $comment->comment_author_email )
|
|
|
|
$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
|
2006-11-19 08:56:05 +01:00
|
|
|
}
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2007-06-26 22:18:56 +02:00
|
|
|
$message_headers = "$from\n"
|
2006-08-30 23:46:31 +02:00
|
|
|
. "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2005-11-11 03:00:06 +01:00
|
|
|
if ( isset($reply_to) )
|
|
|
|
$message_headers .= $reply_to . "\n";
|
|
|
|
|
2006-01-18 19:49:28 +01:00
|
|
|
$notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
|
|
|
|
$subject = apply_filters('comment_notification_subject', $subject, $comment_id);
|
|
|
|
$message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
|
2005-08-31 01:17:42 +02:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
@wp_mail($user->user_email, $subject, $notify_message, $message_headers);
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
/* wp_notify_moderator
|
|
|
|
notifies the moderator of the blog (usually the admin)
|
|
|
|
about a new comment that waits for approval
|
|
|
|
always returns true
|
|
|
|
*/
|
|
|
|
if ( !function_exists('wp_notify_moderator') ) :
|
|
|
|
function wp_notify_moderator($comment_id) {
|
|
|
|
global $wpdb;
|
|
|
|
|
2006-08-30 23:46:31 +02:00
|
|
|
if( get_option( "moderation_notify" ) == 0 )
|
2007-09-04 01:32:58 +02:00
|
|
|
return true;
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-10-02 20:45:47 +02:00
|
|
|
$comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID=%d LIMIT 1", $comment_id));
|
|
|
|
$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID=%d LIMIT 1", $comment->comment_post_ID));
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2006-10-04 05:05:54 +02:00
|
|
|
$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
|
2005-04-20 05:37:23 +02:00
|
|
|
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
|
|
|
|
|
|
|
|
$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";
|
|
|
|
$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";
|
2006-08-30 18:40:17 +02:00
|
|
|
$notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
$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";
|
2006-11-23 01:10:30 +01:00
|
|
|
$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";
|
2007-12-20 18:05:06 +01:00
|
|
|
$strCommentsPending = sprintf( __ngettext('%s comment', '%s comments', $comments_waiting), $comments_waiting );
|
|
|
|
$notify_message .= sprintf( __('Currently %s are waiting for approval. Please visit the moderation panel:'), $strCommentsPending ) . "\r\n";
|
2006-08-30 23:46:31 +02:00
|
|
|
$notify_message .= get_option('siteurl') . "/wp-admin/moderation.php\r\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2006-08-30 23:46:31 +02:00
|
|
|
$subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_option('blogname'), $post->post_title );
|
|
|
|
$admin_email = get_option('admin_email');
|
2005-08-31 01:17:42 +02:00
|
|
|
|
2006-01-18 19:49:28 +01:00
|
|
|
$notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
|
|
|
|
$subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
@wp_mail($admin_email, $subject, $notify_message);
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-09-14 02:03:02 +02:00
|
|
|
if ( !function_exists('wp_new_user_notification') ) :
|
|
|
|
function wp_new_user_notification($user_id, $plaintext_pass = '') {
|
|
|
|
$user = new WP_User($user_id);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2005-11-16 03:54:23 +01:00
|
|
|
$user_login = stripslashes($user->user_login);
|
|
|
|
$user_email = stripslashes($user->user_email);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2006-08-30 23:46:31 +02:00
|
|
|
$message = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n";
|
2005-09-14 02:03:02 +02:00
|
|
|
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
|
|
|
|
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2006-08-30 23:46:31 +02:00
|
|
|
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
|
2005-09-14 02:03:02 +02:00
|
|
|
|
|
|
|
if ( empty($plaintext_pass) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$message = sprintf(__('Username: %s'), $user_login) . "\r\n";
|
|
|
|
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
|
2006-08-30 23:46:31 +02:00
|
|
|
$message .= get_option('siteurl') . "/wp-login.php\r\n";
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2006-08-30 23:46:31 +02:00
|
|
|
wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2005-09-14 02:03:02 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-05-03 00:08:34 +02:00
|
|
|
if ( !function_exists('wp_verify_nonce') ) :
|
|
|
|
function wp_verify_nonce($nonce, $action = -1) {
|
|
|
|
$user = wp_get_current_user();
|
2007-03-23 01:59:21 +01:00
|
|
|
$uid = (int) $user->id;
|
2006-05-03 00:08:34 +02:00
|
|
|
|
|
|
|
$i = ceil(time() / 43200);
|
|
|
|
|
|
|
|
//Allow for expanding range, but only do one check if we can
|
2006-05-31 02:24:03 +02:00
|
|
|
if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce )
|
2006-05-03 00:08:34 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_create_nonce') ) :
|
|
|
|
function wp_create_nonce($action = -1) {
|
|
|
|
$user = wp_get_current_user();
|
2007-03-23 01:59:21 +01:00
|
|
|
$uid = (int) $user->id;
|
2006-05-03 00:08:34 +02:00
|
|
|
|
|
|
|
$i = ceil(time() / 43200);
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-05-31 02:24:03 +02:00
|
|
|
return substr(wp_hash($i . $action . $uid), -12, 10);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-05-31 03:40:00 +02:00
|
|
|
if ( !function_exists('wp_salt') ) :
|
|
|
|
function wp_salt() {
|
2007-12-23 01:58:06 +01:00
|
|
|
|
2007-12-24 07:34:12 +01:00
|
|
|
$secret_key = '';
|
|
|
|
if ( defined('SECRET_KEY') && ('' != SECRET_KEY) && ('put your unique phrase here' != SECRET_KEY) )
|
|
|
|
$secret_key = SECRET_KEY;
|
2007-12-23 01:58:06 +01:00
|
|
|
|
2007-12-24 07:34:12 +01:00
|
|
|
if ( defined('SECRET_SALT') ) {
|
|
|
|
$salt = SECRET_SALT;
|
|
|
|
} else {
|
|
|
|
$salt = get_option('secret');
|
|
|
|
if ( empty($salt) ) {
|
|
|
|
$salt = wp_generate_password();
|
|
|
|
update_option('secret', $salt);
|
|
|
|
}
|
2007-12-16 18:41:59 +01:00
|
|
|
}
|
2006-05-31 03:40:00 +02:00
|
|
|
|
2008-01-09 17:37:43 +01:00
|
|
|
return apply_filters('salt', $secret_key . $salt);
|
2006-05-31 03:40:00 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-05-31 02:24:03 +02:00
|
|
|
if ( !function_exists('wp_hash') ) :
|
|
|
|
function wp_hash($data) {
|
2006-05-31 03:40:00 +02:00
|
|
|
$salt = wp_salt();
|
2006-05-31 02:24:03 +02:00
|
|
|
|
|
|
|
if ( function_exists('hash_hmac') ) {
|
2006-05-31 03:40:00 +02:00
|
|
|
return hash_hmac('md5', $data, $salt);
|
2006-05-31 02:24:03 +02:00
|
|
|
} else {
|
2006-05-31 03:40:00 +02:00
|
|
|
return md5($data . $salt);
|
2006-05-31 02:24:03 +02:00
|
|
|
}
|
2006-05-03 00:08:34 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2007-12-02 06:14:11 +01:00
|
|
|
if ( !function_exists('wp_hash_password') ) :
|
|
|
|
function wp_hash_password($password) {
|
|
|
|
global $wp_hasher;
|
|
|
|
|
|
|
|
if ( empty($wp_hasher) ) {
|
|
|
|
require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
|
|
|
// By default, use the portable hash from phpass
|
|
|
|
$wp_hasher = new PasswordHash(8, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $wp_hasher->HashPassword($password);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_check_password') ) :
|
|
|
|
function wp_check_password($password, $hash) {
|
|
|
|
global $wp_hasher;
|
|
|
|
|
|
|
|
if ( strlen($hash) <= 32 )
|
|
|
|
return ( $hash == md5($password) );
|
|
|
|
|
|
|
|
// If the stored hash is longer than an MD5, presume the
|
|
|
|
// new style phpass portable hash.
|
|
|
|
if ( empty($wp_hasher) ) {
|
|
|
|
require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
|
|
|
// By default, use the portable hash from phpass
|
|
|
|
$wp_hasher = new PasswordHash(8, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $wp_hasher->CheckPassword($password, $hash);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2007-12-15 06:31:16 +01:00
|
|
|
if ( !function_exists('wp_generate_password') ) :
|
|
|
|
/**
|
|
|
|
* Generates a random password drawn from the defined set of characters
|
|
|
|
* @return string the password
|
|
|
|
**/
|
|
|
|
function wp_generate_password() {
|
|
|
|
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
$length = 7;
|
|
|
|
$password = '';
|
|
|
|
for ( $i = 0; $i < $length; $i++ )
|
|
|
|
$password .= substr($chars, mt_rand(0, 61), 1);
|
|
|
|
return $password;
|
|
|
|
}
|
|
|
|
endif;
|
2007-12-16 18:41:59 +01:00
|
|
|
|
2007-12-17 07:02:45 +01:00
|
|
|
if ( !function_exists('wp_set_password') ) :
|
|
|
|
function wp_set_password( $password, $user_id ) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$hash = wp_hash_password($password);
|
|
|
|
$query = $wpdb->prepare("UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $hash, $user_id);
|
|
|
|
$wpdb->query($query);
|
|
|
|
wp_cache_delete($user_id, 'users');
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2007-12-16 18:41:59 +01:00
|
|
|
// Deprecated. Use wp_set_auth_cookie()
|
|
|
|
if ( !function_exists('wp_setcookie') ) :
|
|
|
|
function wp_setcookie($username, $password = '', $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
|
2008-01-04 20:36:34 +01:00
|
|
|
_deprecated_function( __FUNCTION__, '2.4', 'wp_set_auth_cookie()' );
|
2007-12-16 18:41:59 +01:00
|
|
|
$user = get_userdatabylogin($username);
|
|
|
|
wp_set_auth_cookie($user->ID, $remember);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
// Deprecated. Use wp_clear_auth_cookie()
|
|
|
|
if ( !function_exists('wp_clearcookie') ) :
|
|
|
|
function wp_clearcookie() {
|
2008-01-04 20:36:34 +01:00
|
|
|
_deprecated_function( __FUNCTION__, '2.4', 'wp_clear_auth_cookie()' );
|
2007-12-16 18:41:59 +01:00
|
|
|
wp_clear_auth_cookie();
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
// Deprecated. No alternative.
|
|
|
|
if ( !function_exists('wp_get_cookie_login') ):
|
|
|
|
function wp_get_cookie_login() {
|
2008-01-04 20:36:34 +01:00
|
|
|
_deprecated_function( __FUNCTION__, '2.4', '' );
|
2007-12-16 18:41:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-07-12 17:53:13 +02:00
|
|
|
?>
|