ID) ) return $current_user; $current_user = new WP_User($id, $name); setup_userdata($current_user->ID); do_action('set_current_user'); return $current_user; } endif; if ( !function_exists('current_user') ) : function wp_get_current_user() { global $current_user; get_currentuserinfo(); return $current_user; } endif; if ( !function_exists('get_currentuserinfo') ) : function get_currentuserinfo() { global $current_user; if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) return false; if ( ! empty($current_user) ) return; 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; } $user_login = $_COOKIE[USER_COOKIE]; wp_set_current_user(0, $user_login); } endif; if ( !function_exists('get_userdata') ) : function get_userdata( $user_id ) { global $wpdb; $user_id = (int) $user_id; if ( $user_id == 0 ) 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(); $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'"); $wpdb->show_errors(); if ($metavalues) { foreach ( $metavalues as $meta ) { @ $value = unserialize($meta->meta_value); if ($value === FALSE) $value = $meta->meta_value; $user->{$meta->meta_key} = $value; // We need to set user_level from meta, not row if ( $wpdb->prefix . 'user_level' == $meta->meta_key ) $user->user_level = $meta->meta_value; } // end foreach } //end if // 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; wp_cache_add($user_id, $user, 'users'); wp_cache_add($user->user_login, $user, 'userlogins'); return $user; } endif; if ( !function_exists('update_user_cache') ) : function update_user_cache() { return true; } endif; if ( !function_exists('get_userdatabylogin') ) : function get_userdatabylogin($user_login) { global $wpdb; $user_login = sanitize_user( $user_login ); if ( empty( $user_login ) ) return false; $userdata = wp_cache_get($user_login, 'userlogins'); if ( $userdata ) return $userdata; if ( !$user = $wpdb->get_row("SELECT * 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(); if ($metavalues) { foreach ( $metavalues as $meta ) { @ $value = unserialize($meta->meta_value); if ($value === FALSE) $value = $meta->meta_value; $user->{$meta->meta_key} = $value; // We need to set user_level from meta, not row if ( $wpdb->prefix . 'user_level' == $meta->meta_key ) $user->user_level = $meta->meta_value; } } // 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; wp_cache_add($user->ID, $user, 'users'); wp_cache_add($user->user_login, $user, 'userlogins'); return $user; } endif; 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"; } return @mail($to, $subject, $message, $headers); } endif; if ( !function_exists('wp_login') ) : function wp_login($username, $password, $already_md5 = false) { global $wpdb, $error; if ( '' == $username ) return false; if ( '' == $password ) { $error = __('Error: The password field is empty.'); return false; } $login = get_userdatabylogin($username); //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'"); if (!$login) { $error = __('Error: Wrong username.'); return false; } else { // If the password is already_md5, it has been double hashed. // Otherwise, it is plain text. if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) { return true; } else { $error = __('Error: Incorrect password.'); $pwd = ''; return false; } } } endif; if ( !function_exists('is_user_logged_in') ) : function is_user_logged_in() { $user = wp_get_current_user(); if ( $user->id == 0 ) return false; return true; } endif; 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]) && !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) || (empty($_COOKIE[USER_COOKIE])) ) { nocache_headers(); header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])); exit(); } } endif; if ( !function_exists('check_admin_referer') ) : function check_admin_referer($action = -1) { global $pagenow, $menu, $submenu, $parent_file, $submenu_file;; $adminurl = strtolower(get_settings('siteurl')).'/wp-admin'; $referer = strtolower($_SERVER['HTTP_REFERER']); if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) && !(-1 == $action && strstr($referer, $adminurl)) ) { if ( $referer ) $adminurl = $referer; $title = __('WordPress Confirmation'); require_once(ABSPATH . '/wp-admin/admin-header.php'); if ( $_POST ) { $q = http_build_query($_POST); $q = explode( ini_get('arg_separator.output'), $q); $html .= "\t
\n"; } else { $html .= "\t" . __('Are you sure you want to do this?') . "
\n\t\n\t