Eliminate use of `extract()` in `wp_link_pages()`.
Adds unit tests to a new file: `tests/post/template.php`. There were previously no unit tests for `wp_link_pages()`. See #22400. Built from https://develop.svn.wordpress.org/trunk@28398 git-svn-id: http://core.svn.wordpress.org/trunk@28226 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d5acdd82c8
commit
fe2d90ab4f
|
@ -739,29 +739,28 @@ function wp_link_pages( $args = '' ) {
|
||||||
'echo' => 1
|
'echo' => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = wp_parse_args( $args, $defaults );
|
$params = wp_parse_args( $args, $defaults );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the arguments used in retrieving page links for paginated posts.
|
* Filter the arguments used in retrieving page links for paginated posts.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
*
|
||||||
* @param array $r An array of arguments for page links for paginated posts.
|
* @param array $params An array of arguments for page links for paginated posts.
|
||||||
*/
|
*/
|
||||||
$r = apply_filters( 'wp_link_pages_args', $r );
|
$r = apply_filters( 'wp_link_pages_args', $params );
|
||||||
extract( $r, EXTR_SKIP );
|
|
||||||
|
|
||||||
global $page, $numpages, $multipage, $more;
|
global $page, $numpages, $multipage, $more;
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
if ( $multipage ) {
|
if ( $multipage ) {
|
||||||
if ( 'number' == $next_or_number ) {
|
if ( 'number' == $r['next_or_number'] ) {
|
||||||
$output .= $before;
|
$output .= $r['before'];
|
||||||
for ( $i = 1; $i <= $numpages; $i++ ) {
|
for ( $i = 1; $i <= $numpages; $i++ ) {
|
||||||
$link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after;
|
$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
|
||||||
if ( $i != $page || ! $more && 1 == $page )
|
if ( $i != $page || ! $more && 1 == $page ) {
|
||||||
$link = _wp_link_page( $i ) . $link . '</a>';
|
$link = _wp_link_page( $i ) . $link . '</a>';
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Filter the HTML output of individual page number links.
|
* Filter the HTML output of individual page number links.
|
||||||
*
|
*
|
||||||
|
@ -771,28 +770,28 @@ function wp_link_pages( $args = '' ) {
|
||||||
* @param int $i Page number for paginated posts' page links.
|
* @param int $i Page number for paginated posts' page links.
|
||||||
*/
|
*/
|
||||||
$link = apply_filters( 'wp_link_pages_link', $link, $i );
|
$link = apply_filters( 'wp_link_pages_link', $link, $i );
|
||||||
$output .= $separator . $link;
|
$output .= $r['separator'] . $link;
|
||||||
}
|
}
|
||||||
$output .= $after;
|
$output .= $r['after'];
|
||||||
} elseif ( $more ) {
|
} elseif ( $more ) {
|
||||||
$output .= $before;
|
$output .= $r['before'];
|
||||||
$i = $page - 1;
|
$prev = $page - 1;
|
||||||
if ( $i ) {
|
if ( $prev ) {
|
||||||
$link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . '</a>';
|
$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
|
||||||
|
|
||||||
/** This filter is documented in wp-includes/post-template.php */
|
/** This filter is documented in wp-includes/post-template.php */
|
||||||
$link = apply_filters( 'wp_link_pages_link', $link, $i );
|
$link = apply_filters( 'wp_link_pages_link', $link, $prev );
|
||||||
$output .= $separator . $link;
|
$output .= $r['separator'] . $link;
|
||||||
}
|
}
|
||||||
$i = $page + 1;
|
$next = $page + 1;
|
||||||
if ( $i <= $numpages ) {
|
if ( $next <= $numpages ) {
|
||||||
$link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . '</a>';
|
$link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';
|
||||||
|
|
||||||
/** This filter is documented in wp-includes/post-template.php */
|
/** This filter is documented in wp-includes/post-template.php */
|
||||||
$link = apply_filters( 'wp_link_pages_link', $link, $i );
|
$link = apply_filters( 'wp_link_pages_link', $link, $next );
|
||||||
$output .= $separator . $link;
|
$output .= $r['separator'] . $link;
|
||||||
}
|
}
|
||||||
$output .= $after;
|
$output .= $r['after'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -801,15 +800,15 @@ function wp_link_pages( $args = '' ) {
|
||||||
*
|
*
|
||||||
* @since 3.6.0
|
* @since 3.6.0
|
||||||
*
|
*
|
||||||
* @param string $output HTML output of paginated posts' page links.
|
* @param string $html HTML output of paginated posts' page links.
|
||||||
* @param array $args An array of arguments.
|
* @param array $args An array of arguments.
|
||||||
*/
|
*/
|
||||||
$output = apply_filters( 'wp_link_pages', $output, $args );
|
$html = apply_filters( 'wp_link_pages', $output, $args );
|
||||||
|
|
||||||
if ( $echo )
|
if ( $r['echo'] ) {
|
||||||
echo $output;
|
echo $html;
|
||||||
|
}
|
||||||
return $output;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue