Skip to content

Conversation

@SebastianWiz
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/3122496162/91955?viewId=8172236

Summary

This snippet allows the user to limit the year options in Date Dropdown fields based on their min/max settings.

As noted in the snippet, this does not currently support min/max based on other date fields.

Quick examples: https://www.loom.com/share/0e0383b29876457a84060c66fc6fc29b

…ropdown year options based on configured min/max.
@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

Introduces a new PHP class GPLD_Limit_Year_Dropdown that filters Gravity Forms date year dropdown bounds based on configured limit-date options. The class registers hooks for gform_date_min_year and gform_date_max_year, computes adjusted year values from parsed date modifiers, and applies optional form and field scoping.

Changes

Cohort / File(s) Summary
New Year Dropdown Filtering
gp-limit-dates/gpld-limit-year-dropdown-options.php
Added GPLD_Limit_Year_Dropdown class with filter registration for date year bounds, core logic for timestamp computation from configured min/max date values, year extraction with clamping to respect default bounds, and optional form/field scoping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Date timestamp parsing logic: Verify handling of various date modifier formats ("today", numeric values, string/date modifiers) and edge cases
  • Year clamping behavior: Confirm that min/max year bounds are correctly inverted when applied to opposite filters and properly respect default constraints
  • Hook applicability checking: Ensure is_applicable correctly validates Gravity Perks Limit Dates availability, field type compatibility, and optional form/field scoping

Suggested reviewers

  • saifsultanc
  • veryspry

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a snippet to limit date dropdown year options based on configured min/max settings.
Description check ✅ Passed The description includes the required Context section with a ticket link and a Summary explaining the snippet's functionality with a demo link, aligning with the template structure.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch SebastianWiz-patch-1

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

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

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 7e88bf8

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)
gp-limit-dates/gpld-limit-year-dropdown-options.php (2)

43-43: Align variable assignments per coding standards.

PHPCS requires equals signs to be aligned with surrounding assignments for consistency.

As per coding guidelines.

Apply this diff to fix the alignment:

-	$options = gp_limit_dates()->get_limit_dates_field_options( $field );
-	$date_key = $type . 'Date';
-	$mod_key = $type . 'DateMod';
+	$options  = gp_limit_dates()->get_limit_dates_field_options( $field );
+	$date_key = $type . 'Date';
+	$mod_key  = $type . 'DateMod';
-	$date_value = $options[ $date_key ];
-	$modifier = rgar( $options, $mod_key );
+	$date_value = $options[ $date_key ];
+	$modifier   = rgar( $options, $mod_key );

Also applies to: 45-45, 52-52


54-54: Use strict comparison for type safety.

Prefer strict comparison (===) over loose comparison (==) when comparing to string literals.

Apply this diff:

-	if ( $date_value == '{today}' ) {
+	if ( $date_value === '{today}' ) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3324f97 and 7e88bf8.

📒 Files selected for processing (1)
  • gp-limit-dates/gpld-limit-year-dropdown-options.php (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PHP Lint (PR)
gp-limit-dates/gpld-limit-year-dropdown-options.php

[warning] 43-43: Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space (PHPCS: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)


[warning] 45-45: Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space (PHPCS: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)


[warning] 52-52: Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space (PHPCS: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)


[error] 67-67: date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead. (PHPCS: WordPress.DateTime.RestrictedFunctions.date_date)

🪛 GitHub Check: PHPCS (Files Changed)
gp-limit-dates/gpld-limit-year-dropdown-options.php

[failure] 67-67:
date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.


[warning] 52-52:
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space


[warning] 45-45:
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space


[warning] 43-43:
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

🔇 Additional comments (6)
gp-limit-dates/gpld-limit-year-dropdown-options.php (6)

10-28: LGTM! Clean and flexible design.

The constructor properly handles optional scoping and registers the necessary Gravity Forms filters.


30-36: LGTM! Simple and clean delegation.

The public filter methods correctly delegate to the shared helper with the appropriate type parameter.


38-72: LGTM! Core filtering logic is sound.

The year calculation and clamping logic is correct:

  • For min: uses max() to ensure the calculated minimum doesn't go below the form's default minimum
  • For max: uses min() to ensure the calculated maximum doesn't go above the form's default maximum

The handling of different date value types ('{today}', numeric field references, and date strings) is appropriate, and edge cases (failed strtotime() calls) are properly handled.


74-90: LGTM! Proper applicability checks.

The method correctly validates prerequisites (plugin availability, field type) and applies optional scoping filters.


95-98: Remember to customize the configuration values.

The hardcoded form_id (123) and field_id (4) are example values that should be replaced with the actual IDs from your Gravity Forms setup.

To find the correct form and field IDs, edit your form in Gravity Forms admin and inspect the field settings. Form IDs are shown in the form list, and field IDs appear in the field settings panel.


67-67: Use gmdate() to fix PHPCS warning—year extraction is timezone-agnostic.

Line 67 correctly flags the PHPCS issue with date(). Since strtotime() returns Unix timestamps (timezone-independent) and you're extracting only the year, gmdate() is the appropriate fix. It satisfies PHPCS standards and maintains consistency with the rest of the codebase.

The wp_date() alternative is unnecessary here since WordPress date functions aren't used elsewhere in this file, and year extraction doesn't require timezone-aware handling.

-		$calculated_year = date( 'Y', $timestamp );
+		$calculated_year = gmdate( 'Y', $timestamp );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants