From 22eb8b34efe73e8ad11391fd5e4e965a1d0a6d31 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 13 Mar 2014 17:38:51 +0000 Subject: [PATCH] Improve `paginate_links()` performance by not calling `number_format_i18n()` unnecessarily. Fixes #25735 with tests. Props johnpbloch. git-svn-id: https://develop.svn.wordpress.org/trunk@27523 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/general-template.php | 5 ++-- tests/phpunit/tests/general/template.php | 31 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/tests/general/template.php diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 18ffa73a5a..5c4bc7503d 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -2030,9 +2030,8 @@ function paginate_links( $args = '' ) { $page_links[] = ''; endif; for ( $n = 1; $n <= $total; $n++ ) : - $n_display = number_format_i18n($n); if ( $n == $current ) : - $page_links[] = "$n_display"; + $page_links[] = "" . number_format_i18n($n) . ""; $dots = true; else : if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : @@ -2041,7 +2040,7 @@ function paginate_links( $args = '' ) { if ( $add_args ) $link = add_query_arg( $add_args, $link ); $link .= $add_fragment; - $page_links[] = "$n_display"; + $page_links[] = "" . number_format_i18n($n) . ""; $dots = true; elseif ( $dots && !$show_all ) : $page_links[] = '' . __( '…' ) . ''; diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php new file mode 100644 index 0000000000..101118724c --- /dev/null +++ b/tests/phpunit/tests/general/template.php @@ -0,0 +1,31 @@ +i18n_count += 1; + } + + /** + * @ticket 25735 + */ + function test_paginate_links_number_format() { + $this->i18n_count = 0; + add_filter( 'number_format_i18n', array( $this, 'increment_i18n_count' ) ); + paginate_links( array( + 'total' => 100, + 'current' => 50, + 'show_all' => false, + 'prev_next' => true, + 'end_size' => 1, + 'mid_size' => 1, + ) ); + // The links should be: + // < Previous 1 ... 49 50 51 ... 100 Next > + $this->assertEquals( 5, $this->i18n_count ); + remove_filter( 'number_format_i18n', array( $this, 'increment_i18n_count' ) ); + } + +}