Skip to content

Commit ffb0654

Browse files
authored
Merge pull request #29 from gin0115/fix/archives-reverting-to-dates
Fix/archives reverting to dates
2 parents fe9d8b1 + e1308f2 commit ffb0654

File tree

6 files changed

+172
-6
lines changed

6 files changed

+172
-6
lines changed

src/classes/class-se-blocks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public static function event_info_render( $attributes, $content, $block ) {
281281
}
282282

283283
$dates_output = '';
284+
$date_heading = '';
284285

285286
if ( ! empty( $event_dates ) ) {
286287
$has_header_date = false;

src/classes/class-se-event-post-type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ public static function pre_get_posts( $query ) {
659659
public static function handle_expired_events() {
660660
global $wp_query;
661661

662-
if ( $wp_query->is_singular( self::$post_type ) ) {
662+
if ( $wp_query->is_singular( self::$post_type ) || $wp_query->is_singular( self::$event_date_post_type ) ) {
663663
$options = get_option( 'se_options' );
664664

665665
// Values for which passed events should be shown on Single View.

src/classes/class-se-template-loader.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,35 @@ public static function init() {
3030
* @return string
3131
*/
3232
public static function template_include( $template ) {
33+
// Check if we are looking for a single event or event date template.
34+
if ( is_single() && get_post_type() === SE_Event_Post_Type::$post_type ) {
35+
// Attempt to look for the single event template in themes etc.
36+
$theme_templates = array(
37+
'single-se-event.php',
38+
);
39+
// Determine if any of these templates is available in the theme.
40+
$single_event_template = get_query_template( 'singular', $theme_templates );
41+
if ( ! $single_event_template ) {
42+
// If not use our custom template.
43+
$plugins_own = self::locate_template( array( 'single.php' ) );
44+
if ( $plugins_own ) {
45+
// Allow filters to override the template.
46+
$plugins_own = apply_filters( 'se_single_event_template', $plugins_own );
47+
if ( $plugins_own ) {
48+
return $plugins_own;
49+
}
50+
}
51+
}
52+
}
53+
3354
// Return early if this view is not an event view.
34-
if ( ! is_singular( 'se-event' ) && ! is_post_type_archive( 'se-event' ) ) {
55+
if ( ! is_singular( 'se-event-date' ) && ! is_post_type_archive( 'se-event-date' ) ) {
3556
return $template;
3657
}
3758

3859
// Determine if standard single se-event templates are available in the theme
3960
// before replacing with the custom template in this plugin.
40-
if ( is_singular( 'se-event' ) ) {
61+
if ( is_singular( 'se-event-date' ) ) {
4162
$event = get_post();
4263

4364
$theme_templates = array(
@@ -62,14 +83,13 @@ public static function template_include( $template ) {
6283

6384
// Determine if standard se-event archive templates are available in the theme
6485
// before replacing with the custom template in this plugin.
65-
if ( is_archive( 'se-event' ) ) {
86+
if ( is_archive( 'se-event-date' ) ) {
6687
$theme_templates = array(
6788
'archive-se-event.php',
6889
);
6990

7091
// Determine if any of these templates is available in the theme.
7192
$archive_event_template = get_query_template( 'archive', $theme_templates );
72-
7393
if ( $archive_event_template ) {
7494
return $archive_event_template;
7595
}
@@ -81,6 +101,8 @@ public static function template_include( $template ) {
81101
$fallback_template = self::locate_template( array( $fallback_template ) );
82102

83103
if ( '' !== $fallback_template ) {
104+
// Allow filters to override the template.
105+
$fallback_template = apply_filters( 'se_event_archive_template_legacy', $fallback_template );
84106
return $fallback_template;
85107
}
86108

src/template-functions.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,141 @@ function ( $date ) use ( $post ) {
567567
}
568568
}
569569

570+
571+
if ( ! function_exists( 'se_fix_se_events_fse_archive_template' ) ) {
572+
/**
573+
* Fix the template hierarchy for the SE Events FSE archive.
574+
*
575+
* @param array $templates The template hierarchy.
576+
*
577+
* @return array The modified template hierarchy.
578+
*/
579+
function se_fix_se_events_fse_archive_template( $templates ) {
580+
if ( 'se-event-date' === get_query_var( 'post_type' ) ) {
581+
// Create proper hierarchy: archive-se-events.html, then archive.html
582+
$custom_hierarchy = array(
583+
'archive-se-event.html',
584+
'archive.html',
585+
);
586+
587+
return $custom_hierarchy;
588+
}
589+
return $templates;
590+
}
591+
}
592+
593+
// Filter to modify the body class for the event date archive.
594+
if ( ! function_exists( 'se_modify_event_date_archive_body_class' ) ) {
595+
/**
596+
* Modify the body class for the event date archive.
597+
*
598+
* @param array $classes The existing body classes.
599+
*
600+
* @return array The modified body classes.
601+
*/
602+
function se_modify_event_date_archive_body_class( $classes ) {
603+
$classes = array_map(
604+
function ( $body_class ) {
605+
return 'post-type-archive-se-event-date' === $body_class ? 'post-type-archive-se-event' : $class;
606+
},
607+
$classes
608+
);
609+
return $classes;
610+
}
611+
}
612+
613+
// Modify the archive page title.
614+
if ( ! function_exists( 'se_modify_event_date_archive_template_title' ) ) {
615+
/**
616+
* Modify the archive page title for the event date archive.
617+
*
618+
* @param string $title The existing archive title.
619+
*
620+
* @return string The modified archive title.
621+
*/
622+
function se_modify_event_date_archive_template_title( $title ) {
623+
if ( is_post_type_archive( 'se-event-date' ) ) {
624+
$original_title = $title;
625+
// Get the se-event post type object to use its archive title
626+
$post_type_obj = get_post_type_object( 'se-event' );
627+
628+
// If this is a post_typw archive, use the post type archive title.
629+
if ( is_post_type_archive() ) {
630+
$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, 'se-event' ); // phpcs:ignore
631+
$prefix = _x( 'Archives:', 'post type archive title prefix' ); // phpcs:ignore
632+
} elseif ( is_tax() && $post_type_obj ) {
633+
$tax = get_taxonomy( $post_type_obj->taxonomy );
634+
$title = single_term_title( '', false );
635+
$prefix = sprintf(
636+
/* translators: %s: Taxonomy singular name. */
637+
_x( '%s:', 'taxonomy term archive title prefix' ), // phpcs:ignore
638+
$tax->labels->singular_name
639+
);
640+
} else {
641+
$prefix = '';
642+
}
643+
644+
/**
645+
* Filters the archive title prefix.
646+
*
647+
* @since 5.5.0
648+
*
649+
* @param string $prefix Archive title prefix.
650+
*/
651+
$prefix = apply_filters( 'get_the_archive_title_prefix', $prefix ); // phpcs:ignore
652+
if ( $prefix ) {
653+
$title = sprintf(
654+
/* translators: 1: Title prefix. 2: Title. */
655+
_x( '%1$s %2$s', 'archive title' ), // phpcs:ignore
656+
$prefix,
657+
'<span>' . $title . '</span>'
658+
);
659+
}
660+
}
661+
return $title;
662+
}
663+
}
664+
665+
666+
667+
// Modify the page HTML title for the event date archive.
668+
if ( ! function_exists( 'se_modify_event_date_archive_page_title' ) ) {
669+
/**
670+
* Modify the page HTML title for the event date archive.
671+
*
672+
* @param string $title The existing page title.
673+
*
674+
* @return string The modified page title.
675+
*/
676+
function se_modify_event_date_archive_page_title( $title ) {
677+
if ( is_post_type_archive( 'se-event-date' ) ) {
678+
$event_post_type = get_post_type_object( 'se-event' );
679+
$title = $event_post_type->labels->name;
680+
} elseif ( is_tax() ) {
681+
$taxonomy = get_queried_object();
682+
if ( $taxonomy ) {
683+
$title = $taxonomy->name;
684+
}
685+
}
686+
return $title;
687+
}
688+
}
689+
/**
690+
* Ensure that legacy themes will call the se-event archive template.
691+
*
692+
* @since 2.0.0
693+
*
694+
* @param string $template The template file to use.
695+
*
696+
* @return string The modified template file.
697+
*/
698+
function se_event_archive_template( $template ) {
699+
if ( is_post_type_archive( 'se-event-date' ) ) {
700+
// If the template is not set, use the default archive template.
701+
$date_archive_template = locate_template( 'archive-se-event.php' );
702+
if ( $date_archive_template ) {
703+
return $date_archive_template;
704+
}
705+
}
706+
return $template;
707+
}

src/template-hooks.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@
3535
add_action( 'se_single_content', 'se_template_calendar_links', 30 );
3636
// Show the next and previous links either above or below content (based on settings).
3737
add_action( 'se_single_content', 'se_template_event_next_previous', se_event_show_links_above_content() ? 40 : 15 );
38+
39+
// V2 Fixes
40+
add_filter( 'archive_template_hierarchy', 'se_fix_se_events_fse_archive_template' );
41+
add_filter( 'pre_get_document_title', 'se_modify_event_date_archive_page_title' );
42+
add_filter( 'body_class', 'se_modify_event_date_archive_body_class' );
43+
add_filter( 'get_the_archive_title', 'se_modify_event_date_archive_template_title', 20, 1 );

src/templates/content-single.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
}
1010

1111
?>
12-
1312
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
1413
<?php
1514
/**

0 commit comments

Comments
 (0)