Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/wp-includes/general-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,17 @@ function wp_get_archives( $args = '' ) {
'w' => get_query_var( 'w' ),
);

/**
* Filters the archive links list arguments.
Comment thread
jeherve marked this conversation as resolved.
Outdated
*
* @since 7.0.0
*
* @see wp_get_archives()
*
* @param array $args An array of arguments.
Comment thread
jeherve marked this conversation as resolved.
Outdated
*/
$args = apply_filters( 'wp_get_archives_args', $args );

$parsed_args = wp_parse_args( $args, $defaults );

$post_type_object = get_post_type_object( $parsed_args['post_type'] );
Expand Down
37 changes: 37 additions & 0 deletions tests/phpunit/tests/functions/wpGetArchives.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,41 @@ public function test_wp_get_archives_post_type() {
);
$this->assertSame( $expected, trim( $archives ) );
}

/**
* @ticket 64304
*/
public function test_wp_get_archives_args_filter() {
// Test that the filter can modify the limit argument.
$filter_callback = function ( $args ) {
$args['limit'] = 3;
return $args;
};
add_filter( 'wp_get_archives_args', $filter_callback );

$ids = array_slice( array_reverse( self::$post_ids ), 0, 3 );

$link1 = get_permalink( $ids[0] );
$link2 = get_permalink( $ids[1] );
$link3 = get_permalink( $ids[2] );

$title1 = get_post( $ids[0] )->post_title;
$title2 = get_post( $ids[1] )->post_title;
$title3 = get_post( $ids[2] )->post_title;

$expected = <<<EOF
<li><a href='$link1'>$title1</a></li>
<li><a href='$link2'>$title2</a></li>
<li><a href='$link3'>$title3</a></li>
EOF;
Comment thread
jeherve marked this conversation as resolved.
Outdated
Comment thread
jeherve marked this conversation as resolved.
Outdated
$archives = wp_get_archives(
array(
'echo' => false,
'type' => 'postbypost',
'limit' => 5, // This should be overridden by the filter to 3.
)
);

$this->assertSameIgnoreEOL( $expected, trim( $archives ) );
Comment thread
jeherve marked this conversation as resolved.
Outdated
}
}
Loading