From ced492d6749b4569335d76f10aa51e6258e3faa9 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 6 Aug 2026 14:45:59 +0800 Subject: [PATCH 1/2] Tests: Resources: Cache Custom Fields --- tests/Support/Helper/KitPlugin.php | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/Support/Helper/KitPlugin.php b/tests/Support/Helper/KitPlugin.php index 816b75e22..7c6e26cad 100644 --- a/tests/Support/Helper/KitPlugin.php +++ b/tests/Support/Helper/KitPlugin.php @@ -511,12 +511,63 @@ public function setupKitPluginResources($I) ] ); + // Define Custom Fields. + // Define Custom Fields. + $I->haveOptionInDatabase( + 'convertkit_custom_fields', + [ + 1075083 => [ + 'id' => 1075083, + 'name' => 'ck_field_1075083_url', + 'key' => 'url', + 'label' => 'URL', + ], + 276295 => [ + 'id' => 276295, + 'name' => 'Payment Method', + 'key' => 'ck_field_276295_payment_method', + 'label' => 'Payment Method', + ], + 276273 => [ + 'id' => 276273, + 'name' => 'Billing Address', + 'key' => 'ck_field_276273_billing_address', + 'label' => 'Billing Address', + ], + 276272 => [ + 'id' => 276272, + 'name' => 'Shipping Address', + 'key' => 'ck_field_276272_shipping_address', + 'label' => 'Shipping Address', + ], + 276271 => [ + 'id' => 276271, + 'name' => 'Phone Number', + 'key' => 'ck_field_276271_phone_number', + 'label' => 'Phone Number', + ], + 264073 => [ + 'id' => 264073, + 'name' => 'Last Name', + 'key' => 'ck_field_264073_last_name', + 'label' => 'Last Name', + ], + 258240 => [ + 'id' => 258240, + 'name' => 'ck_field_258240_notes', + 'key' => 'notes', + 'label' => 'Notes', + ], + ] + ); + // Define last queried to now for all resources, so they're not automatically immediately refreshed by the Plugin's logic. $I->haveOptionInDatabase( 'convertkit_forms_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_landing_pages_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_posts_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_products_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_tags_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_custom_fields_last_queried', strtotime( 'now' ) ); } /** @@ -560,12 +611,19 @@ public function setupKitPluginResourcesNoData($I) [] ); + // Define Custom Fields. + $I->haveOptionInDatabase( + 'convertkit_custom_fields', + [] + ); + // Define last queried to now for all resources, so they're not automatically immediately refreshed by the Plugin's logic. $I->haveOptionInDatabase( 'convertkit_forms_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_landing_pages_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_posts_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_products_last_queried', strtotime( 'now' ) ); $I->haveOptionInDatabase( 'convertkit_tags_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_custom_fields_last_queried', strtotime( 'now' ) ); } /** @@ -596,6 +654,8 @@ public function resetKitPlugin($I) $I->dontHaveOptionInDatabase('convertkit_products_last_queried'); $I->dontHaveOptionInDatabase('convertkit_tags'); $I->dontHaveOptionInDatabase('convertkit_tags_last_queried'); + $I->dontHaveOptionInDatabase('convertkit_custom_fields'); + $I->dontHaveOptionInDatabase('convertkit_custom_fields_last_queried'); // Persistent notices. $I->dontHaveOptionInDatabase('convertkit-admin-notices'); From 1e640e3d5b9b647fb1823606b2e36605d034f2b6 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 6 Aug 2026 17:17:15 +0800 Subject: [PATCH 2/2] Fix cache for custom fields --- ...class-convertkit-admin-section-general.php | 17 ++++++++++++++- tests/Support/Helper/KitPlugin.php | 21 +++++++++---------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/admin/section/class-convertkit-admin-section-general.php b/admin/section/class-convertkit-admin-section-general.php index 95d4af4da..e17dee1b1 100644 --- a/admin/section/class-convertkit-admin-section-general.php +++ b/admin/section/class-convertkit-admin-section-general.php @@ -695,8 +695,19 @@ public function maybe_initialize_and_refresh_resources() { return; } - // Also refresh Landing Pages, Tags and Posts. Whilst not displayed in the Plugin Settings, this ensures up to date + // Also refresh other resources. Whilst not displayed in the Plugin Settings, this ensures up to date // lists are stored for when editing e.g. Pages. + + // Refresh Custom Fields. + $custom_fields = new ConvertKit_Resource_Custom_Fields( 'settings' ); + $result = $custom_fields->refresh(); + + // Bail if an error occured. + if ( is_wp_error( $result ) ) { + return; + } + + // Refresh Landing Pages. $landing_pages = new ConvertKit_Resource_Landing_Pages( 'settings' ); $result = $landing_pages->refresh(); @@ -705,6 +716,7 @@ public function maybe_initialize_and_refresh_resources() { return; } + // Refresh Posts. remove_all_actions( 'convertkit_resource_refreshed_posts' ); $posts = new ConvertKit_Resource_Posts( 'settings' ); $result = $posts->refresh(); @@ -714,6 +726,7 @@ public function maybe_initialize_and_refresh_resources() { return; } + // Refresh Products. $products = new ConvertKit_Resource_Products( 'settings' ); $result = $products->refresh(); @@ -722,6 +735,7 @@ public function maybe_initialize_and_refresh_resources() { return; } + // Refresh Sequences. $sequences = new ConvertKit_Resource_Sequences( 'settings' ); $result = $sequences->refresh(); @@ -730,6 +744,7 @@ public function maybe_initialize_and_refresh_resources() { return; } + // Refresh Tags. $tags = new ConvertKit_Resource_Tags( 'settings' ); $result = $tags->refresh(); diff --git a/tests/Support/Helper/KitPlugin.php b/tests/Support/Helper/KitPlugin.php index 7c6e26cad..b0043eea9 100644 --- a/tests/Support/Helper/KitPlugin.php +++ b/tests/Support/Helper/KitPlugin.php @@ -511,7 +511,6 @@ public function setupKitPluginResources($I) ] ); - // Define Custom Fields. // Define Custom Fields. $I->haveOptionInDatabase( 'convertkit_custom_fields', @@ -524,32 +523,32 @@ public function setupKitPluginResources($I) ], 276295 => [ 'id' => 276295, - 'name' => 'Payment Method', - 'key' => 'ck_field_276295_payment_method', + 'name' => 'ck_field_276295_payment_method', + 'key' => 'payment_method', 'label' => 'Payment Method', ], 276273 => [ 'id' => 276273, - 'name' => 'Billing Address', - 'key' => 'ck_field_276273_billing_address', + 'name' => 'ck_field_276273_billing_address', + 'key' => 'billing_address', 'label' => 'Billing Address', ], 276272 => [ 'id' => 276272, - 'name' => 'Shipping Address', - 'key' => 'ck_field_276272_shipping_address', + 'name' => 'ck_field_276272_shipping_address', + 'key' => 'shipping_address', 'label' => 'Shipping Address', ], 276271 => [ 'id' => 276271, - 'name' => 'Phone Number', - 'key' => 'ck_field_276271_phone_number', + 'name' => 'ck_field_276271_phone_number', + 'key' => 'phone_number', 'label' => 'Phone Number', ], 264073 => [ 'id' => 264073, - 'name' => 'Last Name', - 'key' => 'ck_field_264073_last_name', + 'name' => 'ck_field_264073_last_name', + 'key' => 'last_name', 'label' => 'Last Name', ], 258240 => [