Conversation
WalkthroughAdds a configurable cookie TTL option exposed in admin, uses that value to compute cookie expiries in runtime state logic, and replaces inline guide/code-block styling with two new CSS classes used in the admin template. Changes
Sequence Diagram(s)sequenceDiagram
actor Admin
participant UI as Paywall Settings UI
participant WP as WordPress Options
participant State as PayButton_State
participant Browser as User Browser
Admin->>UI: submit paybutton_cookie_ttl_days
UI->>WP: update_option('paybutton_cookie_ttl_days', value)
WP-->>UI: saved
Browser->>State: user action (view/unlock)
State->>WP: get_option('paybutton_cookie_ttl_days')
WP-->>State: TTL days (or 0)
State->>State: compute TTL seconds (get_ttl)
State->>Browser: Set-Cookie / Expires using computed TTL
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
includes/class-paybutton-state.php (1)
12-40: TTL helper implementation looks good; consider tightening the “unlimited” wording
get_ttl()correctly derives a TTL frompaybutton_cookie_ttl_daysand falls back toTTL = 31536000when the option is 0/empty. However, the docblock currently calls this an “unlimited default”, while the constant encodes a fixed ~1‑year lifetime. To avoid confusion (especially alongside the admin‑UI text), I’d suggest rephrasing docs to “long‑lived default” or similar rather than “unlimited”.includes/class-paybutton-admin.php (1)
205-229: TTL days option wiring and sanitization look solid
paybutton_cookie_ttl_daysis correctly loaded for the template and, on save, normalized to a non‑negative integer viasanitize_text_field+(int)with a< 0clamp to 0 beforeupdate_option. This gives a clear 0‑or‑more contract toPayButton_State::get_ttl()and keeps unexpected input from breaking cookie expiry logic. If you ever want to be extra defensive, you could also cap very large values (e.g., to align with the 400‑day browser guidance mentioned inPayButton_State::TTLdocs), but it’s not strictly necessary.Also applies to: 290-305
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
assets/css/paybutton-admin.css(1 hunks)includes/class-paybutton-admin.php(3 hunks)includes/class-paybutton-state.php(5 hunks)templates/admin/paywall-settings.php(3 hunks)
🔇 Additional comments (3)
includes/class-paybutton-state.php (1)
135-153: Consistent TTL use across modern and legacy cookie pathsUsing a single
$ttl = self::get_ttl();and applyingtime() + $ttlin both the array‑basedsetcookie()call and the legacyExpires=header keeps behavior consistent forCOOKIE_USER_ADDRandCOOKIE_CONTENT. This cleanly wires the new setting into both cookies without changing any other semantics.Also applies to: 230-249
assets/css/paybutton-admin.css (1)
295-311: New utility classes nicely replace inline styles
.pre-boxand.paybutton-guideprovide reusable styling for code blocks and the guide panel, which is cleaner than inline styles and keeps the admin UI consistent.templates/admin/paywall-settings.php (1)
231-267: Guide and code samples refactor is cleanMoving the PayButton public‑key setup guide to use
.paybutton-guideand.pre-boxinstead of inline styles, withesc_url()for the trigger URL and literal JSON shown in<pre>, keeps the markup readable and styling centralized in CSS. No issues here.
This PR implements #76 by adding a configurable cookie expiry setting for both login and content unlock sessions.
A new “Login & Content Unlock Cookie Expiry” field has been introduced in Paywall Settings, allowing site admins to define how long user authentication and unlock cookies remain valid. The default value of 0 maintains existing behavior (long-lived almost 1 year, effectively unlimited cookies), while any positive number enforces a custom automatic logout period. Also moved some in-line CSS in the Paywall Settings page to it's seprate CSS file.
Test Plan
Summary by CodeRabbit
New Features
Style
✏️ Tip: You can customize this high-level summary in your review settings.
Greptile Overview
Greptile Summary
Added configurable cookie TTL setting for login and content unlock sessions, defaulting to unlimited (1 year) with admin-configurable automatic logout periods.
Key Changes:
get_ttl()method inPayButton_Statecalculates cookie expiry based on admin settingspaybutton-admin.cssDAY_IN_SECONDSconstant for compatibilityThe implementation is clean, well-documented, and follows WordPress best practices for option handling and input sanitization.
Confidence Score: 5/5
Important Files Changed
File Analysis
.pre-box,.paybutton-guide) to CSS file for better maintainabilitySequence Diagram
sequenceDiagram participant Admin as Site Admin participant Settings as Paywall Settings Page participant DB as WordPress Options participant State as PayButton_State participant Browser as User Browser Admin->>Settings: Configure cookie TTL (days) Settings->>DB: save_settings()<br/>update_option('paybutton_cookie_ttl_days', value) Note over Admin,DB: Cookie TTL stored in database<br/>(0 = unlimited, >0 = custom days) User->>State: User logs in or unlocks content State->>DB: get_option('paybutton_cookie_ttl_days', 0) DB-->>State: Returns TTL days alt TTL days > 0 State->>State: get_ttl()<br/>Calculate: days * DAY_IN_SECONDS Note over State: Custom expiry period else TTL days = 0 State->>State: get_ttl()<br/>Return TTL constant (1 year) Note over State: Long-lived "unlimited" cookie end State->>Browser: setcookie()<br/>expires: time() + calculated_ttl Browser-->>User: Cookie set with TTL Note over Browser: Cookie automatically expires<br/>after configured period