Skip to content

Commit

Permalink
Archives: Enable author links to archive pages, make filtering work o…
Browse files Browse the repository at this point in the history
…n author archives.
  • Loading branch information
ryelle committed May 2, 2024
1 parent 1637de9 commit a1c4c6c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
19 changes: 15 additions & 4 deletions source/wp-content/themes/wporg-themes-2024/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ function( $should_show ) {
2000
);

add_action(
'init',
function() {
// Don't swap author link with w.org profile link.
remove_all_filters( 'author_link' );
}
);

/**
* Temporary fix for permission problem during local install.
*/
Expand Down Expand Up @@ -253,17 +261,20 @@ function redirect_term_archives() {
global $wp_query, $wp;
$url = false;
$query_vars = [];
$is_browse_url = str_starts_with( $wp->request, 'browse/' );
$is_tags_url = str_starts_with( $wp->request, 'tags/' );

// Return early if we're already on an author or browse page.
if ( str_starts_with( $wp->request, 'author/' ) || str_starts_with( $wp->request, 'browse/' ) ) {
return;
}

$browse = sanitize_text_field( $wp_query->query['browse'] ?? '' );
$terms = array_map( 'sanitize_text_field', get_query_tags() );

if ( ! empty( $browse ) && ! $is_browse_url ) {
if ( ! empty( $browse ) ) {
$url = home_url( '/browse/' . $browse . '/' );
$query_vars = [ 's', 'tag', 'tag_slug__and' ];

} else if ( count( $terms ) && ! $is_browse_url && ! $is_tags_url ) {
} else if ( count( $terms ) && ! str_starts_with( $wp->request, 'tags/' ) ) {
if ( count( $terms ) === 1 ) {
$url = get_term_link( $terms[0], 'post_tag' );
} else {
Expand Down
19 changes: 16 additions & 3 deletions source/wp-content/themes/wporg-themes-2024/inc/block-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ function update_query_total_label( $label, $found_posts ) {
return _n( '%s theme', '%s themes', $found_posts, 'wporg-themes' );
}

/**
* Get the destination for query-filter submission based on the current page.
*
* @return string
*/
function get_filter_action_url() {
global $wp;
if ( is_author() ) {
return home_url( $wp->request );
}
return home_url( '/' );
}

/**
* Provide a list of layout options.
*
Expand All @@ -49,7 +62,7 @@ function get_layouts_options( $options ) {
'label' => $label,
'title' => __( 'Layout', 'wporg-themes' ),
'key' => 'tag_slug__and',
'action' => home_url( '/' ),
'action' => get_filter_action_url(),
'options' => $layouts,
'selected' => $selected,
);
Expand Down Expand Up @@ -77,7 +90,7 @@ function get_features_options( $options ) {
'label' => $label,
'title' => __( 'Features', 'wporg-themes' ),
'key' => 'tag_slug__and',
'action' => home_url( '/' ),
'action' => get_filter_action_url(),
'options' => $features,
'selected' => $selected,
);
Expand Down Expand Up @@ -105,7 +118,7 @@ function get_subjects_options( $options ) {
'label' => $label,
'title' => __( 'Subjects', 'wporg-themes' ),
'key' => 'tag_slug__and',
'action' => home_url( '/' ),
'action' => get_filter_action_url(),
'options' => $subjects,
'selected' => $selected,
);
Expand Down

0 comments on commit a1c4c6c

Please sign in to comment.