Skip to content

reinstate se_event_get_dates() for legacy sites#46

Merged
gin0115 merged 3 commits intotrunkfrom
feature/reinstate-se_event_get_dates_func
Sep 18, 2025
Merged

reinstate se_event_get_dates() for legacy sites#46
gin0115 merged 3 commits intotrunkfrom
feature/reinstate-se_event_get_dates_func

Conversation

@gin0115
Copy link
Collaborator

@gin0115 gin0115 commented Sep 18, 2025

Changes proposed in this Pull Request

This pull request updates legacy date handling in the event functions to better align with the new event date format and improve backward compatibility. The main focus is on ensuring that the deprecated se_event_get_dates function returns data in the expected legacy structure while internally using the new se_event_get_event_dates function.

Legacy compatibility and function updates:

  • Updated the se_event_get_dates function to internally call se_event_get_event_dates, then map the results to the legacy format expected by older code. The function now returns an array of associative arrays with datetime_start, datetime_end, and all_day keys, ensuring compatibility for code relying on the old structure.
  • Removed the redundant legacy filter (se_event_get_dates) from the se_event_get_event_dates function to avoid double filtering and maintain a single source of truth for event date data.

Testing instructions

  • Sites with custom functionality that works with dates, will now be able to continue with old syntax, as we map to the old structure

Mentions #

Summary by CodeRabbit

  • Refactor

    • Switched event date handling to a single modern format with automatic translation for older integrations, improving consistency and reliability.
    • Removed deprecated legacy pathways to reduce ambiguity and conflicts in date processing.
  • Documentation

    • Clarified parameter usage and specified the exact return structure for event date data to aid developers.
  • Chores

    • Removed obsolete legacy filters and cleaned up related routing to align with current standards.

@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

se_event_get_dates now calls se_event_get_event_dates, maps each new-format date (start_date, end_date, all_day) to the legacy shape (datetime_start, datetime_end, all_day), and returns that mapped array. The legacy filter path for se_event_get_dates was removed and se_event_get_event_dates no longer applies the legacy se_event_get_dates filter; dates are returned only via the se_event_get_event_dates filter. Docblocks for se_event_get_dates were updated to mark the $event_dates parameter as not used and to specify a precise array return type.

Possibly related PRs

  • doing it wrong and more tempalte issues #32: Modifies the same functions (se_event_get_dates and se_event_get_event_dates) in src/event-functions.php, changing how new-format event dates are exposed to legacy callers and how legacy filtering/deprecation is handled.

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 "reinstate se_event_get_dates() for legacy sites" is concise and directly reflects the PR's primary change: bringing back the legacy se_event_get_dates function to provide compatibility for older sites by mapping the new event date format to the legacy structure. It is specific, relevant to the changeset, and clear enough for a teammate scanning history to understand the main intent.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

📜 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 fcd48ec and a294b7d.

📒 Files selected for processing (1)
  • src/event-functions.php (1 hunks)

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

@gin0115 gin0115 merged commit 0368b42 into trunk Sep 18, 2025
6 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 (3)
src/event-functions.php (3)

133-142: Cast to int/bool to match declared return shape.

se_event_get_event_dates() currently returns timestamps as strings (from get_post_meta + esc_attr). Cast here to honor the docblock and avoid subtle numeric/string comparisons downstream.

   $dates = array_map(
     function ( $date ) {
       return array(
-        'datetime_start' => $date['start_date'],
-        'datetime_end'   => $date['end_date'],
-        'all_day'        => $date['all_day'],
+        'datetime_start' => (int) $date['start_date'],
+        'datetime_end'   => (int) $date['end_date'],
+        'all_day'        => (bool) $date['all_day'],
       );
     },
     $dates
   );

121-126: Docblock tweak: clarify legacy param (and quiet analyzers).

Since $event_dates exists for legacy BC (and is forwarded in the filter per above), clarify that in the docblock. If you decide not to forward it, add PHPMD suppression.

- * @param array   $event_dates Event dates, not used.
+ * @param array|null $event_dates Legacy event dates; forwarded to the `se_event_get_dates` filter for BC.

Optional (only if not forwarding):

+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)

129-131: Emit a runtime deprecation notice.

Surface deprecation consistently (as done elsewhere) to help integrators migrate.

 // Get dates in new format.
+$deprecated_replacement = 'se_event_get_event_dates';
+_deprecated_function( __FUNCTION__, '2.0.0', $deprecated_replacement );
 $dates = se_event_get_event_dates( $event_id );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89b0a75 and fcd48ec.

📒 Files selected for processing (1)
  • src/event-functions.php (1 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
src/event-functions.php

127-127: Avoid unused parameters such as '$event_dates'. (undefined)

(UnusedFormalParameter)

🪛 GitHub Actions: PHP Coding Standards
src/event-functions.php

[warning] 127-127: PHPCS: The method parameter '$event_dates' is never used. (Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed)

🔇 Additional comments (1)
src/event-functions.php (1)

144-148: Preserve filter arg count — pass $event_dates as 3rd argument.

Add the original $event_dates (may be null) to apply_filters() to preserve BC and avoid PHP 8 "Too few arguments" fatals / PHPCS warnings.

File: src/event-functions.php (around lines 144–148)

 return apply_filters(
   'se_event_get_dates',
-  $dates,
-  $event_id
+  $dates,
+  $event_id,
+  $event_dates
 );

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