guid ) ) { return true; } return false; } /** * Determine whether a WP post is a cached external event. * * @param WP_Post $post The WordPress post object. * @return bool */ public static function is_cached_external_event( $post ): bool { if ( ! str_starts_with( \get_site_url(), $post->guid ) ) { return true; } 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_activitypub_request() ) { return $template; } if ( ! \is_singular() ) { return $template; } global $post; if ( 'gatherpress_event' !== $post->post_type ) { return $template; } if ( self::is_cached_external_event( $post ) ) { \wp_safe_redirect( $post->guid, 301 ); exit; } return $template; } }