| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* These functions can be replaced via plugins. They are loaded after |
|---|
| 4 | plugins are loaded. */ |
|---|
| 5 | |
|---|
| 6 | if ( !function_exists('set_current_user') ) : |
|---|
| 7 | function set_current_user($id, $name = '') { |
|---|
| 8 | return wp_set_current_user($id, $name); |
|---|
| 9 | } |
|---|
| 10 | endif; |
|---|
| 11 | |
|---|
| 12 | if ( !function_exists('wp_set_current_user') ) : |
|---|
| 13 | function wp_set_current_user($id, $name = '') { |
|---|
| 14 | global $current_user; |
|---|
| 15 | |
|---|
| 16 | if ( isset($current_user) && ($id == $current_user->ID) ) |
|---|
| 17 | return $current_user; |
|---|
| 18 | |
|---|
| 19 | $current_user = new WP_User($id, $name); |
|---|
| 20 | |
|---|
| 21 | setup_userdata($current_user->ID); |
|---|
| 22 | |
|---|
| 23 | do_action('set_current_user'); |
|---|
| 24 | |
|---|
| 25 | return $current_user; |
|---|
| 26 | } |
|---|
| 27 | endif; |
|---|
| 28 | |
|---|
| 29 | if ( !function_exists('wp_get_current_user') ) : |
|---|
| 30 | function wp_get_current_user() { |
|---|
| 31 | global $current_user; |
|---|
| 32 | |
|---|
| 33 | get_currentuserinfo(); |
|---|
| 34 | |
|---|
| 35 | return $current_user; |
|---|
| 36 | } |
|---|
| 37 | endif; |
|---|
| 38 | |
|---|
| 39 | if ( !function_exists('get_currentuserinfo') ) : |
|---|
| 40 | function get_currentuserinfo() { |
|---|
| 41 | global $current_user; |
|---|
| 42 | |
|---|
| 43 | if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) |
|---|
| 44 | return false; |
|---|
| 45 | |
|---|
| 46 | if ( ! empty($current_user) ) |
|---|
| 47 | return; |
|---|
| 48 | |
|---|
| 49 | if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || |
|---|
| 50 | !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { |
|---|
| 51 | wp_set_current_user(0); |
|---|
| 52 | return false; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | $user_login = $_COOKIE[USER_COOKIE]; |
|---|
| 56 | wp_set_current_user(0, $user_login); |
|---|
| 57 | } |
|---|
| 58 | endif; |
|---|
| 59 | |
|---|
| 60 | if ( !function_exists('get_userdata') ) : |
|---|
| 61 | function get_userdata( $user_id ) { |
|---|
| 62 | global $wpdb; |
|---|
| 63 | $user_id = (int) $user_id; |
|---|
| 64 | if ( $user_id == 0 ) |
|---|
| 65 | return false; |
|---|
| 66 | |
|---|
| 67 | $user = wp_cache_get($user_id, 'users'); |
|---|
| 68 | |
|---|
| 69 | if ( $user ) |
|---|
| 70 | return $user; |
|---|
| 71 | |
|---|
| 72 | if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id' LIMIT 1") ) |
|---|
| 73 | return false; |
|---|
| 74 | |
|---|
| 75 | $wpdb->hide_errors(); |
|---|
| 76 | $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'"); |
|---|
| 77 | $wpdb->show_errors(); |
|---|
| 78 | |
|---|
| 79 | if ($metavalues) { |
|---|
| 80 | foreach ( $metavalues as $meta ) { |
|---|
| 81 | $value = maybe_unserialize($meta->meta_value); |
|---|
| 82 | $user->{$meta->meta_key} = $value; |
|---|
| 83 | |
|---|
| 84 | // We need to set user_level from meta, not row |
|---|
| 85 | if ( $wpdb->prefix . 'user_level' == $meta->meta_key ) |
|---|
| 86 | $user->user_level = $meta->meta_value; |
|---|
| 87 | } // end foreach |
|---|
| 88 | } //end if |
|---|
| 89 | |
|---|
| 90 | // For backwards compat. |
|---|
| 91 | if ( isset($user->first_name) ) |
|---|
| 92 | $user->user_firstname = $user->first_name; |
|---|
| 93 | if ( isset($user->last_name) ) |
|---|
| 94 | $user->user_lastname = $user->last_name; |
|---|
| 95 | if ( isset($user->description) ) |
|---|
| 96 | $user->user_description = $user->description; |
|---|
| 97 | |
|---|
| 98 | wp_cache_add($user_id, $user, 'users'); |
|---|
| 99 | wp_cache_add($user->user_login, $user_id, 'userlogins'); |
|---|
| 100 | return $user; |
|---|
| 101 | } |
|---|
| 102 | endif; |
|---|
| 103 | |
|---|
| 104 | if ( !function_exists('update_user_cache') ) : |
|---|
| 105 | function update_user_cache() { |
|---|
| 106 | return true; |
|---|
| 107 | } |
|---|
| 108 | endif; |
|---|
| 109 | |
|---|
| 110 | if ( !function_exists('get_userdatabylogin') ) : |
|---|
| 111 | function get_userdatabylogin($user_login) { |
|---|
| 112 | global $wpdb; |
|---|
| 113 | $user_login = sanitize_user( $user_login ); |
|---|
| 114 | |
|---|
| 115 | if ( empty( $user_login ) ) |
|---|
| 116 | return false; |
|---|
| 117 | |
|---|
| 118 | $user_id = wp_cache_get($user_login, 'userlogins'); |
|---|
| 119 | $userdata = wp_cache_get($user_id, 'users'); |
|---|
| 120 | |
|---|
| 121 | if ( $userdata ) |
|---|
| 122 | return $userdata; |
|---|
| 123 | |
|---|
| 124 | $user_login = $wpdb->escape($user_login); |
|---|
| 125 | |
|---|
| 126 | if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") ) |
|---|
| 127 | return false; |
|---|
| 128 | |
|---|
| 129 | $wpdb->hide_errors(); |
|---|
| 130 | $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'"); |
|---|
| 131 | $wpdb->show_errors(); |
|---|
| 132 | |
|---|
| 133 | if ($metavalues) { |
|---|
| 134 | foreach ( $metavalues as $meta ) { |
|---|
| 135 | $value = maybe_unserialize($meta->meta_value); |
|---|
| 136 | $user->{$meta->meta_key} = $value; |
|---|
| 137 | |
|---|
| 138 | // We need to set user_level from meta, not row |
|---|
| 139 | if ( $wpdb->prefix . 'user_level' == $meta->meta_key ) |
|---|
| 140 | $user->user_level = $meta->meta_value; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | // For backwards compat. |
|---|
| 145 | if ( isset($user->first_name) ) |
|---|
| 146 | $user->user_firstname = $user->first_name; |
|---|
| 147 | if ( isset($user->last_name) ) |
|---|
| 148 | $user->user_lastname = $user->last_name; |
|---|
| 149 | if ( isset($user->description) ) |
|---|
| 150 | $user->user_description = $user->description; |
|---|
| 151 | |
|---|
| 152 | wp_cache_add($user->ID, $user, 'users'); |
|---|
| 153 | wp_cache_add($user->user_login, $user->ID, 'userlogins'); |
|---|
| 154 | return $user; |
|---|
| 155 | |
|---|
| 156 | } |
|---|
| 157 | endif; |
|---|
| 158 | |
|---|
| 159 | if ( !function_exists( 'wp_mail' ) ) : |
|---|
| 160 | function wp_mail($to, $subject, $message, $headers = '') { |
|---|
| 161 | global $phpmailer; |
|---|
| 162 | |
|---|
| 163 | if ( !is_object( $phpmailer ) ) { |
|---|
| 164 | require_once(ABSPATH . WPINC . '/class-phpmailer.php'); |
|---|
| 165 | require_once(ABSPATH . WPINC . '/class-smtp.php'); |
|---|
| 166 | $phpmailer = new PHPMailer(); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | $mail = compact('to', 'subject', 'message', 'headers'); |
|---|
| 170 | $mail = apply_filters('wp_mail', $mail); |
|---|
| 171 | extract($mail, EXTR_SKIP); |
|---|
| 172 | |
|---|
| 173 | if ( $headers == '' ) { |
|---|
| 174 | $headers = "MIME-Version: 1.0\n" . |
|---|
| 175 | "From: " . apply_filters('wp_mail_from', "wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']))) . "\n" . |
|---|
| 176 | "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | $phpmailer->ClearAddresses(); |
|---|
| 180 | $phpmailer->ClearCCs(); |
|---|
| 181 | $phpmailer->ClearBCCs(); |
|---|
| 182 | $phpmailer->ClearReplyTos(); |
|---|
| 183 | $phpmailer->ClearAllRecipients(); |
|---|
| 184 | $phpmailer->ClearCustomHeaders(); |
|---|
| 185 | |
|---|
| 186 | $phpmailer->FromName = "WordPress"; |
|---|
| 187 | $phpmailer->AddAddress("$to", ""); |
|---|
| 188 | $phpmailer->Subject = $subject; |
|---|
| 189 | $phpmailer->Body = $message; |
|---|
| 190 | $phpmailer->IsHTML(false); |
|---|
| 191 | $phpmailer->IsMail(); // set mailer to use php mail() |
|---|
| 192 | |
|---|
| 193 | do_action_ref_array('phpmailer_init', array(&$phpmailer)); |
|---|
| 194 | |
|---|
| 195 | $mailheaders = (array) explode( "\n", $headers ); |
|---|
| 196 | foreach ( $mailheaders as $line ) { |
|---|
| 197 | $header = explode( ":", $line ); |
|---|
| 198 | switch ( trim( $header[0] ) ) { |
|---|
| 199 | case "From": |
|---|
| 200 | $from = trim( str_replace( '"', '', $header[1] ) ); |
|---|
| 201 | if ( strpos( $from, '<' ) ) { |
|---|
| 202 | $phpmailer->FromName = str_replace( '"', '', substr( $header[1], 0, strpos( $header[1], '<' ) - 1 ) ); |
|---|
| 203 | $from = trim( substr( $from, strpos( $from, '<' ) + 1 ) ); |
|---|
| 204 | $from = str_replace( '>', '', $from ); |
|---|
| 205 | } else { |
|---|
| 206 | $phpmailer->FromName = $from; |
|---|
| 207 | } |
|---|
| 208 | $phpmailer->From = trim( $from ); |
|---|
| 209 | break; |
|---|
| 210 | default: |
|---|
| 211 | if ( $line != '' && $header[0] != 'MIME-Version' && $header[0] != 'Content-Type' ) |
|---|
| 212 | $phpmailer->AddCustomHeader( $line ); |
|---|
| 213 | break; |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | $result = @$phpmailer->Send(); |
|---|
| 218 | |
|---|
| 219 | return $result; |
|---|
| 220 | } |
|---|
| 221 | endif; |
|---|
| 222 | |
|---|
| 223 | if ( !function_exists('wp_login') ) : |
|---|
| 224 | function wp_login($username, $password, $already_md5 = false) { |
|---|
| 225 | global $wpdb, $error; |
|---|
| 226 | |
|---|
| 227 | $username = sanitize_user($username); |
|---|
| 228 | |
|---|
| 229 | if ( '' == $username ) |
|---|
| 230 | return false; |
|---|
| 231 | |
|---|
| 232 | if ( '' == $password ) { |
|---|
| 233 | $error = __('<strong>ERROR</strong>: The password field is empty.'); |
|---|
| 234 | return false; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | $login = get_userdatabylogin($username); |
|---|
| 238 | //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'"); |
|---|
| 239 | |
|---|
| 240 | if (!$login) { |
|---|
| 241 | $error = __('<strong>ERROR</strong>: Invalid username.'); |
|---|
| 242 | return false; |
|---|
| 243 | } else { |
|---|
| 244 | // If the password is already_md5, it has been double hashed. |
|---|
| 245 | // Otherwise, it is plain text. |
|---|
| 246 | if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) { |
|---|
| 247 | return true; |
|---|
| 248 | } else { |
|---|
| 249 | $error = __('<strong>ERROR</strong>: Incorrect password.'); |
|---|
| 250 | $pwd = ''; |
|---|
| 251 | return false; |
|---|
| 252 | } |
|---|
| 253 | } |
|---|
| 254 | } |
|---|
| 255 | endif; |
|---|
| 256 | |
|---|
| 257 | if ( !function_exists('is_user_logged_in') ) : |
|---|
| 258 | function is_user_logged_in() { |
|---|
| 259 | $user = wp_get_current_user(); |
|---|
| 260 | |
|---|
| 261 | if ( $user->id == 0 ) |
|---|
| 262 | return false; |
|---|
| 263 | |
|---|
| 264 | return true; |
|---|
| 265 | } |
|---|
| 266 | endif; |
|---|
| 267 | |
|---|
| 268 | if ( !function_exists('auth_redirect') ) : |
|---|
| 269 | function auth_redirect() { |
|---|
| 270 | // Checks if a user is logged in, if not redirects them to the login page |
|---|
| 271 | if ( (!empty($_COOKIE[USER_COOKIE]) && |
|---|
| 272 | !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) || |
|---|
| 273 | (empty($_COOKIE[USER_COOKIE])) ) { |
|---|
| 274 | nocache_headers(); |
|---|
| 275 | |
|---|
| 276 | wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])); |
|---|
| 277 | exit(); |
|---|
| 278 | } |
|---|
| 279 | } |
|---|
| 280 | endif; |
|---|
| 281 | |
|---|
| 282 | if ( !function_exists('check_admin_referer') ) : |
|---|
| 283 | function check_admin_referer($action = -1) { |
|---|
| 284 | $adminurl = strtolower(get_option('siteurl')).'/wp-admin'; |
|---|
| 285 | $referer = strtolower(wp_get_referer()); |
|---|
| 286 | if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) && |
|---|
| 287 | !(-1 == $action && strpos($referer, $adminurl) !== false)) { |
|---|
| 288 | wp_nonce_ays($action); |
|---|
| 289 | die(); |
|---|
| 290 | } |
|---|
| 291 | do_action('check_admin_referer', $action); |
|---|
| 292 | }endif; |
|---|
| 293 | |
|---|
| 294 | if ( !function_exists('check_ajax_referer') ) : |
|---|
| 295 | function check_ajax_referer() { |
|---|
| 296 | $cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie |
|---|
| 297 | foreach ( $cookie as $tasty ) { |
|---|
| 298 | if ( false !== strpos($tasty, USER_COOKIE) ) |
|---|
| 299 | $user = substr(strstr($tasty, '='), 1); |
|---|
| 300 | if ( false !== strpos($tasty, PASS_COOKIE) ) |
|---|
| 301 | $pass = substr(strstr($tasty, '='), 1); |
|---|
| 302 | } |
|---|
| 303 | if ( !wp_login( $user, $pass, true ) ) |
|---|
| 304 | die('-1'); |
|---|
| 305 | do_action('check_ajax_referer'); |
|---|
| 306 | } |
|---|
| 307 | endif; |
|---|
| 308 | |
|---|
| 309 | // Cookie safe redirect. Works around IIS Set-Cookie bug. |
|---|
| 310 | // http://support.microsoft.com/kb/q176113/ |
|---|
| 311 | if ( !function_exists('wp_redirect') ) : |
|---|
| 312 | function wp_redirect($location, $status = 302) { |
|---|
| 313 | global $is_IIS; |
|---|
| 314 | |
|---|
| 315 | $location = apply_filters('wp_redirect', $location, $status); |
|---|
| 316 | |
|---|
| 317 | if ( !$location ) // allows the wp_redirect filter to cancel a redirect |
|---|
| 318 | return false; |
|---|
| 319 | |
|---|
| 320 | $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location); |
|---|
| 321 | $location = wp_kses_no_null($location); |
|---|
| 322 | |
|---|
| 323 | $strip = array('%0d', '%0a'); |
|---|
| 324 | $location = str_replace($strip, '', $location); |
|---|
| 325 | |
|---|
| 326 | if ( $is_IIS ) { |
|---|
| 327 | header("Refresh: 0;url=$location"); |
|---|
| 328 | } else { |
|---|
| 329 | if ( php_sapi_name() != 'cgi-fcgi' ) |
|---|
| 330 | status_header($status); // This causes problems on IIS and some FastCGI setups |
|---|
| 331 | header("Location: $location"); |
|---|
| 332 | } |
|---|
| 333 | } |
|---|
| 334 | endif; |
|---|
| 335 | |
|---|
| 336 | if ( !function_exists('wp_get_cookie_login') ): |
|---|
| 337 | function wp_get_cookie_login() { |
|---|
| 338 | if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ) |
|---|
| 339 | return false; |
|---|
| 340 | |
|---|
| 341 | return array('login' => $_COOKIE[USER_COOKIE], 'password' => $_COOKIE[PASS_COOKIE]); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | endif; |
|---|
| 345 | |
|---|
| 346 | if ( !function_exists('wp_setcookie') ) : |
|---|
| 347 | function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) { |
|---|
| 348 | if ( !$already_md5 ) |
|---|
| 349 | $password = md5( md5($password) ); // Double hash the password in the cookie. |
|---|
| 350 | |
|---|
| 351 | if ( empty($home) ) |
|---|
| 352 | $cookiepath = COOKIEPATH; |
|---|
| 353 | else |
|---|
| 354 | $cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' ); |
|---|
| 355 | |
|---|
| 356 | if ( empty($siteurl) ) { |
|---|
| 357 | $sitecookiepath = SITECOOKIEPATH; |
|---|
| 358 | $cookiehash = COOKIEHASH; |
|---|
| 359 | } else { |
|---|
| 360 | $sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' ); |
|---|
| 361 | $cookiehash = md5($siteurl); |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | if ( $remember ) |
|---|
| 365 | $expire = time() + 31536000; |
|---|
| 366 | else |
|---|
| 367 | $expire = 0; |
|---|
| 368 | |
|---|
| 369 | setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN); |
|---|
| 370 | setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN); |
|---|
| 371 | |
|---|
| 372 | if ( $cookiepath != $sitecookiepath ) { |
|---|
| 373 | setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN); |
|---|
| 374 | setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN); |
|---|
| 375 | } |
|---|
| 376 | } |
|---|
| 377 | endif; |
|---|
| 378 | |
|---|
| 379 | if ( !function_exists('wp_clearcookie') ) : |
|---|
| 380 | function wp_clearcookie() { |
|---|
| 381 | setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
|---|
| 382 | setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
|---|
| 383 | setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
|---|
| 384 | setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
|---|
| 385 | } |
|---|
| 386 | endif; |
|---|
| 387 | |
|---|
| 388 | if ( ! function_exists('wp_notify_postauthor') ) : |
|---|
| 389 | function wp_notify_postauthor($comment_id, $comment_type='') { |
|---|
| 390 | global $wpdb; |
|---|
| 391 | |
|---|
| 392 | $comment = get_comment($comment_id); |
|---|
| 393 | $post = get_post($comment->comment_post_ID); |
|---|
| 394 | $user = get_userdata( $post->post_author ); |
|---|
| 395 | |
|---|
| 396 | if ('' == $user->user_email) return false; // If there's no email to send the comment to |
|---|
| 397 | |
|---|
| 398 | $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
|---|
| 399 | |
|---|
| 400 | $blogname = get_option('blogname'); |
|---|
| 401 | |
|---|
| 402 | if ( empty( $comment_type ) ) $comment_type = 'comment'; |
|---|
| 403 | |
|---|
| 404 | if ('comment' == $comment_type) { |
|---|
| 405 | $notify_message = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; |
|---|
| 406 | $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|---|
| 407 | $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; |
|---|
| 408 | $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
|---|
| 409 | $notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n"; |
|---|
| 410 | $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
|---|
| 411 | $notify_message .= __('You can see all comments on this post here: ') . "\r\n"; |
|---|
| 412 | $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); |
|---|
| 413 | } elseif ('trackback' == $comment_type) { |
|---|
| 414 | $notify_message = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; |
|---|
| 415 | $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|---|
| 416 | $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
|---|
| 417 | $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
|---|
| 418 | $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n"; |
|---|
| 419 | $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); |
|---|
| 420 | } elseif ('pingback' == $comment_type) { |
|---|
| 421 | $notify_message = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; |
|---|
| 422 | $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|---|
| 423 | $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
|---|
| 424 | $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n"; |
|---|
| 425 | $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n"; |
|---|
| 426 | $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); |
|---|
| 427 | } |
|---|
| 428 | $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; |
|---|
| 429 | $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n"; |
|---|
| 430 | $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n"; |
|---|
| 431 | |
|---|
| 432 | $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); |
|---|
| 433 | |
|---|
| 434 | if ( '' == $comment->comment_author ) { |
|---|
| 435 | $from = "From: \"$blogname\" <$wp_email>"; |
|---|
| 436 | if ( '' != $comment->comment_author_email ) |
|---|
| 437 | $reply_to = "Reply-To: $comment->comment_author_email"; |
|---|
| 438 | } else { |
|---|
| 439 | $from = "From: \"$comment->comment_author\" <$wp_email>"; |
|---|
| 440 | if ( '' != $comment->comment_author_email ) |
|---|
| 441 | $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | $message_headers = "MIME-Version: 1.0\n" |
|---|
| 445 | . "$from\n" |
|---|
| 446 | . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
|---|
| 447 | |
|---|
| 448 | if ( isset($reply_to) ) |
|---|
| 449 | $message_headers .= $reply_to . "\n"; |
|---|
| 450 | |
|---|
| 451 | $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id); |
|---|
| 452 | $subject = apply_filters('comment_notification_subject', $subject, $comment_id); |
|---|
| 453 | $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); |
|---|
| 454 | |
|---|
| 455 | @wp_mail($user->user_email, $subject, $notify_message, $message_headers); |
|---|
| 456 | |
|---|
| 457 | return true; |
|---|
| 458 | } |
|---|
| 459 | endif; |
|---|
| 460 | |
|---|
| 461 | /* wp_notify_moderator |
|---|
| 462 | notifies the moderator of the blog (usually the admin) |
|---|
| 463 | about a new comment that waits for approval |
|---|
| 464 | always returns true |
|---|
| 465 | */ |
|---|
| 466 | if ( !function_exists('wp_notify_moderator') ) : |
|---|
| 467 | function wp_notify_moderator($comment_id) { |
|---|
| 468 | global $wpdb; |
|---|
| 469 | |
|---|
| 470 | if( get_option( "moderation_notify" ) == 0 ) |
|---|
| 471 | return true; |
|---|
| 472 | |
|---|
| 473 | $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); |
|---|
| 474 | $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1"); |
|---|
| 475 | |
|---|
| 476 | $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
|---|
| 477 | $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); |
|---|
| 478 | |
|---|
| 479 | $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"; |
|---|
| 480 | $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
|---|
| 481 | $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|---|
| 482 | $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; |
|---|
| 483 | $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; |
|---|
| 484 | $notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n"; |
|---|
| 485 | $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
|---|
| 486 | $notify_message .= sprintf( __('Approve it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "\r\n"; |
|---|
| 487 | $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n"; |
|---|
| 488 | $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n"; |
|---|
| 489 | $notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n"; |
|---|
| 490 | $notify_message .= get_option('siteurl') . "/wp-admin/moderation.php\r\n"; |
|---|
| 491 | |
|---|
| 492 | $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_option('blogname'), $post->post_title ); |
|---|
| 493 | $admin_email = get_option('admin_email'); |
|---|
| 494 | |
|---|
| 495 | $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id); |
|---|
| 496 | $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); |
|---|
| 497 | |
|---|
| 498 | @wp_mail($admin_email, $subject, $notify_message); |
|---|
| 499 | |
|---|
| 500 | return true; |
|---|
| 501 | } |
|---|
| 502 | endif; |
|---|
| 503 | |
|---|
| 504 | if ( !function_exists('wp_new_user_notification') ) : |
|---|
| 505 | function wp_new_user_notification($user_id, $plaintext_pass = '') { |
|---|
| 506 | $user = new WP_User($user_id); |
|---|
| 507 | |
|---|
| 508 | $user_login = stripslashes($user->user_login); |
|---|
| 509 | $user_email = stripslashes($user->user_email); |
|---|
| 510 | |
|---|
| 511 | $message = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n"; |
|---|
| 512 | $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; |
|---|
| 513 | $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n"; |
|---|
| 514 | |
|---|
| 515 | @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message); |
|---|
| 516 | |
|---|
| 517 | if ( empty($plaintext_pass) ) |
|---|
| 518 | return; |
|---|
| 519 | |
|---|
| 520 | $message = sprintf(__('Username: %s'), $user_login) . "\r\n"; |
|---|
| 521 | $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n"; |
|---|
| 522 | $message .= get_option('siteurl') . "/wp-login.php\r\n"; |
|---|
| 523 | |
|---|
| 524 | wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message); |
|---|
| 525 | |
|---|
| 526 | } |
|---|
| 527 | endif; |
|---|
| 528 | |
|---|
| 529 | if ( !function_exists('wp_verify_nonce') ) : |
|---|
| 530 | function wp_verify_nonce($nonce, $action = -1) { |
|---|
| 531 | $user = wp_get_current_user(); |
|---|
| 532 | $uid = (int) $user->id; |
|---|
| 533 | |
|---|
| 534 | $i = ceil(time() / 43200); |
|---|
| 535 | |
|---|
| 536 | //Allow for expanding range, but only do one check if we can |
|---|
| 537 | if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce ) |
|---|
| 538 | return true; |
|---|
| 539 | return false; |
|---|
| 540 | } |
|---|
| 541 | endif; |
|---|
| 542 | |
|---|
| 543 | if ( !function_exists('wp_create_nonce') ) : |
|---|
| 544 | function wp_create_nonce($action = -1) { |
|---|
| 545 | $user = wp_get_current_user(); |
|---|
| 546 | $uid = (int) $user->id; |
|---|
| 547 | |
|---|
| 548 | $i = ceil(time() / 43200); |
|---|
| 549 | |
|---|
| 550 | return substr(wp_hash($i . $action . $uid), -12, 10); |
|---|
| 551 | } |
|---|
| 552 | endif; |
|---|
| 553 | |
|---|
| 554 | if ( !function_exists('wp_salt') ) : |
|---|
| 555 | function wp_salt() { |
|---|
| 556 | $salt = get_option('secret'); |
|---|
| 557 | if ( empty($salt) ) |
|---|
| 558 | $salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH; |
|---|
| 559 | |
|---|
| 560 | return $salt; |
|---|
| 561 | } |
|---|
| 562 | endif; |
|---|
| 563 | |
|---|
| 564 | if ( !function_exists('wp_hash') ) : |
|---|
| 565 | function wp_hash($data) { |
|---|
| 566 | $salt = wp_salt(); |
|---|
| 567 | |
|---|
| 568 | if ( function_exists('hash_hmac') ) { |
|---|
| 569 | return hash_hmac('md5', $data, $salt); |
|---|
| 570 | } else { |
|---|
| 571 | return md5($data . $salt); |
|---|
| 572 | } |
|---|
| 573 | } |
|---|
| 574 | endif; |
|---|
| 575 | |
|---|
| 576 | ?> |
|---|