diff --git a/includes/class-event-sources.php b/includes/class-event-sources.php index f2701fa..ee10388 100644 --- a/includes/class-event-sources.php +++ b/includes/class-event-sources.php @@ -123,4 +123,32 @@ class Event_Sources { // Return false if no application actor is found. return false; } + + /** + * Add the ActivityPub template for EventPrime. + * + * @param string $template The path to the template object. + * @return string The new path to the JSON template. + */ + public static function redirect_activitypub_requests_for_cached_external_events( $template ) { + if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + return $template; + } + + if ( ! \is_singular() ) { + return $template; + } + + global $post; + + if ( 'gatherpress_event' !== $post->post_type ) { + return $template; + } + + if ( ! str_starts_with( \get_site_url(), $post->guid ) ) { + \wp_safe_redirect( $post->guid, 301 ); + } + + return $template; + } } diff --git a/includes/class-setup.php b/includes/class-setup.php index b204bd6..c6eac0b 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -216,6 +216,7 @@ class Setup { add_action( 'activitypub_register_handlers', array( Handler::class, 'register_handlers' ) ); add_action( 'admin_init', array( User_Interface::class, 'init' ) ); } + \add_filter( 'template_include', array( \Event_Bridge_For_ActivityPub\Event_Sources::class, 'redirect_activitypub_requests_for_cached_external_events' ), 100 ); add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 ); }