Skip to content

Commit 03a1467

Browse files
committed
Remove custom fields mapping and add Kit unsubscribe on delete
Remove last_name_field and custom_fields settings from subscribers configuration Remove custom_fields from cache clearing operations Add kit_unsubscribe_on_delete setting to optionally unsubscribe from Kit when deleting subscribers Implement Kit unsubscribe in bulk and single delete operations Add subscriber form handling and admin notices to Subscribers_List Update Subscribers_List_Table to show plugin names from events instead
1 parent c7115d9 commit 03a1467

14 files changed

Lines changed: 1237 additions & 191 deletions

includes/admin/class-kit-oauth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function get_settings_url(): string {
293293
* @return void
294294
*/
295295
public function clear_kit_cache(): void {
296-
foreach ( array( 'forms', 'tags', 'sequences', 'custom_fields' ) as $transient ) {
296+
foreach ( array( 'forms', 'tags', 'sequences' ) as $transient ) {
297297
delete_transient( 'freemkit_kit_' . $transient );
298298
}
299299
}

includes/admin/class-settings-wizard.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ public function get_wizard_steps(): array {
118118
array(
119119
'kit_form_id',
120120
'kit_tag_id',
121-
'last_name_field',
122-
'custom_fields',
123121
),
124122
$all_settings
125123
),
@@ -412,7 +410,6 @@ public function enqueue_wizard_tom_select_data( string $hook ): void {
412410
'endpoint' => '',
413411
'forms' => Settings::get_localized_kit_data( 'forms' ),
414412
'tags' => Settings::get_localized_kit_data( 'tags' ),
415-
'custom_fields' => Settings::get_localized_kit_data( 'custom_fields' ),
416413
'freemius_events' => Settings::get_localized_kit_data( 'freemius_events' ),
417414
'strings' => array(
418415
/* translators: %s: search term */

includes/admin/class-settings.php

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -450,53 +450,25 @@ public static function settings_kit(): array {
450450
*/
451451
public static function settings_subscribers(): array {
452452
$settings = array(
453-
'subscribers' => array(
453+
'subscribers' => array(
454454
'id' => 'subscribers',
455455
'name' => __( 'Subscribers', 'freemkit' ),
456456
'desc' => __( 'Configure your subscribers settings in this tab.', 'freemkit' ),
457457
'type' => 'header',
458458
),
459-
'respect_marketing_optout' => array(
459+
'respect_marketing_optout' => array(
460460
'id' => 'respect_marketing_optout',
461461
'name' => __( 'Respect Marketing Opt-out', 'freemkit' ),
462462
'desc' => __( 'When enabled, users who opt out of marketing on Freemius will be unsubscribed from Kit and blocked from future subscriptions.', 'freemkit' ),
463463
'type' => 'checkbox',
464464
'default' => 1,
465465
),
466-
'last_name_field' => array(
467-
'id' => 'last_name_field',
468-
'name' => __( 'Last Name field', 'freemkit' ),
469-
'desc' => __( 'Select the field name for mapping the last name in Kit. Note: Kit lacks a default last name field; a custom field must be created in your account first.', 'freemkit' ),
470-
'type' => 'text',
471-
'default' => '',
472-
'field_class' => 'ts_autocomplete',
473-
'field_attributes' => self::get_kit_search_field_attributes( 'custom_fields', array( 'maxItems' => 1 ) ),
474-
),
475-
'custom_fields' => array(
476-
'id' => 'custom_fields',
477-
'name' => __( 'Custom Fields', 'freemkit' ),
478-
'desc' => '',
479-
'type' => 'repeater',
480-
'live_update_field' => 'local_name',
481-
'default' => array(),
482-
'fields' => array(
483-
array(
484-
'id' => 'local_name',
485-
'name' => __( 'Field Local Name', 'freemkit' ),
486-
'desc' => __( 'Enter the name of your field that will be used locally in the database on this site.', 'freemkit' ),
487-
'type' => 'text',
488-
'default' => '',
489-
),
490-
array(
491-
'id' => 'remote_name',
492-
'name' => __( 'Field name on Kit', 'freemkit' ),
493-
'desc' => __( 'Enter the name of your custom field that is used on the Kit.', 'freemkit' ),
494-
'type' => 'text',
495-
'default' => '',
496-
'field_class' => 'ts_autocomplete',
497-
'field_attributes' => self::get_kit_search_field_attributes( 'custom_fields', array( 'maxItems' => 1 ) ),
498-
),
499-
),
466+
'kit_unsubscribe_on_delete' => array(
467+
'id' => 'kit_unsubscribe_on_delete',
468+
'name' => __( 'Unsubscribe from Kit on Delete', 'freemkit' ),
469+
'desc' => __( 'When enabled, deleting a subscriber will also unsubscribe them from Kit.', 'freemkit' ),
470+
'type' => 'checkbox',
471+
'default' => 0,
500472
),
501473
);
502474

@@ -515,7 +487,7 @@ public static function settings_subscribers(): array {
515487
*
516488
* @since 1.0.0
517489
*
518-
* @param string $endpoint The endpoint to search ('forms', 'tags', 'custom_fields', 'freemius_events').
490+
* @param string $endpoint The endpoint to search ('forms', 'tags', 'freemius_events').
519491
* @param array $ts_config Optional TypeScript configuration.
520492
* @return array Field attributes array
521493
*/
@@ -706,7 +678,6 @@ public function admin_enqueue_scripts( $hook ) {
706678
'endpoint' => '',
707679
'forms' => self::get_localized_kit_data( 'forms' ),
708680
'tags' => self::get_localized_kit_data( 'tags' ),
709-
'custom_fields' => self::get_localized_kit_data( 'custom_fields' ),
710681
'freemius_events' => self::get_localized_kit_data( 'freemius_events' ),
711682
'strings' => array(
712683
/* translators: %s: search term */
@@ -906,12 +877,12 @@ public function handle_kit_search() {
906877
case 'tags':
907878
$data = $this->get_kit_tags( $query );
908879
break;
909-
case 'custom_fields':
910-
$data = $this->get_kit_custom_fields( $query );
911-
break;
912880
case 'freemius_events':
913881
$data = Freemius::get_events( $query );
914882
break;
883+
case 'custom_fields':
884+
$data = self::get_kit_data( 'custom_fields', $query );
885+
break;
915886
default:
916887
$data = array();
917888
break;
@@ -962,7 +933,7 @@ public function ajax_refresh_lists() {
962933
wp_send_json_error( (object) array( 'message' => esc_html__( 'You do not have permission to perform this action.', 'freemkit' ) ) );
963934
}
964935

965-
foreach ( array( 'forms', 'tags', 'sequences', 'custom_fields' ) as $transient ) {
936+
foreach ( array( 'forms', 'tags', 'sequences' ) as $transient ) {
966937
delete_transient( 'freemkit_kit_' . $transient );
967938
}
968939

@@ -1276,7 +1247,13 @@ public static function normalize_kit_items( array $items, string $type ): array
12761247
continue;
12771248
}
12781249

1279-
$id = isset( $item['id'] ) ? (string) $item['id'] : ( isset( $item['key'] ) ? (string) $item['key'] : '' );
1250+
// Custom fields: use the API key (e.g. 'last_name') not the numeric ID,
1251+
// because Kit's update_subscriber endpoint expects field keys in the fields object.
1252+
if ( 'custom_fields' === $type && isset( $item['key'] ) ) {
1253+
$id = (string) $item['key'];
1254+
} else {
1255+
$id = isset( $item['id'] ) ? (string) $item['id'] : ( isset( $item['key'] ) ? (string) $item['key'] : '' );
1256+
}
12801257
if ( '' === $id ) {
12811258
continue;
12821259
}
@@ -1286,8 +1263,6 @@ public static function normalize_kit_items( array $items, string $type ): array
12861263
$name = (string) $item['name'];
12871264
} elseif ( isset( $item['label'] ) ) {
12881265
$name = (string) $item['label'];
1289-
} elseif ( 'custom_fields' === $type && isset( $item['key'] ) ) {
1290-
$name = (string) $item['key'];
12911266
}
12921267

12931268
if ( '' === $name ) {
@@ -1327,18 +1302,6 @@ public function get_kit_tags( $search = '' ) {
13271302
return self::get_kit_data( 'tags', $search );
13281303
}
13291304

1330-
/**
1331-
* Get Kit custom fields, optionally filtered by search term.
1332-
*
1333-
* @since 1.0.0
1334-
*
1335-
* @param string $search Optional search term.
1336-
* @return array|\WP_Error Array of custom fields.
1337-
*/
1338-
public function get_kit_custom_fields( $search = '' ) {
1339-
return self::get_kit_data( 'custom_fields', $search );
1340-
}
1341-
13421305
/**
13431306
* Add a "Test Connection" button after the OAuth connection output.
13441307
*

0 commit comments

Comments
 (0)