Skip to content

Conversation

@arifulhoque7
Copy link
Contributor

@arifulhoque7 arifulhoque7 commented Dec 24, 2025

fix: resolve subscription post number rollback toggle not saving
Close 1342

The postnum_rollback_on_delete meta field was missing from the REST API
save handler in includes/Api/Subscription.php. Added extraction and
persistence of the field value when creating or updating subscriptions
via the Vue.js-based subscription editor.

  • Added $postnum_rollback_on_delete variable extraction at line 463
  • Added update_post_meta() call for postnum_rollback_on_delete at line 540
  • Properly sanitized using sanitize_text_field()
  • Fixes issue where toggle would revert to off after save/publish

Summary by CodeRabbit

  • Bug Fixes
    • Subscription rollback flag is now read and reliably persisted across create, update and payment gateway flows so deletion rollback behavior is applied consistently.
  • Chores / Admin
    • The post-number rollback option is now marked as a Pro-only admin field in subscription settings.

✏️ Tip: You can customize this high-level summary in your review settings.

@arifulhoque7 arifulhoque7 requested a review from sapayth December 24, 2025 03:46
@arifulhoque7 arifulhoque7 self-assigned this Dec 24, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 24, 2025

Walkthrough

Adds handling and persistence for a new subscription meta postnum_rollback_on_delete (normalized to '' or 'yes') across create/update flows and PayPal handling; marks the post number rollback field as Pro in admin field definitions. No public signatures changed.

Changes

Cohort / File(s) Summary
Subscription meta handling
includes/Api/Subscription.php, includes/Admin/Admin_Subscription.php
Read and normalize postnum_rollback_on_delete from incoming meta ('' or 'yes'), persist via update_post_meta during create/update flows; add is_pro => true to post_number_rollback field config in admin.
PayPal gateway flag read
Lib/Gateway/Paypal.php
Use pack_meta['postnum_rollback_on_delete'] as source and set value to 'yes' only when exactly 'yes'; otherwise keep '' before applying rollback logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

dev: on-progress

Suggested reviewers

  • sapayth
  • Rubaiyat-E-Mohammad

Poem

🐰 I hop through meta fields at dawn,
I tidy flags and keep them on,
I save a rollback, soft and small,
A pro-marked tweak, both neat and tall,
🥕— Rabbit guards the subscription hall.

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 describes the main change: fixing the subscription post number rollback toggle not saving to the database. It directly reflects the core issue addressed in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

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

@arifulhoque7 arifulhoque7 added needs: dev review This PR needs review by a developer needs: testing labels Dec 24, 2025
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: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7d7e76 and 039131a.

📒 Files selected for processing (1)
  • includes/Api/Subscription.php
🧰 Additional context used
🧬 Code graph analysis (1)
includes/Api/Subscription.php (1)
includes/Traits/FieldableTrait.php (1)
  • update_post_meta (367-477)
🪛 GitHub Actions: Inspections
includes/Api/Subscription.php

[error] 1-1: Whitespace found at end of line.

🔇 Additional comments (1)
includes/Api/Subscription.php (1)

540-540: Implementation looks correct.

The persistence logic correctly follows the established pattern for saving subscription meta fields. The sanitized value from line 463 is properly saved using update_post_meta().

Updated logic in Paypal gateway and Subscription API to ensure 'postnum_rollback_on_delete' is set to 'yes' only if explicitly set, otherwise defaults to an empty string. This improves consistency in how the value is handled across the codebase.
Refactored the logic for 'postnum_rollback_on_delete' to directly use the value from metadata if set, and sanitized it in the API. Also marked the 'postnum_rollback_on_delete' option as a pro feature in the admin subscription settings.
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 (1)
includes/Api/Subscription.php (1)

463-465: Consider normalizing toggle value to enforce 'yes' or '' only.

The extraction logic is consistent with other toggle fields in the codebase. However, it accepts any string value after sanitization rather than explicitly normalizing to the expected toggle values ('yes' or ''). This could allow inconsistent values like 'no', 'false', or 'off' to be stored if sent from the frontend.

🔎 Proposed normalization logic
-        $postnum_rollback_on_delete = ! empty( $subscription['meta_value']['postnum_rollback_on_delete'] ) ? sanitize_text_field(
-            $subscription['meta_value']['postnum_rollback_on_delete']
-        ) : '';
+        $postnum_rollback_on_delete = '';
+        if ( ! empty( $subscription['meta_value']['postnum_rollback_on_delete'] ) ) {
+            $value = sanitize_text_field( $subscription['meta_value']['postnum_rollback_on_delete'] );
+            $postnum_rollback_on_delete = ( 'yes' === $value ) ? 'yes' : '';
+        }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7664802 and e5fc4ee.

📒 Files selected for processing (3)
  • Lib/Gateway/Paypal.php
  • includes/Admin/Admin_Subscription.php
  • includes/Api/Subscription.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • Lib/Gateway/Paypal.php
🔇 Additional comments (2)
includes/Admin/Admin_Subscription.php (1)

1342-1342: LGTM! Pro feature flag correctly added.

The addition of the is_pro flag follows the established pattern (consistent with line 1405) and correctly marks the post number rollback feature as Pro-only.

includes/Api/Subscription.php (1)

540-540: LGTM!

The persistence logic correctly saves the postnum_rollback_on_delete value and follows the established pattern of other meta field updates in this method.

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added bug QA Approved This PR is approved by the QA team and removed needs: testing bug labels Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: dev review This PR needs review by a developer QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants