| 1 |
# Admin/Settings Module — Phase 4 Implementation Notes |
| 2 |
|
| 3 |
**Date:** 2026-03-04 |
| 4 |
**Phase:** 4 — Implementation (COMPLETE) |
| 5 |
**PHP syntax check:** PASS (both files) |
| 6 |
|
| 7 |
--- |
| 8 |
|
| 9 |
## Files Modified |
| 10 |
|
| 11 |
### 1. `abilities/class-cartflows-ability-config.php` |
| 12 |
|
| 13 |
Added a new section `// Admin / Settings — Read` and `// Admin / Settings — Write` containing 6 ability entries, inserted just before `); // end $abilities`. |
| 14 |
|
| 15 |
**Entries added:** |
| 16 |
- `CARTFLOWS_ABILITY_API_NAMESPACE . 'get-general-settings'` |
| 17 |
- `CARTFLOWS_ABILITY_API_NAMESPACE . 'get-store-checkout'` |
| 18 |
- `CARTFLOWS_ABILITY_API_NAMESPACE . 'get-permalink-settings'` |
| 19 |
- `CARTFLOWS_ABILITY_API_NAMESPACE . 'get-integration-settings'` |
| 20 |
- `CARTFLOWS_ABILITY_API_NAMESPACE . 'update-general-settings'` |
| 21 |
- `CARTFLOWS_ABILITY_API_NAMESPACE . 'update-permalink-settings'` |
| 22 |
|
| 23 |
### 2. `abilities/class-cartflows-ability-runtime.php` |
| 24 |
|
| 25 |
Added two new sections of execute callbacks immediately before the existing `// Private Helpers` section: |
| 26 |
- `// Execute Callbacks — Admin / Settings Read` (4 methods) |
| 27 |
- `// Execute Callbacks — Admin / Settings Write` (2 methods) |
| 28 |
|
| 29 |
**Methods added:** |
| 30 |
- `get_general_settings( $input )` |
| 31 |
- `get_store_checkout( $input )` |
| 32 |
- `get_permalink_settings( $input )` |
| 33 |
- `get_integration_settings( $input )` |
| 34 |
- `update_general_settings( $input )` |
| 35 |
- `update_permalink_settings( $input )` |
| 36 |
|
| 37 |
--- |
| 38 |
|
| 39 |
## Implementation Details |
| 40 |
|
| 41 |
### `get-general-settings` [Free — read] |
| 42 |
- Calls `\Cartflows_Helper::get_common_settings()` which reads `_cartflows_common` with defaults merged. |
| 43 |
- Returns: `default_page_builder`, `global_checkout`, `override_global_checkout`, `override_store_order_pay`, `disallow_indexing`. |
| 44 |
- Permission: `cartflows_manage_flows_steps` |
| 45 |
|
| 46 |
### `get-store-checkout` [Free — read] |
| 47 |
- Calls `\Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' )`. |
| 48 |
- Validates that the returned ID is a real `cartflows_flow` post before returning details. |
| 49 |
- Returns `is_configured: false` with zeroed fields if no store checkout is set or ID is invalid. |
| 50 |
- Permission: `cartflows_manage_flows_steps` |
| 51 |
|
| 52 |
### `get-permalink-settings` [Free — read] |
| 53 |
- Calls `\Cartflows_Helper::get_permalink_settings()` which reads `_cartflows_permalink` with defaults merged. |
| 54 |
- Returns: `permalink`, `permalink_flow_base`, `permalink_structure`. |
| 55 |
- Permission: `cartflows_manage_flows_steps` |
| 56 |
|
| 57 |
### `get-integration-settings` [Free — read] |
| 58 |
- Accepts optional `integration` enum: `facebook | google_analytics | google_ads | tiktok | pinterest | snapchat | all` (default: `all`). |
| 59 |
- Maps each group to its WP option key and calls `\Cartflows_Helper::get_admin_settings_option()`. |
| 60 |
- Returns only the requested group(s) as an object. |
| 61 |
- Permission: `cartflows_manage_flows_steps` |
| 62 |
|
| 63 |
### `update-general-settings` [Free — write, option-gated] |
| 64 |
- Reads current settings via `\Cartflows_Helper::get_common_settings()`. |
| 65 |
- Iterates only `allowed_keys` — ignores any fields not explicitly whitelisted (protects `override_store_order_pay` and other keys from accidental clobber). |
| 66 |
- Merges changes via `wp_parse_args( $updates, $current )` — partial updates are safe. |
| 67 |
- Saves via `\Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, true )` (network-aware). |
| 68 |
- Permission: `cartflows_manage_flows_steps` + `cartflows_abilities_api_write` option gate. |
| 69 |
|
| 70 |
### `update-permalink-settings` [Free — write, option-gated] |
| 71 |
- Each field is individually optional; throws if no fields provided. |
| 72 |
- Falls back to `CARTFLOWS_STEP_PERMALINK_SLUG` / `CARTFLOWS_FLOW_PERMALINK_SLUG` constants if an empty string is passed (mirrors original AJAX handler's reset behaviour). |
| 73 |
- Calls `update_option( 'cartflows_permalink_refresh', true )` after save to flush rewrite rules. |
| 74 |
- Saves via `\Cartflows_Helper::update_admin_settings_option( '_cartflows_permalink', $new_settings, true )`. |
| 75 |
- Permission: `cartflows_manage_flows_steps` + `cartflows_abilities_api_write` option gate. |
| 76 |
|
| 77 |
--- |
| 78 |
|
| 79 |
## Schema Decisions |
| 80 |
|
| 81 |
- All read abilities: `idempotentHint: true`, `readOnlyHint: true`, `priority: 1.0`, `type: resource`. |
| 82 |
- All write abilities: `idempotentHint: true`, `readOnlyHint: false`, `priority: 2.0`, `type: tool`. |
| 83 |
- `get-general-settings`, `get-store-checkout`, `get-permalink-settings`: empty `properties: {}` input schema (no input required). |
| 84 |
- `get-integration-settings`: single optional `integration` enum input with default `all`. |
| 85 |
- `update-general-settings` / `update-permalink-settings`: all fields optional (no `required` array) — partial updates supported. |
| 86 |
- Write gate uses `cartflows_abilities_api_write` option (consistent with existing write abilities in the plugin). |
| 87 |
|