190 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
190 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
191 * correspond to a WP_Comment object, an associative array, or a numeric array, |
191 * correspond to a WP_Comment object, an associative array, or a numeric array, |
192 * respectively. Default OBJECT. |
192 * respectively. Default OBJECT. |
193 * @return WP_Comment|array|null Depends on $output value. |
193 * @return WP_Comment|array|null Depends on $output value. |
194 */ |
194 */ |
195 function get_comment( &$comment = null, $output = OBJECT ) { |
195 function get_comment( $comment = null, $output = OBJECT ) { |
196 if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) { |
196 if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) { |
197 $comment = $GLOBALS['comment']; |
197 $comment = $GLOBALS['comment']; |
198 } |
198 } |
199 |
199 |
200 if ( $comment instanceof WP_Comment ) { |
200 if ( $comment instanceof WP_Comment ) { |
216 * |
216 * |
217 * @param WP_Comment $_comment Comment data. |
217 * @param WP_Comment $_comment Comment data. |
218 */ |
218 */ |
219 $_comment = apply_filters( 'get_comment', $_comment ); |
219 $_comment = apply_filters( 'get_comment', $_comment ); |
220 |
220 |
221 if ( OBJECT == $output ) { |
221 if ( OBJECT === $output ) { |
222 return $_comment; |
222 return $_comment; |
223 } elseif ( ARRAY_A == $output ) { |
223 } elseif ( ARRAY_A === $output ) { |
224 return $_comment->to_array(); |
224 return $_comment->to_array(); |
225 } elseif ( ARRAY_N == $output ) { |
225 } elseif ( ARRAY_N === $output ) { |
226 return array_values( $_comment->to_array() ); |
226 return array_values( $_comment->to_array() ); |
227 } |
227 } |
228 return $_comment; |
228 return $_comment; |
229 } |
229 } |
230 |
230 |
452 * @param int $comment_id Comment ID. |
452 * @param int $comment_id Comment ID. |
453 * @param string $meta_key Metadata name. |
453 * @param string $meta_key Metadata name. |
454 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
454 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
455 * @param bool $unique Optional. Whether the same key should not be added. |
455 * @param bool $unique Optional. Whether the same key should not be added. |
456 * Default false. |
456 * Default false. |
457 * @return int|bool Meta ID on success, false on failure. |
457 * @return int|false Meta ID on success, false on failure. |
458 */ |
458 */ |
459 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) { |
459 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) { |
460 return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); |
460 return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); |
461 } |
461 } |
462 |
462 |
491 * |
491 * |
492 * @param int $comment_id Comment ID. |
492 * @param int $comment_id Comment ID. |
493 * @param string $key Optional. The meta key to retrieve. By default, |
493 * @param string $key Optional. The meta key to retrieve. By default, |
494 * returns data for all keys. |
494 * returns data for all keys. |
495 * @param bool $single Optional. Whether to return a single value. |
495 * @param bool $single Optional. Whether to return a single value. |
496 * This parameter has no effect if $key is not specified. |
496 * This parameter has no effect if `$key` is not specified. |
497 * Default false. |
497 * Default false. |
498 * @return mixed An array if $single is false. The value of meta data field |
498 * @return mixed An array of values if `$single` is false. |
499 * if $single is true. False for an invalid $comment_id. |
499 * The value of meta data field if `$single` is true. |
|
500 * False for an invalid `$comment_id` (non-numeric, zero, or negative value). |
|
501 * An empty string if a valid but non-existing comment ID is passed. |
500 */ |
502 */ |
501 function get_comment_meta( $comment_id, $key = '', $single = false ) { |
503 function get_comment_meta( $comment_id, $key = '', $single = false ) { |
502 return get_metadata( 'comment', $comment_id, $key, $single ); |
504 return get_metadata( 'comment', $comment_id, $key, $single ); |
503 } |
505 } |
504 |
506 |
613 * |
615 * |
614 * @since 1.5.0 |
616 * @since 1.5.0 |
615 * |
617 * |
616 * @param string $author_cookie The comment author name cookie. |
618 * @param string $author_cookie The comment author name cookie. |
617 */ |
619 */ |
618 $comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE[ 'comment_author_' . COOKIEHASH ] ); |
620 $comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE[ 'comment_author_' . COOKIEHASH ] ); |
619 $comment_author = wp_unslash( $comment_author ); |
621 $comment_author = wp_unslash( $comment_author ); |
620 $comment_author = esc_attr( $comment_author ); |
622 $comment_author = esc_attr( $comment_author ); |
|
623 |
621 $_COOKIE[ 'comment_author_' . COOKIEHASH ] = $comment_author; |
624 $_COOKIE[ 'comment_author_' . COOKIEHASH ] = $comment_author; |
622 } |
625 } |
623 |
626 |
624 if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) { |
627 if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) { |
625 /** |
628 /** |
630 * |
633 * |
631 * @since 1.5.0 |
634 * @since 1.5.0 |
632 * |
635 * |
633 * @param string $author_email_cookie The comment author email cookie. |
636 * @param string $author_email_cookie The comment author email cookie. |
634 */ |
637 */ |
635 $comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ); |
638 $comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ); |
636 $comment_author_email = wp_unslash( $comment_author_email ); |
639 $comment_author_email = wp_unslash( $comment_author_email ); |
637 $comment_author_email = esc_attr( $comment_author_email ); |
640 $comment_author_email = esc_attr( $comment_author_email ); |
|
641 |
638 $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] = $comment_author_email; |
642 $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] = $comment_author_email; |
639 } |
643 } |
640 |
644 |
641 if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) { |
645 if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) { |
642 /** |
646 /** |
647 * |
651 * |
648 * @since 1.5.0 |
652 * @since 1.5.0 |
649 * |
653 * |
650 * @param string $author_url_cookie The comment author URL cookie. |
654 * @param string $author_url_cookie The comment author URL cookie. |
651 */ |
655 */ |
652 $comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ); |
656 $comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ); |
653 $comment_author_url = wp_unslash( $comment_author_url ); |
657 $comment_author_url = wp_unslash( $comment_author_url ); |
|
658 |
654 $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] = $comment_author_url; |
659 $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] = $comment_author_url; |
655 } |
660 } |
656 } |
661 } |
657 |
662 |
658 /** |
663 /** |
1252 break; |
1257 break; |
1253 } |
1258 } |
1254 |
1259 |
1255 if ( ! is_array( $col_length ) && (int) $col_length > 0 ) { |
1260 if ( ! is_array( $col_length ) && (int) $col_length > 0 ) { |
1256 $max_length = (int) $col_length; |
1261 $max_length = (int) $col_length; |
1257 } elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && intval( $col_length['length'] ) > 0 ) { |
1262 } elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && (int) $col_length['length'] > 0 ) { |
1258 $max_length = (int) $col_length['length']; |
1263 $max_length = (int) $col_length['length']; |
1259 |
1264 |
1260 if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) { |
1265 if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) { |
1261 $max_length = $max_length - 10; |
1266 $max_length = $max_length - 10; |
1262 } |
1267 } |
1920 * Get unapproved comment author's email. |
1925 * Get unapproved comment author's email. |
1921 * |
1926 * |
1922 * Used to allow the commenter to see their pending comment. |
1927 * Used to allow the commenter to see their pending comment. |
1923 * |
1928 * |
1924 * @since 5.1.0 |
1929 * @since 5.1.0 |
|
1930 * @since 5.7.0 The window within which the author email for an unapproved comment |
|
1931 * can be retrieved was extended to 10 minutes. |
1925 * |
1932 * |
1926 * @return string The unapproved comment author's email (when supplied). |
1933 * @return string The unapproved comment author's email (when supplied). |
1927 */ |
1934 */ |
1928 function wp_get_unapproved_comment_author_email() { |
1935 function wp_get_unapproved_comment_author_email() { |
1929 $commenter_email = ''; |
1936 $commenter_email = ''; |
1931 if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) { |
1938 if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) { |
1932 $comment_id = (int) $_GET['unapproved']; |
1939 $comment_id = (int) $_GET['unapproved']; |
1933 $comment = get_comment( $comment_id ); |
1940 $comment = get_comment( $comment_id ); |
1934 |
1941 |
1935 if ( $comment && hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) { |
1942 if ( $comment && hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) { |
1936 // The comment will only be viewable by the comment author for 1 minute. |
1943 // The comment will only be viewable by the comment author for 10 minutes. |
1937 $comment_preview_expires = strtotime( $comment->comment_date_gmt . '+1 minute' ); |
1944 $comment_preview_expires = strtotime( $comment->comment_date_gmt . '+10 minutes' ); |
1938 |
1945 |
1939 if ( time() < $comment_preview_expires ) { |
1946 if ( time() < $comment_preview_expires ) { |
1940 $commenter_email = $comment->comment_author_email; |
1947 $commenter_email = $comment->comment_author_email; |
1941 } |
1948 } |
1942 } |
1949 } |
2186 $commentdata['user_id'] = $commentdata['user_ID']; |
2193 $commentdata['user_id'] = $commentdata['user_ID']; |
2187 } |
2194 } |
2188 |
2195 |
2189 $prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0; |
2196 $prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0; |
2190 |
2197 |
|
2198 if ( ! isset( $commentdata['comment_author_IP'] ) ) { |
|
2199 $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; |
|
2200 } |
|
2201 |
|
2202 if ( ! isset( $commentdata['comment_agent'] ) ) { |
|
2203 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
2204 } |
|
2205 |
2191 /** |
2206 /** |
2192 * Filters a comment's data before it is sanitized and inserted into the database. |
2207 * Filters a comment's data before it is sanitized and inserted into the database. |
2193 * |
2208 * |
2194 * @since 1.5.0 |
2209 * @since 1.5.0 |
|
2210 * @since 5.6.0 Comment data includes the `comment_agent` and `comment_author_IP` values. |
2195 * |
2211 * |
2196 * @param array $commentdata Comment data. |
2212 * @param array $commentdata Comment data. |
2197 */ |
2213 */ |
2198 $commentdata = apply_filters( 'preprocess_comment', $commentdata ); |
2214 $commentdata = apply_filters( 'preprocess_comment', $commentdata ); |
2199 |
2215 |
2209 |
2225 |
2210 $parent_status = ( $commentdata['comment_parent'] > 0 ) ? wp_get_comment_status( $commentdata['comment_parent'] ) : ''; |
2226 $parent_status = ( $commentdata['comment_parent'] > 0 ) ? wp_get_comment_status( $commentdata['comment_parent'] ) : ''; |
2211 |
2227 |
2212 $commentdata['comment_parent'] = ( 'approved' === $parent_status || 'unapproved' === $parent_status ) ? $commentdata['comment_parent'] : 0; |
2228 $commentdata['comment_parent'] = ( 'approved' === $parent_status || 'unapproved' === $parent_status ) ? $commentdata['comment_parent'] : 0; |
2213 |
2229 |
2214 if ( ! isset( $commentdata['comment_author_IP'] ) ) { |
|
2215 $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; |
|
2216 } |
|
2217 $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] ); |
2230 $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] ); |
2218 |
2231 |
2219 if ( ! isset( $commentdata['comment_agent'] ) ) { |
|
2220 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
2221 } |
|
2222 $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 ); |
2232 $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 ); |
2223 |
2233 |
2224 if ( empty( $commentdata['comment_date'] ) ) { |
2234 if ( empty( $commentdata['comment_date'] ) ) { |
2225 $commentdata['comment_date'] = current_time( 'mysql' ); |
2235 $commentdata['comment_date'] = current_time( 'mysql' ); |
2226 } |
2236 } |
2396 clean_comment_cache( $comment_old->comment_ID ); |
2406 clean_comment_cache( $comment_old->comment_ID ); |
2397 |
2407 |
2398 $comment = get_comment( $comment_old->comment_ID ); |
2408 $comment = get_comment( $comment_old->comment_ID ); |
2399 |
2409 |
2400 /** |
2410 /** |
2401 * Fires immediately before transitioning a comment's status from one to another |
2411 * Fires immediately after transitioning a comment's status from one to another in the database |
2402 * in the database. |
2412 * and removing the comment from the object cache, but prior to all status transition hooks. |
2403 * |
2413 * |
2404 * @since 1.5.0 |
2414 * @since 1.5.0 |
2405 * |
2415 * |
2406 * @param int $comment_id Comment ID. |
2416 * @param int $comment_id Comment ID. |
2407 * @param string|bool $comment_status Current comment status. Possible values include |
2417 * @param string $comment_status Current comment status. Possible values include |
2408 * 'hold', 'approve', 'spam', 'trash', or false. |
2418 * 'hold', '0', 'approve', '1', 'spam', and 'trash'. |
2409 */ |
2419 */ |
2410 do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); |
2420 do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); |
2411 |
2421 |
2412 wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment ); |
2422 wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment ); |
2413 |
2423 |
2711 * check for the rel="pingback" has more overhead than just the header. |
2721 * check for the rel="pingback" has more overhead than just the header. |
2712 * |
2722 * |
2713 * @since 1.5.0 |
2723 * @since 1.5.0 |
2714 * |
2724 * |
2715 * @param string $url URL to ping. |
2725 * @param string $url URL to ping. |
2716 * @param int $deprecated Not Used. |
2726 * @param string $deprecated Not Used. |
2717 * @return string|false String containing URI on success, false on failure. |
2727 * @return string|false String containing URI on success, false on failure. |
2718 */ |
2728 */ |
2719 function discover_pingback_server_uri( $url, $deprecated = '' ) { |
2729 function discover_pingback_server_uri( $url, $deprecated = '' ) { |
2720 if ( ! empty( $deprecated ) ) { |
2730 if ( ! empty( $deprecated ) ) { |
2721 _deprecated_argument( __FUNCTION__, '2.7.0' ); |
2731 _deprecated_argument( __FUNCTION__, '2.7.0' ); |
2795 |
2805 |
2796 /** |
2806 /** |
2797 * Perform all pingbacks, enclosures, trackbacks, and send to pingback services. |
2807 * Perform all pingbacks, enclosures, trackbacks, and send to pingback services. |
2798 * |
2808 * |
2799 * @since 2.1.0 |
2809 * @since 2.1.0 |
2800 * |
2810 * @since 5.6.0 Introduced `do_all_pings` action hook for individual services. |
2801 * @global wpdb $wpdb WordPress database abstraction object. |
|
2802 */ |
2811 */ |
2803 function do_all_pings() { |
2812 function do_all_pings() { |
2804 global $wpdb; |
2813 /** |
2805 |
2814 * Fires immediately after the `do_pings` event to hook services individually. |
2806 // Do pingbacks. |
2815 * |
|
2816 * @since 5.6.0 |
|
2817 */ |
|
2818 do_action( 'do_all_pings' ); |
|
2819 } |
|
2820 |
|
2821 /** |
|
2822 * Perform all pingbacks. |
|
2823 * |
|
2824 * @since 5.6.0 |
|
2825 */ |
|
2826 function do_all_pingbacks() { |
2807 $pings = get_posts( |
2827 $pings = get_posts( |
2808 array( |
2828 array( |
2809 'post_type' => get_post_types(), |
2829 'post_type' => get_post_types(), |
2810 'suppress_filters' => false, |
2830 'suppress_filters' => false, |
2811 'nopaging' => true, |
2831 'nopaging' => true, |
2816 |
2836 |
2817 foreach ( $pings as $ping ) { |
2837 foreach ( $pings as $ping ) { |
2818 delete_post_meta( $ping, '_pingme' ); |
2838 delete_post_meta( $ping, '_pingme' ); |
2819 pingback( null, $ping ); |
2839 pingback( null, $ping ); |
2820 } |
2840 } |
2821 |
2841 } |
2822 // Do enclosures. |
2842 |
|
2843 /** |
|
2844 * Perform all enclosures. |
|
2845 * |
|
2846 * @since 5.6.0 |
|
2847 */ |
|
2848 function do_all_enclosures() { |
2823 $enclosures = get_posts( |
2849 $enclosures = get_posts( |
2824 array( |
2850 array( |
2825 'post_type' => get_post_types(), |
2851 'post_type' => get_post_types(), |
2826 'suppress_filters' => false, |
2852 'suppress_filters' => false, |
2827 'nopaging' => true, |
2853 'nopaging' => true, |
2832 |
2858 |
2833 foreach ( $enclosures as $enclosure ) { |
2859 foreach ( $enclosures as $enclosure ) { |
2834 delete_post_meta( $enclosure, '_encloseme' ); |
2860 delete_post_meta( $enclosure, '_encloseme' ); |
2835 do_enclose( null, $enclosure ); |
2861 do_enclose( null, $enclosure ); |
2836 } |
2862 } |
2837 |
2863 } |
2838 // Do trackbacks. |
2864 |
|
2865 /** |
|
2866 * Perform all trackbacks. |
|
2867 * |
|
2868 * @since 5.6.0 |
|
2869 */ |
|
2870 function do_all_trackbacks() { |
2839 $trackbacks = get_posts( |
2871 $trackbacks = get_posts( |
2840 array( |
2872 array( |
2841 'post_type' => get_post_types(), |
2873 'post_type' => get_post_types(), |
2842 'suppress_filters' => false, |
2874 'suppress_filters' => false, |
2843 'nopaging' => true, |
2875 'nopaging' => true, |
3230 function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) { |
3259 function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) { |
3231 global $wpdb; |
3260 global $wpdb; |
3232 |
3261 |
3233 $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); |
3262 $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); |
3234 if ( ! empty( $non_cached_ids ) ) { |
3263 if ( ! empty( $non_cached_ids ) ) { |
3235 $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); |
3264 $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); |
3236 |
3265 |
3237 update_comment_cache( $fresh_comments, $update_meta_cache ); |
3266 update_comment_cache( $fresh_comments, $update_meta_cache ); |
3238 } |
3267 } |
3239 } |
3268 } |
3240 |
3269 |