Skip to content

901/improve feeds#1146

Merged
mauteri merged 33 commits intodevelopfrom
901/improve-feeds
Sep 10, 2025
Merged

901/improve feeds#1146
mauteri merged 33 commits intodevelopfrom
901/improve-feeds

Conversation

@jmarx
Copy link
Copy Markdown
Collaborator

@jmarx jmarx commented Aug 2, 2025

Description of the Change

In this pr we are fixing the events feed so it returns events appropriately

Closes #901

How to test the Change

Visit /events/feed and ensure you are getting an rss/xml feed of events and not anything else(Comments or RSVPs).

Changelog Entry

Fixed - Bug

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Aug 2, 2025

PR Summary

  • Introduction of Feed_Improvements Instance
    A new instance for a feature named Feed_Improvements has been added in one of the primary setup files. This paves way for enhancing the overall feed features provided by the application.

  • Establishment of New Test File
    In order to ensure the newly added Feed_Improvements functionality works as expected, a test file class-test-feed-improvements.php has been introduced. This will help us maintain the integrity of this feature by allowing regular checks via these tests.

  • Introduction of Test Methods for Feed_Improvements
    Multiple testing methods have been implemented for checking various aspects of Feed_Improvements:

    • Verifying if Feed_Improvements successfully retains only a single active instance at any given time.
    • Check on force_events_feed_query method to ensure both event feeds and non-event feeds are handled as intended.
    • Assessment of functionality to customize event and non-event posts via customize_event_excerpt and customize_event_content methods.
    • Test to check the operation of get_event_datetime_info across a variety of scenarios including instances with no date and time information.

@jmarx jmarx marked this pull request as ready for review August 2, 2025 18:27
@jmarx jmarx requested a review from mauteri August 2, 2025 18:27
@mauteri mauteri requested a review from carstingaxion August 2, 2025 19:28
Copy link
Copy Markdown
Contributor

@mauteri mauteri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carstingaxion mind reviewing and adding some feedback on this too? Thx!

*
* @since 1.0.0
*/
class Feed_Improvements {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change name to Event_Feed and class-event-feed.php and make additional updates that match this change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done.

if ( ! get_option( 'gatherpress_events_feed_rewrite_flushed' ) ) {
flush_rewrite_rules();
update_option( 'gatherpress_events_feed_rewrite_flushed', true );
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of this and handle updates to rewrite rules that @carstingaxion put in here #880. We'll make this ticket part of 0.33

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done

}



Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line breaks, should just be one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done

* @param \WP $wp WordPress environment instance.
* @return void
*/
public function intercept_events_feed( \WP $wp ): void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add use WP and only have WP here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Removed this method so it doesn't matter.

// Also try to force the main query to be an events query.
add_action(
'wp',
function () {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static function (): void {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Removed this method so oit doesn't matter.

* @param Event $event The event object.
* @return array Array of event information strings.
*/
private function get_event_datetime_info( Event $event ): array {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is duplicating functionality you can get from the event you are passing to it. Look at class-event.php and you'll find methods like is_same_date, get_display_datetime, get_formatted_datetime and others you can use rather than calculating all this below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done. Using the existing logic now

}



Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra line breaks, just 1

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done

*
* @return void
*/
public function force_events_feed(): void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at prepare_event_query_before_execution method in class-event-query.php. You might be able to have that method handle for feeds too so we don't have to pre_get_posts hooks that are ordering events and could change independently causing issues and bugs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done


// Remove any comment-related query vars.
$query->set( 'comments', false );
$query->set( 'comment_feed', false );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing comments?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri I had a hard time with this one. Let's discuss. The comments feed kept overwriting the events feed. And that url would be nothing but comments. Maybe we handle this separately. Or maybe you have ideas.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would look at how comments are applied to feeds for regular posts and follow that. There's a callback hook on pre_get_comments in GatherPress that will prevent including RSVPs in with it, so you don't need to worry about filtering those out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri yeah I think that filter is applied to get_comments (which I am using there) I put in some RSVPs and don't see them in the comment feed. Is that what you're concerned about?

* @param \WP_Query $query The WP_Query instance.
* @return void
*/
public function force_events_feed_query( \WP_Query $query ): void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there 2 pre_get_posts callbacks? I would leverage what is in class-event-query.php to handle feeds as well and make sure they are upcoming.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done

public function add_events_feed_rewrite_rules(): void {
// Add a rewrite rule for /events/feed/ to be treated as an events feed.
add_rewrite_rule(
'^events/feed/?$',
Copy link
Copy Markdown
Contributor

@mauteri mauteri Aug 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the slug should be a setting (at least eventually)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Let's handle separately

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri I handled this as well. I didn't realize that setting was already available.

@jmarx jmarx requested a review from mauteri August 2, 2025 23:56
@jmarx
Copy link
Copy Markdown
Collaborator Author

jmarx commented Aug 2, 2025

@mauteri I handled most of your review comments. But we still have another couple open issues. Can you please take another look and confirm the ones I handled were adequate?

@mauteri
Copy link
Copy Markdown
Contributor

mauteri commented Aug 3, 2025

@mauteri I handled most of your review comments. But we still have another couple open issues. Can you please take another look and confirm the ones I handled were adequate?

@jmarx I'd like @carstingaxion to look at this next and provide additional feedback. Thx!

@carstingaxion
Copy link
Copy Markdown
Collaborator

@mauteri I handled most of your review comments. But we still have another couple open issues. Can you please take another look and confirm the ones I handled were adequate?

@jmarx I'd like @carstingaxion to look at this next and provide additional feedback. Thx!

I’ll be available in 27 minutes and will start with this. Thanks for your patience.

return $custom_content;
}

/**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of that method?

It seems (to me) to replicate, what register_post_type() is already doing?

If there is a real reason for having it, it might be better to build the URL based on the gatherpress_general['urls']['events'] setting and not with the hardcoded 'events' string.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carstingaxion I am now using settings for building the url. The purpose of the method is to customize output of the event content for the purposes of RSS feed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jmarx,

I'm sorry that I need to ask again: Why are you creating that new rewrite_rule?
I don't get it.

Before:
image

After:
image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carstingaxion
Sorry, I completely misunderstood your comment/question. I get what you're saying now. I removed the redundant rewrite rule.

Comment on lines +87 to +88
// Check if this is /events/feed/.
if ( strpos( $request_uri, '/events/feed' ) !== false ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to build the URL based on the gatherpress_general['urls']['events'] setting and not with the hardcoded 'events' string.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carstingaxion I am using the setting now.

Comment on lines +55 to +57
// Customize RSS excerpts for events.
add_filter( 'the_excerpt_rss', array( $this, 'customize_event_excerpt' ) );
add_filter( 'the_content_feed', array( $this, 'customize_event_content' ) );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really happy with that hard replacements at all and would like to keep some more flexibility for the editor and or theme designer.

I haven't tested this, but I'd like to try hooking into get_template_part_slug or later and provide a default template from within GatherPress. This template could be overwrittren by a theme or within the block-editor or both.

Copy link
Copy Markdown
Collaborator

@carstingaxion carstingaxion Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe even better would be using register_block_template() which allows to hook into the default template hierachy, just by setting the $template_name correctly to match a default template.

In our case this should be "gatherpress/feed-gatherpress_event" I think.

Using this, GatherPress could provide a default different from wp core and allow theme designers to adjust the template (even inside the block editor).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carstingaxion OK, I implemented some filters to make sure it can be overwritten if need be:
0608028

@carstingaxion
Copy link
Copy Markdown
Collaborator

Hello @jmarx,

thanks for starting the journey on this ticket!

I left some review comments and hope that you can understand.

In general, it would help me to understand, if you could provide some basic PR description and what is changing;
including some Testing instructions on what to try and what to assert.

@jmarx jmarx requested a review from mauteri August 10, 2025 18:25
@jmarx
Copy link
Copy Markdown
Collaborator Author

jmarx commented Aug 10, 2025

@mauteri Removed all the unneeded code. The feed should be using the standard wordpress format now.

$event_info = array();
$display_datetime = $event->get_display_datetime();

if ( ! empty( $display_datetime ) && __( '—', 'gatherpress' ) !== $display_datetime ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed this.

if ( ! empty( $display_datetime ) && '—' !== $display_datetime ) {

@mauteri
Copy link
Copy Markdown
Contributor

mauteri commented Aug 10, 2025

@mauteri Removed all the unneeded code. The feed should be using the standard wordpress format now.

@jmarx Okay thanks. You missed one thing, so please make that change. Also, I'd like @carstingaxion to have another look at this and approve if he thinks it's good now since he put in the original ticket.

$request_uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );

// Check if this is the events feed URL.
if ( str_contains( $request_uri, '/' . $this->rewrite_slug . '/feed' ) ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word "feed" can also be changed, so make sure to use feed_base from the global $wp_rewrite.

https://developer.wordpress.org/reference/classes/wp_rewrite/#properties

}

// Allow themes and editors to customize the excerpt.
return apply_filters( 'gatherpress_event_feed_excerpt', $excerpt );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't phpcs complain about the missing doc-block here?
I suggest adding some more info here.

}

// Allow themes and editors to customize the content.
return apply_filters( 'gatherpress_event_feed_content', $content );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some docs about using this filter, too.

* @return string The customized content.
*/
public function apply_event_content( string $content ): string {
global $post;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This global can be omitted, because get_post_type() will use the global as its default, if nothing else is given.

https://developer.wordpress.org/reference/functions/get_post_type/

@jmarx jmarx requested review from carstingaxion and mauteri August 11, 2025 00:19
@jmarx
Copy link
Copy Markdown
Collaborator Author

jmarx commented Aug 11, 2025

@mauteri @carstingaxion I think we should be good now?

Copy link
Copy Markdown
Collaborator

@carstingaxion carstingaxion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to what you already prepared @jmarx , I’d like to suggest to improve all feed endpoints where events are queried. Even this was not part of the initial issue, I mentioned this in a comment on the same issue: #901 (comment)

  • gatherpress_event post type archive feed
  • gatherpress_topic taxonomy archive feed
  • _gatherpress_venue taxonomy archive feed

@jmarx
Copy link
Copy Markdown
Collaborator Author

jmarx commented Aug 11, 2025

In addition to what you already prepared @jmarx , I’d like to suggest to improve all feed endpoints where events are queried. Even this was not part of the initial issue, I mentioned this in a comment on the same issue: #901 (comment)

  • gatherpress_event post type archive feed
  • gatherpress_topic taxonomy archive feed
  • _gatherpress_venue taxonomy archive feed

@carstingaxion Agreed. But should we not do that in a follow up ticket? To keep these prs/chunks of work, tight?
I'll leave that up to you and @mauteri

@jmarx
Copy link
Copy Markdown
Collaborator Author

jmarx commented Aug 11, 2025

@carstingaxion I suggest we have Andrew Short create follow up tickets for those feeds. And we can use this as model.
cc @mauteri

@jmarx jmarx requested a review from carstingaxion August 11, 2025 13:51
* @return string The customized excerpt.
*/
public function get_default_event_excerpt( string $excerpt ): string {
global $post;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
global $post;
if ( Event::POST_TYPE !== get_post_type() ) {
return $excerpt;
}

I already mentioned this before, but I guess you may have missed this @jmarx

I would remove the global $post and rely on get_post_type() falling back to the global internaly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carstingaxion Fixed. I swear I tried this and it was not working before. But it's good now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmarx you still have the global $post and have $post passing as an argument.

* @return string The customized content.
*/
public function get_default_event_content( string $content ): string {
global $post;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: I would remove the global $post and rely on get_post_type() falling back to the global internaly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @return string The customized excerpt.
*/
public function apply_event_excerpt( string $excerpt ): string {
global $post;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: I would remove the global $post and rely on get_post_type() falling back to the global internaly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public function apply_event_content( string $content ): string {

// Only apply to events.
if ( Event::POST_TYPE !== get_post_type( get_the_ID() ) ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost the same as above: I would remove the get_the_ID() and rely on get_post_type() falling back to the global internaly.

Copy link
Copy Markdown
Collaborator Author

@jmarx jmarx Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @return string The customized excerpt.
*/
public function get_default_event_excerpt( string $excerpt ): string {
global $post;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmarx you still have the global $post and have $post passing as an argument.

protected function __construct() {
// Initialize the rewrite slug from settings.
$settings = Settings::get_instance();
$this->rewrite_slug = $settings->get_value( 'general', 'urls', 'events' );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmarx this is your text domain issue. You're only using the rewrite_slug once so no need to make it a property of the class. Just add this code where you use it and just make it a regular variable.

*
* @return void
*/
public function instantiate_event_feed(): void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmarx you don't need to do this (see my comment above). You can put it back where singletons initialize. You need to move that code out of the constructor and into an init hook.

* @coversDefaultClass \GatherPress\Core\Event_Feed
*/
class Test_Event_Feed extends Base {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line break.

@jmarx
Copy link
Copy Markdown
Collaborator Author

jmarx commented Aug 15, 2025

@mauteri @carstingaxion Sorry for the sloppiness there. Can you check again?

@jmarx jmarx requested a review from mauteri August 15, 2025 12:18
* @var string
*/
private $rewrite_slug;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line breaks

*/
public function get_default_event_excerpt( string $excerpt ): string {
global $post;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line break

* @return void
*/
public function instantiate_event_feed(): void {
Event_Feed::get_instance();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put in alphabetical order

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done

* @return string The customized content.
*/
public function apply_event_content( string $content ): string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line break

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauteri Done

@jmarx jmarx requested a review from mauteri August 15, 2025 12:34
@github-actions
Copy link
Copy Markdown
Contributor

Preview changes with Playground

You can preview the recent changes for PR#1146 with the following PHP versions:

PHP Version 8.3

PHP Version 7.4

Download .zip with build changes

Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions.

@mauteri mauteri merged commit 06d6ff8 into develop Sep 10, 2025
16 checks passed
@mauteri mauteri deleted the 901/improve-feeds branch September 10, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve default feeds

3 participants