Skip to content

Commit e3f5187

Browse files
committed
Account and Profile subpages now inherit the parent page template which was broken in WordPress 6.0+. Fixes #288
1 parent 5aa3979 commit e3f5187

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

includes/filters.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,28 @@ function wpum_remove_slashes_from_field_data( $field_name ) {
336336

337337
add_filter( 'wpum_field_name', 'wpum_remove_slashes_from_field_data' );
338338
add_filter( 'wpum_field_description', 'wpum_remove_slashes_from_field_data' );
339+
340+
/**
341+
* In WP 6.0+, virtual pages for our Account and Profile subpages (eg. account/posts or profile/comments)
342+
* no longer inherit the page template of the parent page. This fixes that.
343+
*/
344+
add_filter( 'template_include', function ( $template ) {
345+
global $wp;
346+
347+
if ( ! isset( $wp->query_vars ) ) {
348+
return $template;
349+
}
350+
351+
if ( ! isset( $wp->query_vars['page_id'] ) ) {
352+
return $template;
353+
}
354+
355+
if ( $wp->query_vars['page_id'] === wpum_get_core_page_id( 'account' ) || $wp->query_vars['page_id'] === wpum_get_core_page_id( 'profile' ) ) {
356+
$new_template_slug = get_page_template_slug( $wp->query_vars['page_id'] );
357+
if ( $new_template_slug && basename( $template ) !== $new_template_slug ) {
358+
$template = dirname( $template ) . '/' . $new_template_slug;
359+
}
360+
}
361+
362+
return $template;
363+
}, 100 );

0 commit comments

Comments
 (0)