Skip to content

Commit 3b2059e

Browse files
committed
New table to hold subscriber events
1 parent 5c45117 commit 3b2059e

8 files changed

Lines changed: 485 additions & 58 deletions

CLAUDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ FreemKit is a WordPress plugin (v1.0.0-beta1) that bridges Freemius software lic
99
## Commands
1010

1111
### PHP
12+
1213
```bash
1314
composer phpcs # Lint PHP (WordPress coding standards)
1415
composer phpcbf # Auto-fix PHP code style
@@ -20,6 +21,7 @@ composer zip # Create distribution zip
2021
```
2122

2223
### JavaScript/CSS
24+
2325
```bash
2426
npm run build # Build JS/CSS assets with wp-scripts
2527
npm run build:assets # Minify CSS/JS and generate RTL CSS (node build-assets.js)
@@ -33,30 +35,35 @@ npm run zip # Create plugin zip via wp-scripts
3335
## Architecture
3436

3537
### Entry Point & Bootstrap
38+
3639
`freemkit.php` defines constants (`FREEMKIT_VERSION`, `FREEMKIT_PLUGIN_FILE`, `FREEMKIT_PLUGIN_DIR`, `FREEMKIT_PLUGIN_URL`), loads Kit shared library classes from `vendor/convertkit/convertkit-wordpress-libraries/`, registers the autoloader, and calls `\WebberZone\FreemKit\load()` on `plugins_loaded`.
3740

3841
**Autoloader convention:** Namespace segments become path segments under `includes/`; underscores → hyphens, lowercase, last segment prefixed with `class-`. e.g. `WebberZone\FreemKit\Admin\Settings``includes/admin/class-settings.php`.
3942

4043
### Core Components
44+
4145
- **`Main`** (`includes/class-main.php`) — Singleton. Instantiates `Runtime`, `Kit_Credential_Hooks`, and `Language_Handler`; registers hooks via `Hook_Registry`.
4246
- **`Runtime`** (`includes/class-runtime.php`) — Initializes `Database`, `Kit_API`, and `Webhook_Handler` on `init`. Creates the `Admin` object when in admin context.
4347
- **`Webhook_Handler`** (`includes/class-webhook-handler.php`) — Core logic. Registers a REST endpoint at `freemkit/v1/webhook` (or a query-var fallback). Validates HMAC-SHA256 signatures (`x-signature` header) and webhook freshness (15-minute window). Queues events as WP transients and processes them asynchronously via WP-Cron (`freemkit_process_webhook_event`). Includes deduplication via `freemkit_webhook_seen_*` transients, and exponential-backoff retry (max 3 attempts).
4448
- **`Database`** (`includes/class-database.php`) — Manages the `{prefix}freemkit_subscribers` custom table, which persists subscriber records locally.
4549
- **`Options_API`** (`includes/class-options-api.php`) — All settings stored as a single `freemkit_settings` array in `wp_options`. Access via `Options_API::get_option($key)` / `Options_API::get_settings()`. Sensitive keys (access/refresh tokens) are encrypted at rest using AES-256-CBC (OpenSSL) or libsodium.
4650

4751
### Kit Integration (`includes/kit/`)
52+
4853
- **`Kit_API`** — Wraps `ConvertKit_API_V4` to subscribe users to forms and apply tags.
4954
- **`Kit_Settings`** — Manages OAuth tokens (`kit_access_token`, `kit_refresh_token`). Falls back to the official Kit WordPress plugin's stored credentials if available.
5055
- **`Kit_Credential_Hooks`** — Listens for `freemkit_api_get_access_token` / `freemkit_api_refresh_token` / `convertkit_api_access_token_invalid` actions to keep tokens in sync.
5156
- **`Kit_Audit_Log`** — Logs Kit API interactions.
5257

5358
### Admin (`includes/admin/`)
59+
5460
- **`Admin`** — Admin menu, settings page, subscriber list screen.
5561
- **`Settings`** / **`Settings_Wizard`** — Settings pages; wizard is shown on first activation. Settings include: global Kit form/tag defaults, per-plugin overrides (free and paid form IDs, tag IDs, event types), custom field mappings, webhook endpoint type (REST vs query-var).
5662
- **`Kit_OAuth`** — OAuth flow for connecting to Kit.
5763
- **`Subscribers_List`** / **`Subscribers_List_Table`** — Admin screen displaying the local `freemkit_subscribers` table.
5864

5965
### Utilities (`includes/util/`)
66+
6067
- **`Hook_Registry`** — Static registry for all registered actions/filters; prevents duplicates (same pattern as CRP).
6168

6269
## Key Patterns

includes/admin/class-subscribers-list-table.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function get_columns(): array {
7272
'status' => __( 'Status', 'freemkit' ),
7373
'created' => __( 'Created', 'freemkit' ),
7474
'fields' => __( 'Fields', 'freemkit' ),
75-
'tags' => __( 'Tags', 'freemkit' ),
76-
'forms' => __( 'Forms', 'freemkit' ),
75+
'plugins' => __( 'Plugins', 'freemkit' ),
7776
);
7877

7978
return $columns;
@@ -165,11 +164,12 @@ public function column_default( $item, $column_name ): string {
165164
case 'last_name':
166165
return esc_html( $item->last_name );
167166

168-
case 'tags':
169-
return esc_html( implode( ', ', $item->tags ) );
167+
case 'fields':
168+
return esc_html( implode( ', ', (array) $item->fields ) );
170169

171-
case 'forms':
172-
return esc_html( implode( ', ', $item->forms ) );
170+
case 'plugins':
171+
$slugs = $this->database->get_subscriber_plugin_slugs( $item->id );
172+
return esc_html( implode( ', ', $slugs ) );
173173

174174
case 'status':
175175
return esc_html( $item->status );

includes/admin/class-subscribers-list.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public function render_page() {
9797
?>
9898
<div class="wrap">
9999
<h1><?php esc_html_e( 'FreemKit - Subscribers', 'freemkit' ); ?></h1>
100-
<a href="<?php echo esc_url( admin_url( 'options-general.php?page=freemkit_options_page' ) ); ?>" class="page-title-action"><?php esc_html_e( 'View Settings', 'freemkit' ); ?></a>
101100
<?php do_action( 'freemkit_subscribers_page_header' ); ?>
102101

103102
<div id="poststuff">

0 commit comments

Comments
 (0)