@@ -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