Skip to content

Some cleanup for archiveW#27

Merged
gin0115 merged 4 commits intoa8cteam51:trunkfrom
gin0115:feature/allow-enabling-disabling-html-date-markup
Jul 24, 2025
Merged

Some cleanup for archiveW#27
gin0115 merged 4 commits intoa8cteam51:trunkfrom
gin0115:feature/allow-enabling-disabling-html-date-markup

Conversation

@gin0115
Copy link
Collaborator

@gin0115 gin0115 commented Jul 24, 2025

Changes proposed in this Pull Request

This pull request introduces a new utility class, SE_Event_Query_Utils, to centralize and simplify event query-related logic. It also adds a feature to toggle HTML output in date formatting and refactors several methods to improve maintainability and reusability.

Key Changes:

Centralization of Event Query Logic:

  • Introduced SE_Event_Query_Utils to encapsulate logic for filtering, modifying, and sorting event queries. This includes replacing inline implementations of filter_unique_parents_where, modify_event_posts, and fix_sort_order with calls to the new utility class. (plugin.php: [1] class-se-block-variations.php: [2] [3] [4] class-se-blocks.php: [5] [6] [7] class-se-event-post-type.php: [8]

HTML Toggle for Date Formatting:

  • Added a new property, use_html_in_date_output, to the SE_Date_Display_Formatter class to conditionally include or exclude HTML in the rendered date output. (class-date-display-formatter.php: [1] [2]
  • Updated methods in SE_Date_Display_Formatter to respect the use_html_in_date_output flag, ensuring flexibility in date rendering. (class-date-display-formatter.php: [1] [2] [3] [4]

Refactoring and Cleanup:

  • Removed redundant methods (filter_unique_parents_where, modify_event_posts_for_blocks, etc.) from SE_Blocks and SE_Block_Variations, delegating their functionality to SE_Event_Query_Utils. (class-se-blocks.php: [1] class-se-block-variations.php: [2]
  • Simplified pre_get_posts in SE_Event_Post_Type by using utility functions for unique parent filtering and post modification. (class-se-event-post-type.php: src/classes/class-se-event-post-type.phpL626-R651)

Minor Improvements:

These changes improve the codebase's modularity, maintainability, and flexibility while introducing a new feature for controlling HTML output in date formatting.

Testing instructions

Mentions #

Summary by CodeRabbit

  • New Features

    • Added a setting to toggle HTML markup in date outputs for improved styling.
    • Date outputs now respect the new setting, allowing either HTML-wrapped or plain text display.
  • Enhancements

    • Event date post titles now include both the event title and formatted start date for clearer identification.
    • Improved handling of event queries to support unique parent event filtering and correct ordering.
  • Bug Fixes

    • Fixed an issue in event archive templates to ensure correct parent post assignment for event date posts.
  • Refactor

    • Centralized event query and post modification logic into a new utility class for consistency and maintainability.
    • Replaced duplicated filter logic across multiple classes with shared utility methods.

@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces a new utility class, SE_Event_Query_Utils, to centralize event query filtering and post-processing logic, refactoring related code in several classes to delegate to these new static methods. It also adds a setting to toggle HTML wrapping in date output, updates date formatting logic to respect this setting, and improves event date post title formatting. Minor corrections and cleanup are also included.

Changes

File(s) Change Summary
plugin.php Added a require_once statement to include the new class-se-event-query-utils.php utility class.
src/classes/class-se-event-query-utils.php Introduced SE_Event_Query_Utils class with static methods for filtering SQL WHERE clauses, modifying event posts, fixing sort order, and managing event query filters.
src/classes/class-se-block-variations.php
src/classes/class-se-blocks.php
Refactored to delegate event post filtering, parent uniqueness, and sort order logic to SE_Event_Query_Utils methods. Removed redundant local methods now handled by the utility class.
src/classes/class-se-event-post-type.php Enhanced pre_get_posts to add filters and query vars for unique parent event filtering, using SE_Event_Query_Utils methods. Improved logic for handling "hide past events" and event date treatment modes.
src/classes/class-date-display-formatter.php Added $use_html_in_date_output property and logic to toggle HTML wrapping in date outputs based on a new setting. Modified date rendering methods to conditionally output HTML or plain text.
src/classes/class-se-settings.php Added a new setting field "Use HTML in date output" and a static method use_html_in_date_output() to retrieve its value.
src/event-functions.php Changed event date post title format to include both event title and formatted start date.
src/templates/content-archive.php Fixed variable reference in event date post handling, replacing $parent_post with $se_parent_post.
src/template-functions.php Added a blank line at the end of the file (no functional change).

Sequence Diagram(s)

sequenceDiagram
    participant WP_Query
    participant SE_Event_Query_Utils
    participant SE_Blocks
    participant SE_Block_Variations
    participant SE_Event_Post_Type

    SE_Blocks->>SE_Event_Query_Utils: add_event_query_filters(query, order, context)
    SE_Block_Variations->>SE_Event_Query_Utils: add_event_query_filters(query, order, context)
    SE_Event_Post_Type->>SE_Event_Query_Utils: add_event_query_filters(query, order, context)
    WP_Query->>SE_Event_Query_Utils: filter_unique_parents_where(where, query)
    WP_Query->>SE_Event_Query_Utils: modify_event_posts(posts, query, context)
    WP_Query->>SE_Event_Query_Utils: fix_sort_order(orderby, query)
    SE_Blocks->>SE_Event_Query_Utils: remove_event_query_filters(context)
    SE_Block_Variations->>SE_Event_Query_Utils: remove_event_query_filters(context)
    SE_Event_Post_Type->>SE_Event_Query_Utils: remove_event_query_filters(context)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • V2 main dev branch #21: Introduces the SE_Event_Query_Utils class and refactors event date post filtering and modification logic in SE_Blocks and SE_Block_Variations to delegate to this utility class, directly relating to the current PR’s changes.

Poem

In the warren of code, a new class appears,
Querying events with fewer fears.
HTML dates now wrap or not—
Settings decide what’s hot!
Titles grow smarter, bugs disappear,
A rabbit’s hop brings tidy cheer.
(And now, our events are crystal clear!)

((\
( -.-)
o_(")(")

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2dbfbdc and 896b3dc.

📒 Files selected for processing (10)
  • plugin.php (1 hunks)
  • src/classes/class-date-display-formatter.php (6 hunks)
  • src/classes/class-se-block-variations.php (3 hunks)
  • src/classes/class-se-blocks.php (2 hunks)
  • src/classes/class-se-event-post-type.php (3 hunks)
  • src/classes/class-se-event-query-utils.php (1 hunks)
  • src/classes/class-se-settings.php (2 hunks)
  • src/event-functions.php (1 hunks)
  • src/template-functions.php (1 hunks)
  • src/templates/content-archive.php (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gin0115 gin0115 merged commit 0bcb9c6 into a8cteam51:trunk Jul 24, 2025
6 of 7 checks passed
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.

1 participant