ping_status );
+
+ /**
+ * Filter whether the current post is open for pings.
+ *
+ * @since 2.5.0
+ *
+ * @param bool $open Whether the current post is open for pings.
+ * @param int|WP_Post $post_id The post ID or WP_Post object.
+ */
return apply_filters( 'pings_open', $open, $post_id );
}
@@ -1011,7 +1121,8 @@ function wp_comment_form_unfiltered_html_nonce() {
* @since 1.5.0
*
* @param string $file Optional. The file to load. Default '/comments.php'.
- * @param bool $separate_comments Optional. Whether to separate the comments by comment type. Default false.
+ * @param bool $separate_comments Optional. Whether to separate the comments by comment type.
+ * Default false.
* @return null Returns null if no comments appear.
*/
function comments_template( $file = '/comments.php', $separate_comments = false ) {
@@ -1025,45 +1136,51 @@ function comments_template( $file = '/comments.php', $separate_comments = false
$req = get_option('require_name_email');
- /**
+ /*
* Comment author information fetched from the comment cookies.
- *
- * @uses wp_get_current_commenter()
+ * Uuses wp_get_current_commenter().
*/
$commenter = wp_get_current_commenter();
- /**
+ /*
* The name of the current comment author escaped for use in attributes.
+ * Escaped by sanitize_comment_cookies().
*/
- $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies()
+ $comment_author = $commenter['comment_author'];
- /**
+ /*
* The email address of the current comment author escaped for use in attributes.
+ * Escaped by sanitize_comment_cookies().
*/
- $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies()
+ $comment_author_email = $commenter['comment_author_email'];
- /**
+ /*
* The url of the current comment author escaped for use in attributes.
*/
$comment_author_url = esc_url($commenter['comment_author_url']);
- /** @todo Use API instead of SELECTs. */
- if ( $user_ID) {
- $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, $user_ID));
- } else if ( empty($comment_author) ) {
- $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
- } else {
- $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
+ $comment_args = array(
+ 'order' => 'ASC',
+ 'orderby' => 'comment_date_gmt',
+ 'status' => 'approve',
+ 'post_id' => $post->ID,
+ );
+
+ if ( $user_ID ) {
+ $comment_args['include_unapproved'] = array( $user_ID );
+ } else if ( ! empty( $comment_author_email ) ) {
+ $comment_args['include_unapproved'] = array( $comment_author_email );
}
- // keep $comments for legacy's sake
+ $comments = get_comments( $comment_args );
+
/**
* Filter the comments array.
*
* @since 2.1.0
*
- * @param array $comments The array of comments supplied to the comments template.
- * @param int $post->ID The post ID.
+ * @param array $comments Array of comments supplied to the comments template.
+ * @param int $post_ID Post ID.
*/
$wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
$comments = &$wp_query->comments;
@@ -1136,19 +1253,22 @@ function comments_popup_script( $width = 400, $height = 400, $file = '' ) {
/**
* Displays the link to the comments popup window for the current post ID.
*
- * Is not meant to be displayed on single posts and pages. Should be used on the
- * lists of posts
+ * Is not meant to be displayed on single posts and pages. Should be used
+ * on the lists of posts
*
* @global string $wpcommentspopupfile The URL to use for the popup window.
* @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
*
* @since 0.71
*
- * @param string $zero Optional. The string to display when no comments. Default false.
- * @param string $one Optional. The string to display when only one comment is available. Default false.
- * @param string $more Optional. The string to display when there are more than one comment. Default false.
- * @param string $css_class Optional. The CSS class to use for comments. Default empty.
- * @param string $none Optional. The string to display when comments have been turned off. Default false.
+ * @param string $zero Optional. String to display when no comments. Default false.
+ * @param string $one Optional. String to display when only one comment is available.
+ * Default false.
+ * @param string $more Optional. String to display when there are more than one comment.
+ * Default false.
+ * @param string $css_class Optional. CSS class to use for comments. Default empty.
+ * @param string $none Optional. String to display when comments have been turned off.
+ * Default false.
* @return null Returns null on single posts and pages.
*/
function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
@@ -1217,70 +1337,95 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
* @param array $args {
* Optional. Override default arguments.
*
- * @type string 'add_below' The first part of the selector used to identify the comment to respond below. The resulting
- * value is passed as the first parameter to addComment.moveForm(), concatenated
- * as $add_below-$comment->comment_ID. Default 'comment'.
- * @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(),
- * and appended to the link URL as a hash value. Default 'respond'.
- * @type string 'reply_text' The text of the Reply link. Default 'Reply'.
- * @type string 'login_text' The text of the link to reply if logged out. Default 'Log in to Reply'.
- * @type int 'depth' The depth of the new comment. Must be greater than 0 and less than the value of the 'thread_comments_depth'
- * option set in Settings > Discussion.
- * Default 0.
- * @type string 'before' The text or HTML to add before the reply link. Default empty.
- * @type string 'after' The text or HTML to add after the reply link. Default empty.
+ * @type string $add_below The first part of the selector used to identify the comment to respond below.
+ * The resulting value is passed as the first parameter to addComment.moveForm(),
+ * concatenated as $add_below-$comment->comment_ID. Default 'comment'.
+ * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
+ * to addComment.moveForm(), and appended to the link URL as a hash value.
+ * Default 'respond'.
+ * @type string $reply_text The text of the Reply link. Default 'Reply'.
+ * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
+ * @type int $depth' The depth of the new comment. Must be greater than 0 and less than the value
+ * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
+ * @type string $before The text or HTML to add before the reply link. Default empty.
+ * @type string $after The text or HTML to add after the reply link. Default empty.
* }
- * @param int $comment Optional. Comment being replied to. Default current comment.
- * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
- * @return mixed Link to show comment form, if successful. False, if comments are closed.
+ * @param int $comment Comment being replied to. Default current comment.
+ * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
+ * Default current post.
+ * @return null|false|string Link to show comment form, if successful. False, if comments are closed.
*/
-function get_comment_reply_link($args = array(), $comment = null, $post = null) {
+function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
$defaults = array(
- 'add_below' => 'comment',
- 'respond_id' => 'respond',
- 'reply_text' => __('Reply'),
- 'login_text' => __('Log in to Reply'),
- 'depth' => 0,
- 'before' => '',
- 'after' => ''
+ 'add_below' => 'comment',
+ 'respond_id' => 'respond',
+ 'reply_text' => __( 'Reply' ),
+ 'reply_to_text' => __( 'Reply to %s' ),
+ 'login_text' => __( 'Log in to Reply' ),
+ 'depth' => 0,
+ 'before' => '',
+ 'after' => ''
);
- $args = wp_parse_args($args, $defaults);
+ $args = wp_parse_args( $args, $defaults );
- if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
+ if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
return;
+ }
- extract($args, EXTR_SKIP);
+ $comment = get_comment( $comment );
- $comment = get_comment($comment);
- if ( empty($post) )
+ if ( empty( $post ) ) {
$post = $comment->comment_post_ID;
- $post = get_post($post);
+ }
- if ( !comments_open($post->ID) )
- return false;
+ $post = get_post( $post );
- $link = '';
+ if ( ! comments_open( $post->ID ) ) {
+ return false;
+ }
- if ( get_option('comment_registration') && ! is_user_logged_in() )
- $link = '';
- else
- $link = "";
+ /**
+ * Filter the comment reply link arguments.
+ *
+ * @since 4.1.0
+ *
+ * @param array $args Comment reply link arguments. See {@see get_comment_reply_link()}
+ * for more information on accepted arguments.
+ * @param object $comment The object of the comment being replied to.
+ * @param WP_Post $post The {@see WP_Post} object.
+ */
+ $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );
+ if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
+ $link = sprintf( '',
+ esc_url( wp_login_url( get_permalink() ) ),
+ $args['login_text']
+ );
+ } else {
+ $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
+ $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID
+ );
+
+ $link = sprintf( "",
+ esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $args['respond_id'],
+ $onclick,
+ esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
+ $args['reply_text']
+ );
+ }
/**
* Filter the comment reply link.
*
* @since 2.7.0
*
- * @param string $before Text or HTML displayed before the reply link.
* @param string $link The HTML markup for the comment reply link.
- * @param string $after Text or HTML displayed after the reply link.
* @param array $args An array of arguments overriding the defaults.
* @param object $comment The object of the comment being replied.
* @param WP_Post $post The WP_Post object.
*/
- return apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post );
+ return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
}
/**
@@ -1288,9 +1433,12 @@ function get_comment_reply_link($args = array(), $comment = null, $post = null)
*
* @since 2.7.0
*
- * @param array $args Optional. Override default options, @see get_comment_reply_link()
- * @param int $comment Optional. Comment being replied to. Default current comment.
- * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
+ * @see get_comment_reply_link()
+ *
+ * @param array $args Optional. Override default options.
+ * @param int $comment Comment being replied to. Default current comment.
+ * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
+ * Default current post.
* @return mixed Link to show comment form, if successful. False, if comments are closed.
*/
function comment_reply_link($args = array(), $comment = null, $post = null) {
@@ -1305,18 +1453,20 @@ function comment_reply_link($args = array(), $comment = null, $post = null) {
* @param array $args {
* Optional. Override default arguments.
*
- * @type string 'add_below' The first part of the selector used to identify the comment to respond below.
- * The resulting value is passed as the first parameter to addComment.moveForm(),
- * concatenated as $add_below-$comment->comment_ID. Default is 'post'.
- * @type string 'respond_id' The selector identifying the responding comment. Passed as the third parameter
- * to addComment.moveForm(), and appended to the link URL as a hash value. Default is 'respond'.
- * @type string 'reply_text' The text of the Reply link. Default is 'Leave a Comment'.
- * @type string 'login_text' The text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
- * @type string 'before' The text or HTML to add before the reply link. Default empty.
- * @type string 'after' The text or HTML to add after the reply link. Default empty.
+ * @type string $add_below The first part of the selector used to identify the comment to respond below.
+ * The resulting value is passed as the first parameter to addComment.moveForm(),
+ * concatenated as $add_below-$comment->comment_ID. Default is 'post'.
+ * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
+ * to addComment.moveForm(), and appended to the link URL as a hash value.
+ * Default 'respond'.
+ * @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'.
+ * @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
+ * @type string $before Text or HTML to add before the reply link. Default empty.
+ * @type string $after Text or HTML to add after the reply link. Default empty.
* }
- * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
- * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.
+ * Default current post.
+ * @return false|null|string Link to show comment form, if successful. False, if comments are closed.
*/
function get_post_reply_link($args = array(), $post = null) {
$defaults = array(
@@ -1329,18 +1479,30 @@ function get_post_reply_link($args = array(), $post = null) {
);
$args = wp_parse_args($args, $defaults);
- extract($args, EXTR_SKIP);
+
$post = get_post($post);
- if ( !comments_open($post->ID) )
+ if ( ! comments_open( $post->ID ) ) {
return false;
+ }
- if ( get_option('comment_registration') && ! is_user_logged_in() )
- $link = '' . $login_text . '';
- else
- $link = "";
-
- $formatted_link = $before . $link . $after;
+ if ( get_option('comment_registration') && ! is_user_logged_in() ) {
+ $link = sprintf( '%s',
+ wp_login_url( get_permalink() ),
+ $args['login_text']
+ );
+ } else {
+ $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',
+ $args['add_below'], $post->ID, $args['respond_id']
+ );
+
+ $link = sprintf( "",
+ get_permalink( $post->ID ) . '#' . $args['respond_id'],
+ $onclick,
+ $args['reply_text']
+ );
+ }
+ $formatted_link = $args['before'] . $link . $args['after'];
/**
* Filter the formatted post comments link HTML.
*
@@ -1357,8 +1519,11 @@ function get_post_reply_link($args = array(), $post = null) {
*
* @since 2.7.0
*
- * @param array $args Optional. Override default options, @see get_post_reply_link()
- * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. Default current post.
+ * @see get_post_reply_link()
+ *
+ * @param array $args Optional. Override default options,
+ * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
+ * Default current post.
* @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
*/
function post_reply_link($args = array(), $post = null) {
@@ -1386,8 +1551,8 @@ function get_cancel_comment_reply_link( $text = '' ) {
* @since 2.7.0
*
* @param string $formatted_link The HTML-formatted cancel comment reply link.
- * @param string $link The cancel comment reply link URL.
- * @param string $text The cancel comment reply link text.
+ * @param string $link Cancel comment reply link URL.
+ * @param string $text Cancel comment reply link text.
*/
return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
}
@@ -1445,14 +1610,17 @@ function comment_id_fields( $id = 0 ) {
/**
* Display text based on comment reply status.
*
- * Only affects users with Javascript disabled.
+ * Only affects users with JavaScript disabled.
*
* @since 2.7.0
*
- * @param string $noreplytext Optional. Text to display when not replying to a comment. Default false.
+ * @param string $noreplytext Optional. Text to display when not replying to a comment.
+ * Default false.
* @param string $replytext Optional. Text to display when replying to a comment.
- * Default false. Accepts "%s" for the author of the comment being replied to.
- * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment. Default true.
+ * Default false. Accepts "%s" for the author of the comment
+ * being replied to.
+ * @param string $linktoparent Optional. Boolean to control making the author's name a link
+ * to their comment. Default true.
*/
function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
global $comment;
@@ -1474,7 +1642,6 @@ function comment_form_title( $noreplytext = false, $replytext = false, $linktopa
/**
* HTML comment list class.
*
- * @package WordPress
* @uses Walker
* @since 2.7.0
*/
@@ -1487,7 +1654,7 @@ class Walker_Comment extends Walker {
* @since 2.7.0
* @var string
*/
- var $tree_type = 'comment';
+ public $tree_type = 'comment';
/**
* DB fields to use.
@@ -1497,7 +1664,7 @@ class Walker_Comment extends Walker {
* @since 2.7.0
* @var array
*/
- var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
+ public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
/**
* Start the list before the elements are added.
@@ -1510,7 +1677,7 @@ class Walker_Comment extends Walker {
* @param int $depth Depth of comment.
* @param array $args Uses 'style' argument for type of HTML list.
*/
- function start_lvl( &$output, $depth = 0, $args = array() ) {
+ public function start_lvl( &$output, $depth = 0, $args = array() ) {
$GLOBALS['comment_depth'] = $depth + 1;
switch ( $args['style'] ) {
@@ -1519,8 +1686,8 @@ class Walker_Comment extends Walker {
case 'ol':
$output .= '' . "\n";
break;
- default:
case 'ul':
+ default:
$output .= '' . "\n";
break;
}
@@ -1537,7 +1704,7 @@ class Walker_Comment extends Walker {
* @param int $depth Depth of comment.
* @param array $args Will only append content if style argument value is 'ol' or 'ul'.
*/
- function end_lvl( &$output, $depth = 0, $args = array() ) {
+ public function end_lvl( &$output, $depth = 0, $args = array() ) {
$GLOBALS['comment_depth'] = $depth + 1;
switch ( $args['style'] ) {
@@ -1546,8 +1713,8 @@ class Walker_Comment extends Walker {
case 'ol':
$output .= "
\n";
break;
- default:
case 'ul':
+ default:
$output .= "\n";
break;
}
@@ -1573,6 +1740,7 @@ class Walker_Comment extends Walker {
* 2.2
*
* @see Walker::display_element()
+ * @see wp_list_comments()
*
* @since 2.7.0
*
@@ -1580,11 +1748,11 @@ class Walker_Comment extends Walker {
* @param array $children_elements List of elements to continue traversing.
* @param int $max_depth Max depth to traverse.
* @param int $depth Depth of current element.
- * @param array $args An array of arguments. @see wp_list_comments()
+ * @param array $args An array of arguments.
* @param string $output Passed by reference. Used to append additional content.
* @return null Null on failure with no changes to parameters.
*/
- function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
+ public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
if ( !$element )
return;
@@ -1608,16 +1776,17 @@ class Walker_Comment extends Walker {
/**
* Start the element output.
*
- * @see Walker::start_el()
- *
* @since 2.7.0
*
+ * @see Walker::start_el()
+ * @see wp_list_comments()
+ *
* @param string $output Passed by reference. Used to append additional content.
* @param object $comment Comment data object.
* @param int $depth Depth of comment in reference to parents.
- * @param array $args An array of arguments. @see wp_list_comments()
+ * @param array $args An array of arguments.
*/
- function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
+ public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
$depth++;
$GLOBALS['comment_depth'] = $depth;
$GLOBALS['comment'] = $comment;
@@ -1647,16 +1816,17 @@ class Walker_Comment extends Walker {
/**
* Ends the element output, if needed.
*
- * @see Walker::end_el()
- *
* @since 2.7.0
*
+ * @see Walker::end_el()
+ * @see wp_list_comments()
+ *
* @param string $output Passed by reference. Used to append additional content.
* @param object $comment The comment object. Default current comment.
* @param int $depth Depth of comment.
- * @param array $args An array of arguments. @see wp_list_comments()
+ * @param array $args An array of arguments.
*/
- function end_el( &$output, $comment, $depth = 0, $args = array() ) {
+ public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
if ( !empty( $args['end-callback'] ) ) {
ob_start();
call_user_func( $args['end-callback'], $comment, $args, $depth );
@@ -1675,9 +1845,11 @@ class Walker_Comment extends Walker {
* @access protected
* @since 3.6.0
*
+ * @see wp_list_comments()
+ *
* @param object $comment The comment object.
* @param int $depth Depth of comment.
- * @param array $args An array of arguments. @see wp_list_comments()
+ * @param array $args An array of arguments.
*/
protected function ping( $comment, $depth, $args ) {
$tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
@@ -1695,9 +1867,11 @@ class Walker_Comment extends Walker {
* @access protected
* @since 3.6.0
*
+ * @see wp_list_comments()
+ *
* @param object $comment Comment to display.
* @param int $depth Depth of comment.
- * @param array $args An array of arguments. @see wp_list_comments()
+ * @param array $args An array of arguments.
*/
protected function comment( $comment, $depth, $args ) {
if ( 'div' == $args['style'] ) {
@@ -1708,7 +1882,7 @@ class Walker_Comment extends Walker {
$add_below = 'div-comment';
}
?>
- < id="comment-">
+ < has_children ? 'parent' : '' ); ?> id="comment-">
@@ -1721,7 +1895,7 @@ class Walker_Comment extends Walker {
-
' . ' ' . '
', 'email' => '' . - '
', + '', 'url' => '' . '
', ); @@ -1995,13 +2199,17 @@ function comment_form( $args = array(), $post_id = null ) { $fields = apply_filters( 'comment_form_default_fields', $fields ); $defaults = array( 'fields' => $fields, - 'comment_field' => '' . sprintf( __( 'You must be logged in to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '
', + /** This filter is documented in wp-includes/link-template.php */ 'logged_in_as' => '' . sprintf( __( 'Logged in as %2$s. Log out?' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '
', - 'comment_notes_before' => '' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '
', - 'comment_notes_after' => '' . sprintf( __( 'You may use these HTML tags and attributes: %s' ), '
', + 'comment_notes_before' => '' . allowed_tags() . '
' ) . '' . __( 'Your email address will not be published.' ) . ''. ( $req ? $required_text : '' ) . '
', + 'comment_notes_after' => '' . sprintf( __( 'You may use these HTML tags and attributes: %s' ), '
', 'id_form' => 'commentform', 'id_submit' => 'submit', + 'class_submit' => 'submit', + 'name_submit' => 'submit', 'title_reply' => __( 'Leave a Reply' ), 'title_reply_to' => __( 'Leave a Reply to %s' ), 'cancel_reply_link' => __( 'Cancel reply' ), @@ -2046,7 +2254,7 @@ function comment_form( $args = array(), $post_id = null ) {' . allowed_tags() . '
' ) . '