Index: general-template.php
===================================================================
--- general-template.php	(revision 46405)
+++ general-template.php	(working copy)
@@ -1022,10 +1022,11 @@
  *
  * @global int $page  Page number of a single post.
  * @global int $paged Page number of a list of posts.
- *
+ * 
+ * @param string $sep 
  * @return string Tag with the document title.
  */
-function wp_get_document_title() {
+function wp_get_document_title($sep = '-') {
 
 	/**
 	 * Filters the document title before it is generated.
@@ -1116,7 +1117,7 @@
 	 *
 	 * @param string $sep Document title separator. Default '-'.
 	 */
-	$sep = apply_filters( 'document_title_separator', '-' );
+	$sep = apply_filters( 'document_title_separator', $sep );
 
 	/**
 	 * Filters the parts of the document title.
@@ -3970,21 +3971,68 @@
 }
 
 /**
- * Retrieve paginated link for archive post pages.
+ * Get default values based on the current URL
  *
- * Technically, the function can be used to create paginated link list for any
- * area. The 'base' argument is used to reference the url, which will be used to
- * create the paginated links. The 'format' argument is then used for replacing
- * the page number. It is however, most likely and by default, to be used on the
- * archive post pages.
+ * @param bool $get_all	Return a full modified array of $url_parts
+ * @return string|array
+ */
+function default_paginate_base( bool $get_all = false ) {
+	// Setting up default values based on the current URL.
+	$base = html_entity_decode( get_pagenum_link() );
+	$url_parts = explode( '?', $base );
+	$url_parts[0] = trailingslashit( $url_parts[0] ) . '%_%';
+	
+	// Append the format placeholder to the base URL.
+	return $get_all ? $url_parts : $url_parts[0];
+}
+
+/**
+ * Get URL base depends on permalink settings
  *
- * The 'type' argument controls format of the returned value. The default is
- * 'plain', which is just a string with the links separated by a newline
- * character. The other possible values are either 'array' or 'list'. The
- * 'array' value will return an array of the paginated link list to offer full
- * control of display. The 'list' value will place all of the paginated links in
- * an unordered HTML list.
+ * @return string
+ */
+function default_paginate_format():string {
+	global $wp_rewrite;
+
+	$format = $wp_rewrite->using_index_permalinks() && ! strpos( $base, 'index.php' ) ? 'index.php/' : '';
+	$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
+
+	return $format;
+}
+
+/**
+ * Return a proper URL from given base, format, current page.
  *
+ * @param int $page			
+ * @param string $format	
+ * @param string $base		
+ * @param array $args		
+ * @param string $fragment	
+ * @return string			
+ */
+function format_paginate_link( int $page, $base = null, $format = null, array $args = [], string $fragment = '' ):string {
+	$base = $base ?: default_paginate_base();
+	$format = $format ?: default_paginate_format();
+
+	$link = str_replace( '%_%', $format, $base);
+	$link = str_replace( '%#%', $page, $link );
+	if ( $args ) {
+		$link = add_query_arg( $args, $link );
+	}
+	$link .= $fragment;
+	
+	return esc_url( apply_filters( 'paginate_links', $link ) );
+}
+
+/**
+ * Retrieve paginated links in array for archive post pages.
+ * 
+ * Technically, the function can be used to create paginated links in array for
+ * any area. The 'base' argument is used to reference the url, which will be
+ * used to create the paginated links. The 'format' argument is then used for
+ * replacing the page number. It is however, most likely and by default, to be
+ * used on the archive post pages.
+ * 
  * The 'total' argument is the total amount of pages and is an integer. The
  * 'current' argument is the current page number and is also an integer.
  *
@@ -4009,19 +4057,10 @@
  * It is possible to add query vars to the link by using the 'add_args' argument
  * and see add_query_arg() for more information.
  *
- * The 'before_page_number' and 'after_page_number' arguments allow users to
- * augment the links themselves. Typically this might be to add context to the
- * numbered links so that screen reader users understand what the links are for.
- * The text strings are added before and after the page number - within the
- * anchor tag.
- *
- * @since 2.1.0
- * @since 4.9.0 Added the `aria_current` argument.
- *
  * @global WP_Query   $wp_query   WordPress Query object.
  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  *
- * @param string|array $args {
+ * @param array $args	{
  *     Optional. Array or string of arguments for generating paginated links for archives.
  *
  *     @type string $base               Base of the paginated url. Default empty.
@@ -4029,7 +4068,6 @@
  *     @type int    $total              The total amount of pages. Default is the value WP_Query's
  *                                      `max_num_pages` or 1.
  *     @type int    $current            The current page number. Default is 'paged' query var or 1.
- *     @type string $aria_current       The value for the aria-current attribute. Possible values are 'page',
  *                                      'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
  *     @type bool   $show_all           Whether to show all pages. Default false.
  *     @type int    $end_size           How many numbers on either the start and the end list edges.
@@ -4036,58 +4074,51 @@
  *                                      Default 1.
  *     @type int    $mid_size           How many numbers to either side of the current pages. Default 2.
  *     @type bool   $prev_next          Whether to include the previous and next links in the list. Default true.
- *     @type bool   $prev_text          The previous page text. Default '&laquo; Previous'.
- *     @type bool   $next_text          The next page text. Default 'Next &raquo;'.
- *     @type string $type               Controls format of the returned value. Possible values are 'plain',
- *                                      'array' and 'list'. Default is 'plain'.
  *     @type array  $add_args           An array of query args to add. Default false.
  *     @type string $add_fragment       A string to append to each link. Default empty.
- *     @type string $before_page_number A string to appear before the page number. Default empty.
- *     @type string $after_page_number  A string to append after the page number. Default empty.
  * }
- * @return string|array|void String of page links or array of page links.
+ * @return array|void	Void value is return if total is less than 2. Otherwise, an informative array is returned.
  */
-function paginate_links( $args = '' ) {
-	global $wp_query, $wp_rewrite;
+function paginate_array( array $args = [] ) {
+	if ( empty( $args['base'] ) ) :
+		$url_parts = default_paginate_base(true);
+		$base = $url_parts[0];
+	else:
+		$base = $args['base'];
+	endif;
 
-	// Setting up default values based on the current URL.
-	$pagenum_link = html_entity_decode( get_pagenum_link() );
-	$url_parts    = explode( '?', $pagenum_link );
+	if ( empty( $args['total'] ) ) :
+		global $wp_query;
+		$total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
+	else:
+		$total = $args['total'];
+	endif;
 
-	// Get max pages and current page out of the current query, if available.
-	$total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
-	$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
+	if ( empty( $args['current'] ) ) :
+		global $wp_query;
+		$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
+	else:
+		$current = $args['current'];
+	endif;
 
-	// Append the format placeholder to the base URL.
-	$pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
-
-	// URL base depends on permalink settings.
-	$format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
-	$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
-
-	$defaults = array(
-		'base'               => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
-		'format'             => $format, // ?page=%#% : %#% is replaced by the page number
+	$defaults = [
+		'base'               => $base,
+		'format'             => empty( $args['format'] ) ? default_paginate_format() : $args['format'],
 		'total'              => $total,
 		'current'            => $current,
-		'aria_current'       => 'page',
 		'show_all'           => false,
 		'prev_next'          => true,
-		'prev_text'          => __( '&laquo; Previous' ),
-		'next_text'          => __( 'Next &raquo;' ),
 		'end_size'           => 1,
 		'mid_size'           => 2,
-		'type'               => 'plain',
-		'add_args'           => array(), // array of query args to add
-		'add_fragment'       => '',
-		'before_page_number' => '',
-		'after_page_number'  => '',
-	);
+		'add_args'           => [],
+		'add_fragment'       => ''
+	];
+	unset($args['base'], $args['format'], $args['total'], $args['current']);
 
 	$args = wp_parse_args( $args, $defaults );
 
 	if ( ! is_array( $args['add_args'] ) ) {
-		$args['add_args'] = array();
+		$args['add_args'] = [];
 	}
 
 	// Merge additional query vars found in the original URL into 'add_args' array.
@@ -4122,100 +4153,182 @@
 	if ( $mid_size < 0 ) {
 		$mid_size = 2;
 	}
-
-	$add_args   = $args['add_args'];
-	$r          = '';
-	$page_links = array();
 	$dots       = false;
 
+	$page_array = [
+		'prev'	=> null,
+		'pages'	=> [],
+		'next'	=> null
+	];
+
 	if ( $args['prev_next'] && $current && 1 < $current ) :
-		$link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
-		$link = str_replace( '%#%', $current - 1, $link );
-		if ( $add_args ) {
-			$link = add_query_arg( $add_args, $link );
-		}
-		$link .= $args['add_fragment'];
+		$link = format_paginate_link(
+			$current - 1,
+			$args['base'],
+			2 == $current ? '' : $args['format'],
+			$args['add_args'],
+			$args['add_fragment']
+		);
 
-		$page_links[] = sprintf(
-			'<a class="prev page-numbers" href="%s">%s</a>',
-			/**
-			 * Filters the paginated links for the given archive pages.
-			 *
-			 * @since 3.0.0
-			 *
-			 * @param string $link The paginated link URL.
-			 */
-			esc_url( apply_filters( 'paginate_links', $link ) ),
-			$args['prev_text']
-		);
+		$page_array['prev'] = [
+			'url'	=> $link,
+			'class'	=> 'prev page-numbers'
+		];
 	endif;
-
 	for ( $n = 1; $n <= $total; $n++ ) :
-		if ( $n == $current ) :
-			$page_links[] = sprintf(
-				'<span aria-current="%s" class="page-numbers current">%s</span>',
-				esc_attr( $args['aria_current'] ),
-				$args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
-			);
+		$current_stage = $current && $n >= $current - $mid_size && $n <= $current + $mid_size;
+		$cond = $args['show_all'] ||
+		(
+			$n <= $end_size ||
+			$current_stage ||
+			$n > $total - $end_size
+		);
+		if ( $cond ):
+			$link = null;
+			if ($n !== $current):
+				$link = format_paginate_link(
+					$n,
+					$args['base'],
+					1 == $n ? '' : $args['format'],
+					$args['add_args'],
+					$args['add_fragment']
+				);
+			endif;
 
+			$page_array['pages'][] = [
+				'type'	=> 'page',
+				'url'	=> $link ?: null,
+				'label'	=> $n,
+				'class'	=> 'page-numbers'
+			];
 			$dots = true;
-		else :
-			if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
-				$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
-				$link = str_replace( '%#%', $n, $link );
-				if ( $add_args ) {
-					$link = add_query_arg( $add_args, $link );
-				}
-				$link .= $args['add_fragment'];
+		elseif ( $dots && !$args['show_all'] ) :
+			$page_array['pages'][] = [
+				'type'	=> 'etc',
+				'label'	=> __( '&hellip;' ),
+				'class'	=> 'page-numbers dots'
+			];
+			$dots = false;
+		endif;
+	endfor;
+	if ( $args['prev_next'] && $current && $current < $total ) :
+		$link = format_paginate_link(
+			$current + 1,
+			$args['base'],
+			$args['format'],
+			$args['add_args'],
+			$args['add_fragment']
+		);
 
-				$page_links[] = sprintf(
-					'<a class="page-numbers" href="%s">%s</a>',
-					/** This filter is documented in wp-includes/general-template.php */
-					esc_url( apply_filters( 'paginate_links', $link ) ),
-					$args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
-				);
+		$page_array['next'] = [
+			'url'	=> $link,
+			'class'	=> 'next page-numbers'
+		];
+	endif;
 
-				$dots = true;
-			elseif ( $dots && ! $args['show_all'] ) :
-				$page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
+	return $page_array;
+}
 
-				$dots = false;
-			endif;
-		endif;
-	endfor;
+/**
+ * Retrieve paginated link for archive post pages.
+ *
+ * Technically, the function can be used to create paginated link list for any
+ * area. The 'base' argument is used to reference the url, which will be used to
+ * create the paginated links. The 'format' argument is then used for replacing
+ * the page number. It is however, most likely and by default, to be used on the
+ * archive post pages.
+ *
+ * The 'type' argument controls format of the returned value. The default is
+ * 'plain', which is just a string with the links separated by a newline
+ * character. The other possible values are either 'array' or 'list'. The
+ * 'array' value will return an array of the paginated link list to offer full
+ * control of display. The 'list' value will place all of the paginated links in
+ * an unordered HTML list.
+ *
+ * The 'before_page_number' and 'after_page_number' arguments allow users to
+ * augment the links themselves. Typically this might be to add context to the
+ * numbered links so that screen reader users understand what the links are for.
+ * The text strings are added before and after the page number - within the
+ * anchor tag.
+ *
+ * @since 2.1.0
+ * @since 4.9.0 Added the `aria_current` argument.
+ *
+ * @param string|array $args {
+ *     Optional. Array or string of arguments for generating paginated links for archives.
+ *
+ *     @type string $base               Base of the paginated url. Default empty.
+ *     @type string $format             Format for the pagination structure. Default empty.
+ *     @type int    $total              The total amount of pages. Default is the value WP_Query's
+ *                                      `max_num_pages` or 1.
+ *     @type int    $current            The current page number. Default is 'paged' query var or 1.
+ *     @type string $aria_current       The value for the aria-current attribute. Possible values are 'page',
+ *                                      'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
+ *     @type bool   $show_all           Whether to show all pages. Default false.
+ *     @type int    $end_size           How many numbers on either the start and the end list edges.
+ *                                      Default 1.
+ *     @type int    $mid_size           How many numbers to either side of the current pages. Default 2.
+ *     @type bool   $prev_next          Whether to include the previous and next links in the list. Default true.
+ *     @type bool   $prev_text          The previous page text. Default '&laquo; Previous'.
+ *     @type bool   $next_text          The next page text. Default 'Next &raquo;'.
+ *     @type string $type               Controls format of the returned value. Possible values are 'plain',
+ *                                      'array' and 'list'. Default is 'plain'.
+ *     @type array  $add_args           An array of query args to add. Default false.
+ *     @type string $add_fragment       A string to append to each link. Default empty.
+ *     @type string $before_page_number A string to appear before the page number. Default empty.
+ *     @type string $after_page_number  A string to append after the page number. Default empty.
+ * }
+ * @return string|array|void String of page links or array of page links.
+ */
+function paginate_links( $args = '' ) {
+	$defaults = [
+		'aria_current'       => 'page',
+		'prev_text'          => __( '&laquo; Previous' ),
+		'next_text'          => __( 'Next &raquo;' ),
+		'type'               => 'plain',
+		'before_page_number' => '',
+		'after_page_number'  => ''
+	];
 
-	if ( $args['prev_next'] && $current && $current < $total ) :
-		$link = str_replace( '%_%', $args['format'], $args['base'] );
-		$link = str_replace( '%#%', $current + 1, $link );
-		if ( $add_args ) {
-			$link = add_query_arg( $add_args, $link );
-		}
-		$link .= $args['add_fragment'];
+	$paginate_array = paginate_array( wp_parse_args( $args, $defaults ) );
+	$page_links = [];
 
-		$page_links[] = sprintf(
-			'<a class="next page-numbers" href="%s">%s</a>',
-			/** This filter is documented in wp-includes/general-template.php */
-			esc_url( apply_filters( 'paginate_links', $link ) ),
-			$args['next_text']
-		);
+
+	if ( isset($paginate_array['prev']) ) :
+		$prev = $paginate_array['prev'];
+		$page_links[] = "<a class='{$prev['class']}' href='{$prev['url']}'>{$args['prev_text']}</a>";
 	endif;
 
+	foreach ( $paginate_array['pages'] as $item ) :
+		if ( $item['type'] === 'etc' ) :
+			$page_links[] = "<a class='{$item['class']}'>{$item['label']}</a>";
+		elseif ( !$item['url'] && $item['type'] === 'page' ) :
+			$pos = $args['before_page_number'] . number_format_i18n( $item['label'] ) . $args['after_page_number'];
+			$page_links[] = "<a class='{$item['class']} current' aria-current='{$args['aria_current']}'>{$pos}</a>";
+		else:
+			$pos = $args['before_page_number'] . number_format_i18n( $item['label'] ) . $args['after_page_number'];
+			$page_links[] = "<a class='{$item['class']}' href='{$item['url']}'>{$pos}</a>";
+		endif;
+	endforeach;
+
+	if ( isset($paginate_array['next']) ) :
+		$next = $paginate_array['next'];
+		$page_links[] = "<a class='{$next['class']}' href='{$next['url']}'>{$args['next_text']}</a>";
+	endif;
+
+
 	switch ( $args['type'] ) {
 		case 'array':
 			return $page_links;
 
 		case 'list':
-			$r .= "<ul class='page-numbers'>\n\t<li>";
-			$r .= join( "</li>\n\t<li>", $page_links );
-			$r .= "</li>\n</ul>\n";
-			break;
+			return "<ul class='page-numbers'>\n\t<li>".
+				join( "</li>\n\t<li>", $page_links ).
+				"</li>\n</ul>\n";
 
 		default:
-			$r = join( "\n", $page_links );
-			break;
+			return join( "\n", $page_links );
 	}
-
-	return $r;
 }
 
 /**
