> $items Entries from the settings. */ private static function current_page_matches( array $items ): bool { // The posts page lists posts, and is a page that can be chosen too. $posts_page = (int) get_option( 'page_for_posts' ); $queried_id = is_singular() || ( is_home() && $posts_page > 0 && (int) get_queried_object_id() === $posts_page ) ? (int) get_queried_object_id() : 0; $listing = is_archive() || is_search() || is_404() || ( is_home() && ! is_front_page() ); return self::matches( $items, $queried_id, is_front_page(), $listing ); } /** * Whether a page matches any of the chosen entries. * * @param array> $items Entries from the settings. * @param int $post_id The post a single page shows, or 0. * @param bool $front Whether it's the front page. * @param bool $listing Whether it's an archive, search results or the posts page. */ public static function matches( array $items, int $post_id, bool $front, bool $listing ): bool { $post_type = $post_id ? (string) get_post_type( $post_id ) : ''; foreach ( $items as $item ) { $type = $item['type'] ?? ''; if ( 'post' === $type && $post_id && (int) ( $item['id'] ?? 0 ) === $post_id ) { return true; } if ( 'front' === $type && $front ) { return true; } if ( 'post_type' === $type && '' !== $post_type && ( $item['name'] ?? '' ) === $post_type ) { return true; } if ( 'archives' === $type && $listing ) { return true; } } return false; } }