From 7e9b6d5eb26c252e57ae7d4f04c4af243b7614c1 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Mon, 30 Sep 2024 19:43:23 +1300 Subject: [PATCH] :lipstick: Add theme namespace --- .../themes/wporg-make-2024/functions.php | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/source/wp-content/themes/wporg-make-2024/functions.php b/source/wp-content/themes/wporg-make-2024/functions.php index 9ffa209..461a057 100644 --- a/source/wp-content/themes/wporg-make-2024/functions.php +++ b/source/wp-content/themes/wporg-make-2024/functions.php @@ -1,6 +1,19 @@ set_404(); } } -add_action( 'pre_get_posts', 'make_query_mods' ); - -add_filter( - 'the_posts', - function( $posts, $query ) { - // Ensure all non-post routes 404, as this site isn't like most others. - if ( - ( ! is_admin() && $query->is_main_query() && ! $query->is_robots() && ! $posts ) || - ( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive( 'meeting' ) && $query->get( 'paged' ) > 1 ) // Pagination on the query is explicitly disabled, so this doens't 404 - ) { - $query->set_404(); - status_header( 404 ); - nocache_headers(); - } - - return $posts; - }, - 10, - 2 -); + +/** + * Ensure all non-post routes 404, as this site isn't like most others. + * + * @param array $posts The array of posts. + * @param WP_Query $query The WP_Query instance (passed by reference). + * @return array The filtered posts array. + */ +function make_handle_non_post_routes( $posts, $query ) { + if ( + ( ! is_admin() && $query->is_main_query() && ! $query->is_robots() && ! $posts ) || + // Pagination on the query is explicitly disabled, so this doesn't 404 + ( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive( 'meeting' ) && $query->get( 'paged' ) > 1 ) + ) { + $query->set_404(); + status_header( 404 ); + nocache_headers(); + } + + return $posts; +} /** * Adds custom classes to the array of post classes. @@ -135,7 +147,6 @@ function make_home_site_classes( $classes, $class, $id ) { $classes[] = sanitize_html_class( 'make-' . get_post( $id )->post_name ); return $classes; } -add_filter( 'post_class', 'make_home_site_classes', 10, 3 ); /** * Set page name for front page title. @@ -151,7 +162,6 @@ function make_add_frontpage_name_to_title( $parts ) { return $parts; } -add_filter( 'document_title_parts', 'make_add_frontpage_name_to_title' ); /** * Noindex the post_type behind the site listing. @@ -163,5 +173,3 @@ function make_noindex( $noindex ) { return $noindex; } -add_filter( 'wporg_noindex_request', 'make_noindex' ); -