diff --git a/wp-admin/options-discussion.php b/wp-admin/options-discussion.php
index bd81e5c943..9a97ede469 100644
--- a/wp-admin/options-discussion.php
+++ b/wp-admin/options-discussion.php
@@ -40,6 +40,14 @@ include('admin-header.php');
/>
') ?>
+ ') ?>
+
+ ') ?>
+
diff --git a/wp-admin/options.php b/wp-admin/options.php
index 02a36d1a77..766cfdf67b 100644
--- a/wp-admin/options.php
+++ b/wp-admin/options.php
@@ -23,7 +23,7 @@ wp_reset_vars(array('action'));
$whitelist_options = array(
'general' => array('blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'comment_registration', 'default_role' ),
- 'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'close_comments_for_old_posts', 'close_comments_days_old' ),
+ 'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page' ),
'misc' => array( 'hack_file', 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path' ),
'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
'privacy' => array( 'blog_public' ),
diff --git a/wp-content/themes/default/comments.php b/wp-content/themes/default/comments.php
index 6820449c44..3cd73ee54d 100644
--- a/wp-content/themes/default/comments.php
+++ b/wp-content/themes/default/comments.php
@@ -15,9 +15,12 @@
-
+
comment_status) : ?>
diff --git a/wp-includes/classes.php b/wp-includes/classes.php
index 210272fb26..2241ad8552 100644
--- a/wp-includes/classes.php
+++ b/wp-includes/classes.php
@@ -26,7 +26,7 @@ class WP {
* @access public
* @var array
*/
- var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term');
+ var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage');
/**
* Private query variables.
@@ -36,7 +36,7 @@ class WP {
* @since 2.0.0
* @var array
*/
- var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm');
+ var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');
/**
* Extra query variables set by the user.
@@ -730,6 +730,15 @@ class Walker {
*/
var $db_fields;
+ /**
+ * Max number of pages walked by the paged walker
+ *
+ * @since 2.7.0
+ * @var int
+ * @access protected
+ */
+ var $max_pages = 1;
+
/**
* Starts the list before the elements are added.
*
@@ -947,7 +956,7 @@ class Walker {
function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
/* sanity check */
- if ( empty($elements) || $max_depth < 0 )
+ if ( empty($elements) || $max_depth < -1 )
return '';
$args = array_slice( func_get_args(), 4 );
@@ -956,6 +965,38 @@ class Walker {
$id_field = $this->db_fields['id'];
$parent_field = $this->db_fields['parent'];
+ $count = -1;
+ if ( -1 == $max_depth )
+ $total_top = count( $elements );
+ if ( $page_num < 1 || $per_page < 0 ) {
+ // No paging
+ $paging = false;
+ $start = 0;
+ if ( -1 == $max_depth )
+ $end = $total_top;
+ $this->max_pages = 1;
+ } else {
+ $paging = true;
+ $start = ( (int)$page_num - 1 ) * (int)$per_page;
+ $end = $start + $per_page;
+ if ( -1 == $max_depth )
+ $this->max_pages = ceil($total_top / $per_page);
+ }
+
+ // flat display
+ if ( -1 == $max_depth ) {
+ $empty_array = array();
+ foreach ( $elements as $e ) {
+ $count++;
+ if ( $count < $start )
+ continue;
+ if ( $count >= $end )
+ break;
+ $this->display_element( $e, $empty_array, 1, 0, $args, $output );
+ }
+ return $output;
+ }
+
/*
* seperate elements into two buckets: top level and children elements
* children_elements is two dimensional array, eg.
@@ -970,15 +1011,10 @@ class Walker {
$children_elements[ $e->$parent_field ][] = $e;
}
- $count = -1;
$total_top = count( $top_level_elements );
- if ( $page_num < 1 || $per_page < 0 ) {
- $start = 0;
- $end = $total_top;
- } else {
- $start = ( (int)$page_num - 1 ) * (int)$per_page;
- $end = $start + $per_page;
- }
+
+ if ( $paging )
+ $this->max_pages = ceil($total_top / $per_page);
foreach( $top_level_elements as $e ){
$count++;
@@ -996,7 +1032,7 @@ class Walker {
$this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
}
- if ( $end >= $total_top && count( $children_elements ) > 0 ){
+ if ( $end >= $total_top && count( $children_elements ) > 0 ) {
$empty_array = array();
foreach ( $children_elements as $orphans )
foreach( $orphans as $op )
@@ -1030,7 +1066,8 @@ class Walker {
foreach ( (array)$children_elements[$id] as $child )
$this->unset_children( $child, $children_elements );
- unset( $children_elements[$id] );
+ if ( isset($children_elements[$id]) )
+ unset( $children_elements[$id] );
}
}
diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php
index cf199c0f61..eb1e8811a1 100644
--- a/wp-includes/comment-template.php
+++ b/wp-includes/comment-template.php
@@ -850,7 +850,7 @@ function comment_reply_link($args = array(), $comment = null, $post = null) {
$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);
@@ -973,15 +973,34 @@ class Walker_Comment extends Walker {
* @uses Walker_Comment
*
* @param $args string|array Formatting options
- * @param $comments array Optional array of comment objects. Defaults to $wp_query->comments
+ * @param $comments array Optional array of comment objects. Defaults to $wp_query->comments
*/
function wp_list_comments($args = array(), $comments = null ) {
global $wp_query;
- $defaults = array('walker' => null, 'depth' => 3, 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all');
+ $defaults = array('walker' => null, 'depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
+ 'page' => get_query_var('cpage'), 'per_page' => '');
$r = wp_parse_args( $args, $defaults );
+ if ( '' === $r['per_page'] && get_option('page_comments') )
+ $r['per_page'] = get_query_var('comments_per_page');
+
+ if ( empty($r['per_page']) ) {
+ $r['page'] = 0;
+ } else {
+ $r['page'] = intval($r['page']);
+ if ( empty($r['page']) )
+ $r['page'] = 1;
+ }
+
+ if ( '' === $r['depth'] ) {
+ if ( get_option('thread_comments') )
+ $r['depth'] = get_option('thread_comments_depth');
+ else
+ $r['depth'] = -1;
+ }
+
extract( $r, EXTR_SKIP );
if ( empty($walker) )
@@ -995,19 +1014,25 @@ function wp_list_comments($args = array(), $comments = null ) {
$wp_query->comments_by_type = &separate_comments($wp_query->comments);
if ( empty($wp_query->comments_by_type[$type]) )
return;
- return $walker->walk($wp_query->comments_by_type[$type], $depth, $r);
+ $walker->paged_walk($wp_query->comments_by_type[$type], $depth, $page, $per_page, $r);
+ $wp_query->max_num_comment_pages = $walker->max_pages;
+ return;
}
- $walker->walk($wp_query->comments, $depth, $r);
+ $walker->paged_walk($wp_query->comments, $depth, $page, $per_page, $r);
+ $wp_query->max_num_comment_pages = $walker->max_pages;
} else {
if ( empty($comments) )
return;
if ( 'all' != $type ) {
- $comments_by_type = separate_comments($comments);
+ $comments_by_type = &separate_comments($comments);
if ( empty($comments_by_type[$type]) )
return;
- return $walker->walk($comments_by_type[$type], $depth, $r);
+ $walker->paged_walk($comments_by_type[$type], $depth, $page, $per_page, $r);
+ $wp_query->max_num_comment_pages = $walker->max_pages;
+ return;
}
- $walker->walk($comments, $depth, $r);
+ $walker->paged_walk($comments, $depth, $page, $per_page, $r);
+ $wp_query->max_num_comment_pages = $walker->max_pages;
}
}
diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 20442146a5..9d9a0e97b9 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -1820,6 +1820,9 @@ function sanitize_option($option, $value) {
case 'default_category':
case 'default_email_category':
case 'default_link_category':
+ case 'close_comments_days_old':
+ case 'comments_per_page':
+ case 'thread_comments_depth':
$value = abs((int) $value);
break;
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index d01b96814c..cd149e62ee 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -793,6 +793,84 @@ function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nx
}
}
+function get_comments_pagenum_link($pagenum = 1) {
+ global $wp_rewrite;
+
+ $pagenum = (int) $pagenum;
+
+ $request = remove_query_arg( 'cpage' );
+
+ $home_root = parse_url(get_option('home'));
+ $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
+ $home_root = preg_quote( trailingslashit( $home_root ), '|' );
+
+ $request = preg_replace('|^'. $home_root . '|', '', $request);
+ $request = preg_replace('|^/+|', '', $request);
+
+ $base = trailingslashit( get_bloginfo( 'home' ) );
+
+ if ( $pagenum > 1 ) {
+ $result = add_query_arg( 'cpage', $pagenum, $base . $request );
+ } else {
+ $result = $base . $request;
+ }
+
+ $result = apply_filters('get_comments_pagenum_link', $result);
+
+ return $result;
+}
+
+function next_comments_link($label='', $max_page = 0) {
+ global $wp_query;
+
+ if ( !is_singular() )
+ return;
+
+ $page = get_query_var('cpage');
+
+ if ( !$page )
+ $page = 1;
+
+ if ( !$page )
+ $page = 1;
+
+ $nextpage = intval($page) + 1;
+
+ if ( empty($max_page) )
+ $max_page = $wp_query->max_num_comment_pages;
+
+ if ( $nextpage > $max_page )
+ return;
+
+ if ( empty($label) )
+ $label = __('» Newer Comments');
+
+ echo '". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'';
+}
+
+function previous_comments_link($label='') {
+ global $wp_query;
+
+ if ( !is_singular() )
+ return;
+
+ $page = get_query_var('cpage');
+
+ if ( $page <= 1 )
+ return;
+
+ $nextpage = intval($page) - 1;
+
+ if ( empty($label) )
+ $label = __('« Older Comments');
+
+ echo '". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'';
+}
+
function get_shortcut_link() {
$link = "javascript:
var d=document,
diff --git a/wp-includes/query.php b/wp-includes/query.php
index 1f56a13101..8810541484 100644
--- a/wp-includes/query.php
+++ b/wp-includes/query.php
@@ -843,6 +843,15 @@ class WP_Query {
*/
var $max_num_pages = 0;
+ /**
+ * The amount of comment pages.
+ *
+ * @since 2.7.0
+ * @access public
+ * @var int
+ */
+ var $max_num_comment_pages = 0;
+
/**
* Set if query is single post.
*
@@ -1612,6 +1621,9 @@ class WP_Query {
else if ( $q['posts_per_page'] == 0 )
$q['posts_per_page'] = 1;
+ if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 )
+ $q['comments_per_page'] = get_option('comments_per_page');
+
if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) {
$this->is_page = true;
$this->is_home = false;