WordPressを読む 96-3 /blog/wp-includes/pluggable.php 3
/blog/wp-includes/pluggable.php 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | if ( !function_exists('check_admin_referer') ) : /** * Makes sure that a user was referred from another admin page. * * To avoid security exploits. * * @since 1.2.0 * * @param string $action Action nonce * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5) */ function check_admin_referer($action = -1, $query_arg = '_wpnonce') { if ( -1 == $action ) _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2' ); $adminurl = strtolower(admin_url()); $referer = strtolower(wp_get_referer()); $result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce($_REQUEST[$query_arg], $action) : false; if ( !$result && !(-1 == $action && strpos($referer, $adminurl) === 0) ) { wp_nonce_ays($action); die(); } /** * Fires once the admin request has been validated or not. * * @since 1.5.1 * * @param string $action The nonce action. * @param bool $result Whether the admin request nonce was validated. */ do_action( 'check_admin_referer', $action, $result ); return $result; } endif; if ( !function_exists('check_ajax_referer') ) : /** * Verifies the AJAX request to prevent processing requests external of the blog. * * @since 2.0.3 * * @param string $action Action nonce * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5) */ function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) { $nonce = ''; if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) $nonce = $_REQUEST[ $query_arg ]; elseif ( isset( $_REQUEST['_ajax_nonce'] ) ) $nonce = $_REQUEST['_ajax_nonce']; elseif ( isset( $_REQUEST['_wpnonce'] ) ) $nonce = $_REQUEST['_wpnonce']; $result = wp_verify_nonce( $nonce, $action ); if ( $die && false == $result ) { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) wp_die( -1 ); else die( '-1' ); } /** * Fires once the AJAX request has been validated or not. * * @since 2.1.0 * * @param string $action The AJAX nonce action. * @param bool $result Whether the AJAX request nonce was validated. */ do_action( 'check_ajax_referer', $action, $result ); return $result; } endif; if ( !function_exists('wp_redirect') ) : /** * Redirects to another page. * * @since 1.5.1 * * @param string $location The path to redirect to. * @param int $status Status code to use. * @return bool False if $location is not provided, true otherwise. */ function wp_redirect($location, $status = 302) { global $is_IIS; /** * Filter the redirect location. * * @since 2.1.0 * * @param string $location The path to redirect to. * @param int $status Status code to use. */ $location = apply_filters( 'wp_redirect', $location, $status ); /** * Filter the redirect status code. * * @since 2.3.0 * * @param int $status Status code to use. * @param string $location The path to redirect to. */ $status = apply_filters( 'wp_redirect_status', $status, $location ); if ( ! $location ) return false; $location = wp_sanitize_redirect($location); if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' ) status_header($status); // This causes problems on IIS and some FastCGI setups header("Location: $location", true, $status); return true; } endif; if ( !function_exists('wp_sanitize_redirect') ) : /** * Sanitizes a URL for use in a redirect. * * @since 2.3.0 * * @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', '%0D', '%0A'); $location = _deep_replace($strip, $location); return $location; } endif; if ( !function_exists('wp_safe_redirect') ) : /** * Performs a safe (local) redirect, using wp_redirect(). * * Checks whether the $location is using an allowed host, if it has an absolute * path. A plugin can therefore set or remove allowed host(s) to or from the * list. * * If the host is not allowed, then the redirect is to wp-admin on the siteurl * instead. This prevents malicious redirects which redirect to another host, * but only used in a few places. * * @since 2.3.0 * * @uses wp_validate_redirect() To validate the redirect is to an allowed host. * * @return void Does not return anything **/ 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); $location = wp_validate_redirect($location, admin_url()); wp_redirect($location, $status); } endif; if ( !function_exists('wp_validate_redirect') ) : /** * Validates a URL for use in a redirect. * * Checks whether the $location is using an allowed host, if it has an absolute * path. A plugin can therefore set or remove allowed host(s) to or from the * list. * * If the host is not allowed, then the redirect is to $default supplied * * @since 2.8.1 * * @param string $location The redirect to validate * @param string $default The value to return if $location is not allowed * @return string redirect-sanitized URL **/ function wp_validate_redirect($location, $default = '') { $location = trim( $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; // In php 5 parse_url may fail if the URL query part contains http://, bug #38143 $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location; $lp = parse_url($test); // Give up if malformed URL if ( false === $lp ) return $default; // Allow only http and https schemes. No data:, etc. if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) ) return $default; // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field. if ( isset($lp['scheme']) && !isset($lp['host']) ) return $default; $wpp = parse_url(home_url()); /** * Filter the whitelist of hosts to redirect to. * * @since 2.3.0 * * @param array $hosts An array of allowed hosts. * @param bool|string $host The parsed host; empty if not isset. */ $allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '' ); if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) ) $location = $default; return $location; } endif; if ( ! function_exists('wp_notify_postauthor') ) : /** * Notify an author (and/or others) of a comment/trackback/pingback on a post. * * @since 1.0.0 * * @param int $comment_id Comment ID * @param string $deprecated Not used * @return bool True on completion. False if no email addresses were specified. */ function wp_notify_postauthor( $comment_id, $deprecated = null ) { if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__, '3.8' ); } $comment = get_comment( $comment_id ); if ( empty( $comment ) ) return false; $post = get_post( $comment->comment_post_ID ); $author = get_userdata( $post->post_author ); // Who to notify? By default, just the post author, but others can be added. $emails = array(); if ( $author ) { $emails[] = $author->user_email; } /** * Filter the list of email addresses to receive a comment notification. * * By default, only post authors are notified of comments. This filter allows * others to be added. * * @since 3.7.0 * * @param array $emails An array of email addresses to receive a comment notification. * @param int $comment_id The comment ID. */ $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id ); $emails = array_filter( $emails ); // If there are no addresses to send the comment to, bail. if ( ! count( $emails ) ) { return false; } // Facilitate unsetting below without knowing the keys. $emails = array_flip( $emails ); /** * Filter whether to notify comment authors of their comments on their own posts. * * By default, comment authors aren't notified of their comments on their own * posts. This filter allows you to override that. * * @since 3.8.0 * * @param bool $notify Whether to notify the post author of their own comment. * Default false. * @param int $comment_id The comment ID. */ $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id ); // The comment was left by the author if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { unset( $emails[ $author->user_email ] ); } // The author moderated a comment on their own post if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) { unset( $emails[ $author->user_email ] ); } // The post author is no longer a member of the blog if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { unset( $emails[ $author->user_email ] ); } // If there's no email to send the comment to, bail, otherwise flip array back around for use below if ( ! count( $emails ) ) { return false; } else { $emails = array_flip( $emails ); } $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); switch ( $comment->comment_type ) { case 'trackback': $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; /* translators: 1: website name, 2: author IP, 3: author domain */ $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( __('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"; /* translators: 1: blog name, 2: post title */ $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); break; case 'pingback': $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; /* translators: 1: comment author, 2: author IP, 3: author domain */ $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( __('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"; /* translators: 1: blog name, 2: post title */ $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); break; default: // Comments $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; /* translators: 1: comment author, 2: author IP, 3: author domain */ $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( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%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"; /* translators: 1: blog name, 2: post title */ $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); break; } $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n"; if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) { if ( EMPTY_TRASH_DAYS ) $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; else $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; } $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); if ( '' == $comment->comment_author ) { $from = "From: \"$blogname\" <$wp_email>"; if ( '' != $comment->comment_author_email ) $reply_to = "Reply-To: $comment->comment_author_email"; } 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 = "$from\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; if ( isset($reply_to) ) $message_headers .= $reply_to . "\n"; /** * Filter the comment notification email text. * * @since 1.5.2 * * @param string $notify_message The comment notification email text. * @param int $comment_id Comment ID. */ $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id ); /** * Filter the comment notification email subject. * * @since 1.5.2 * * @param string $subject The comment notification email subject. * @param int $comment_id Comment ID. */ $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id ); /** * Filter the comment notification email headers. * * @since 1.5.2 * * @param string $message_headers Headers for the comment notification email. * @param int $comment_id Comment ID. */ $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id ); foreach ( $emails as $email ) { @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); } return true; } endif; if ( !function_exists('wp_notify_moderator') ) : /** * Notifies the moderator of the blog about a new comment that is awaiting approval. * * @since 1.0.0 * * @uses $wpdb * * @param int $comment_id Comment ID * @return bool Always returns true */ function wp_notify_moderator($comment_id) { global $wpdb; if ( 0 == get_option( 'moderation_notify' ) ) return true; $comment = get_comment($comment_id); $post = get_post($comment->comment_post_ID); $user = get_userdata( $post->post_author ); // Send to the administration and to the post author if the author can modify the comment. $emails = array( get_option( 'admin_email' ) ); if ( user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) $emails[] = $user->user_email; } $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); switch ( $comment->comment_type ) { case 'trackback': $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\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( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; break; case 'pingback': $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\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( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; break; default: // Comments $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $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"; $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n"; $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; break; } $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n"; if ( EMPTY_TRASH_DAYS ) $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; else $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n"; $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); $message_headers = ''; /** * Filter the list of recipients for comment moderation emails. * * @since 3.7.0 * * @param array $emails List of email addresses to notify for comment moderation. * @param int $comment_id Comment ID. */ $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); /** * Filter the comment moderation email text. * * @since 1.5.2 * * @param string $notify_message Text of the comment moderation email. * @param int $comment_id Comment ID. */ $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); /** * Filter the comment moderation email subject. * * @since 1.5.2 * * @param string $subject Subject of the comment moderation email. * @param int $comment_id Comment ID. */ $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); /** * Filter the comment moderation email headers. * * @since 2.8.0 * * @param string $message_headers Headers for the comment moderation email. * @param int $comment_id Comment ID. */ $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); foreach ( $emails as $email ) { @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); } return true; } endif; |