Skip to content

Show the event passed message if not events and not rendered output#43

Merged
gin0115 merged 1 commit intotrunkfrom
fix/show-editor-message-if-all-dates-passed
Sep 17, 2025
Merged

Show the event passed message if not events and not rendered output#43
gin0115 merged 1 commit intotrunkfrom
fix/show-editor-message-if-all-dates-passed

Conversation

@gin0115
Copy link
Collaborator

@gin0115 gin0115 commented Sep 17, 2025

Changes proposed in this Pull Request

  • If an event has only passed events and set to hide passed events, we should show the Event passed message, over empty string.

Testing instructions

Mentions #

Summary by CodeRabbit

  • New Features
    • When an event has no dates to display (e.g., all dates are in the past), the event info block now shows a notice to visitors using your configured “Past event notice” text, if set.
    • The notice appears only when no other event details are rendered, improving clarity for users viewing past or undated events.

@coderabbitai
Copy link

coderabbitai bot commented Sep 17, 2025

Walkthrough

The change in src/classes/class-se-blocks.php adds a local variable $date_count = 0 within event_info_render. A new conditional branch checks when count($event_dates) == 0 and $output is empty; in that case, it retrieves se_options['past_event_notice'] and, if non-empty, appends a notice to $output as a div.wp-block-se-event-info containing p.se-event-past-notice with the notice text. Existing past-date filtering logic remains intact. No public method signatures were modified.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately captures the primary change: it states that the "event passed" message will be shown when there are no events to render and the output would otherwise be empty, which matches the PR summary and objectives. It is concise and focused on the main behavior change.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

@gin0115 gin0115 merged commit 8c3f52d into trunk Sep 17, 2025
6 of 7 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/classes/class-se-blocks.php (2)

265-265: Remove unused $date_count.

$date_count is never read; triggers PHPMD UnusedLocalVariable. Delete it to keep the scope clean.

-		$date_count = 0;

373-381: Ensure the notice shows with a sensible default (align editor vs front‑end).

In block_assets() you default the editor setting to "Event has passed" when the option is missing, but here the front‑end only renders a notice if the option exists and is non‑empty. This creates an editor/front‑end mismatch. Also prefer empty() over count(...) === 0 for safety.

-		// Maybe show the event passes message.
-		if ( 0 === count( $event_dates ) && '' === $output ) {
-			$options = get_option( 'se_options' );
-			if ( isset( $options['past_event_notice'] ) && ! empty( $options['past_event_notice'] ) ) {
-				$output .= '<div class="wp-block-se-event-info">';
-				$output .= '<p class="se-event-past-notice">' . esc_html( $options['past_event_notice'] ) . '</p>';
-				$output .= '</div>';
-			}
-		}
+		// Maybe show the event passed message.
+		if ( empty( $event_dates ) && '' === $output ) {
+			$options = get_option( 'se_options' );
+			$notice  = isset( $options['past_event_notice'] ) && $options['past_event_notice'] !== ''
+				? $options['past_event_notice']
+				: __( 'Event has passed', 'simple-events' );
+
+			$notice = trim( (string) $notice );
+			if ( $notice !== '' ) {
+				$output .= '<div class="wp-block-se-event-info">';
+				$output .= '<p class="se-event-past-notice">' . esc_html( $notice ) . '</p>';
+				$output .= '</div>';
+			}
+		}

Verification ask:

  • Confirm desired behavior when “Add to calendar links” are enabled. Since those append to $output earlier, the notice won’t render even if all dates are filtered out—consistent with “not rendered output,” but please verify this matches the product intent.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 020ca32 and 6b6a097.

📒 Files selected for processing (1)
  • src/classes/class-se-blocks.php (3 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
src/classes/class-se-blocks.php

265-265: Avoid unused local variables such as '$date_count'. (undefined)

(UnusedLocalVariable)

🔇 Additional comments (1)
src/classes/class-se-blocks.php (1)

278-278: No-op whitespace.

Nothing to do here.

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