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 816b75e22..b0043eea9 100644 --- a/tests/Support/Helper/KitPlugin.php +++ b/tests/Support/Helper/KitPlugin.php @@ -511,12 +511,62 @@ public function setupKitPluginResources($I) ] ); + // Define Custom Fields. + $I->haveOptionInDatabase( + 'convertkit_custom_fields', + [ + 1075083 => [ + 'id' => 1075083, + 'name' => 'ck_field_1075083_url', + 'key' => 'url', + 'label' => 'URL', + ], + 276295 => [ + 'id' => 276295, + 'name' => 'ck_field_276295_payment_method', + 'key' => 'payment_method', + 'label' => 'Payment Method', + ], + 276273 => [ + 'id' => 276273, + 'name' => 'ck_field_276273_billing_address', + 'key' => 'billing_address', + 'label' => 'Billing Address', + ], + 276272 => [ + 'id' => 276272, + 'name' => 'ck_field_276272_shipping_address', + 'key' => 'shipping_address', + 'label' => 'Shipping Address', + ], + 276271 => [ + 'id' => 276271, + 'name' => 'ck_field_276271_phone_number', + 'key' => 'phone_number', + 'label' => 'Phone Number', + ], + 264073 => [ + 'id' => 264073, + 'name' => 'ck_field_264073_last_name', + 'key' => '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 +610,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 +653,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');