Conversation
PR Summary
|
mauteri
left a comment
There was a problem hiding this comment.
@carstingaxion mind reviewing and adding some feedback on this too? Thx!
| * | ||
| * @since 1.0.0 | ||
| */ | ||
| class Feed_Improvements { |
There was a problem hiding this comment.
Change name to Event_Feed and class-event-feed.php and make additional updates that match this change.
| if ( ! get_option( 'gatherpress_events_feed_rewrite_flushed' ) ) { | ||
| flush_rewrite_rules(); | ||
| update_option( 'gatherpress_events_feed_rewrite_flushed', true ); | ||
| } |
There was a problem hiding this comment.
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
| } | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Remove extra line breaks, should just be one.
| * @param \WP $wp WordPress environment instance. | ||
| * @return void | ||
| */ | ||
| public function intercept_events_feed( \WP $wp ): void { |
There was a problem hiding this comment.
add use WP and only have WP here.
There was a problem hiding this comment.
@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 () { |
There was a problem hiding this comment.
@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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@mauteri Done. Using the existing logic now
| } | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
remove extra line breaks, just 1
| * | ||
| * @return void | ||
| */ | ||
| public function force_events_feed(): void { |
There was a problem hiding this comment.
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.
|
|
||
| // Remove any comment-related query vars. | ||
| $query->set( 'comments', false ); | ||
| $query->set( 'comment_feed', false ); |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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 { |
There was a problem hiding this comment.
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.
| 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/?$', |
There was a problem hiding this comment.
I feel like the slug should be a setting (at least eventually)
There was a problem hiding this comment.
@mauteri I handled this as well. I didn't realize that setting was already available.
|
@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; | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
Hi @jmarx,
I'm sorry that I need to ask again: Why are you creating that new rewrite_rule?
I don't get it.
There was a problem hiding this comment.
@carstingaxion
Sorry, I completely misunderstood your comment/question. I get what you're saying now. I removed the redundant rewrite rule.
| // Check if this is /events/feed/. | ||
| if ( strpos( $request_uri, '/events/feed' ) !== false ) { |
There was a problem hiding this comment.
It might be better to build the URL based on the gatherpress_general['urls']['events'] setting and not with the hardcoded 'events' string.
There was a problem hiding this comment.
@carstingaxion I am using the setting now.
| // 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' ) ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
@carstingaxion OK, I implemented some filters to make sure it can be overwritten if need be:
0608028
|
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; |
|
@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 ) { |
There was a problem hiding this comment.
You missed this.
if ( ! empty( $display_datetime ) && '—' !== $display_datetime ) {
@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' ) ) { |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
Please add some docs about using this filter, too.
| * @return string The customized content. | ||
| */ | ||
| public function apply_event_content( string $content ): string { | ||
| global $post; |
There was a problem hiding this comment.
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/
|
@mauteri @carstingaxion I think we should be good now? |
carstingaxion
left a comment
There was a problem hiding this comment.
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_eventpost type archive feed -
gatherpress_topictaxonomy archive feed -
_gatherpress_venuetaxonomy archive feed
@carstingaxion Agreed. But should we not do that in a follow up ticket? To keep these prs/chunks of work, tight? |
|
@carstingaxion I suggest we have Andrew Short create follow up tickets for those feeds. And we can use this as model. |
| * @return string The customized excerpt. | ||
| */ | ||
| public function get_default_event_excerpt( string $excerpt ): string { | ||
| global $post; |
There was a problem hiding this comment.
| 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.
There was a problem hiding this comment.
@carstingaxion Fixed. I swear I tried this and it was not working before. But it's good now.
There was a problem hiding this comment.
@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; |
There was a problem hiding this comment.
Same as above: I would remove the global $post and rely on get_post_type() falling back to the global internaly.
| * @return string The customized excerpt. | ||
| */ | ||
| public function apply_event_excerpt( string $excerpt ): string { | ||
| global $post; |
There was a problem hiding this comment.
Same as above: I would remove the global $post and rely on get_post_type() falling back to the global internaly.
| public function apply_event_content( string $content ): string { | ||
|
|
||
| // Only apply to events. | ||
| if ( Event::POST_TYPE !== get_post_type( get_the_ID() ) ) { |
There was a problem hiding this comment.
Almost the same as above: I would remove the get_the_ID() and rely on get_post_type() falling back to the global internaly.
| * @return string The customized excerpt. | ||
| */ | ||
| public function get_default_event_excerpt( string $excerpt ): string { | ||
| global $post; |
There was a problem hiding this comment.
@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' ); |
There was a problem hiding this comment.
@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 { |
There was a problem hiding this comment.
@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 { | ||
|
|
|
@mauteri @carstingaxion Sorry for the sloppiness there. Can you check again? |
| * @var string | ||
| */ | ||
| private $rewrite_slug; | ||
|
|
| */ | ||
| public function get_default_event_excerpt( string $excerpt ): string { | ||
| global $post; | ||
|
|
| * @return void | ||
| */ | ||
| public function instantiate_event_feed(): void { | ||
| Event_Feed::get_instance(); |
| * @return string The customized content. | ||
| */ | ||
| public function apply_event_content( string $content ): string { | ||
|
|
Preview changes with PlaygroundYou can preview the recent changes for PR#1146 with the following PHP versions: PHP Version 8.3
PHP Version 7.4
Download Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions. |


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
Checklist: