@@ -667,8 +667,8 @@ public function output_accounts( $connection_id = '', $connection = array() ) {
667667 }
668668
669669 /**
670- * Outputs a <select> dropdown of ConvertKit Forms, allowing the user
671- * to choose which ConvertKit Form to send form submissions to.
670+ * Outputs a <select> dropdown of Kit Forms, Sequences and Tags , allowing the user
671+ * to choose which resource to send form submissions to.
672672 *
673673 * @since 1.5.0
674674 *
@@ -691,28 +691,67 @@ public function output_lists( $connection_id = '', $connection = array() ) {
691691 return '' ;
692692 }
693693
694+ // Get the selected ConvertKit subscribe setting, if one was already defined.
695+ $ value = ! empty ( $ connection ['list_id ' ] ) ? $ connection ['list_id ' ] : '' ;
696+
697+ // Initialize resource classes.
698+ $ forms = new Integrate_ConvertKit_WPForms_Resource_Forms ( $ api , $ connection ['account_id ' ] );
699+ $ sequences = new Integrate_ConvertKit_WPForms_Resource_Sequences ( $ api , $ connection ['account_id ' ] );
700+ $ tags = new Integrate_ConvertKit_WPForms_Resource_Tags ( $ api , $ connection ['account_id ' ] );
701+
694702 // Fetch Forms.
695703 // We use refresh() to ensure we get the latest data, as we're in the admin interface
696704 // and need to populate the select dropdown.
697- $ forms = new Integrate_ConvertKit_WPForms_Resource_Forms ( $ api , $ connection ['account_id ' ] );
698- $ forms ->refresh ();
705+ $ result = $ forms ->refresh ();
706+
707+ // Return the <select> dropdown if an error occurred, so the cached resources are
708+ // available for selection.
709+ if ( is_wp_error ( $ result ) ) {
710+ return $ this ->output_select_dropdown ( $ forms , $ sequences , $ tags , $ value , $ connection_id , $ result ->get_error_message () );
711+ }
699712
700713 // Fetch Sequences.
701714 // We use refresh() to ensure we get the latest data, as we're in the admin interface
702715 // and need to populate the select dropdown.
703- $ sequences = new Integrate_ConvertKit_WPForms_Resource_Sequences ( $ api , $ connection ['account_id ' ] );
704- $ sequences ->refresh ();
716+ $ result = $ sequences ->refresh ();
717+
718+ // Return the <select> dropdown if an error occurred, so the cached resources are
719+ // available for selection.
720+ if ( is_wp_error ( $ result ) ) {
721+ return $ this ->output_select_dropdown ( $ forms , $ sequences , $ tags , $ value , $ connection_id , $ result ->get_error_message () );
722+ }
705723
706724 // Fetch Tags.
707725 // We use refresh() to ensure we get the latest data, as we're in the admin interface
708726 // and need to populate the select dropdown.
709- $ tags = new Integrate_ConvertKit_WPForms_Resource_Tags ( $ api , $ connection ['account_id ' ] );
710- $ tags ->refresh ();
727+ $ result = $ tags ->refresh ();
711728
712- // Get the selected ConvertKit subscribe setting, if one was already defined.
713- $ value = ! empty ( $ connection ['list_id ' ] ) ? $ connection ['list_id ' ] : '' ;
729+ // Return the <select> dropdown if an error occurred, so the cached resources are
730+ // available for selection.
731+ if ( is_wp_error ( $ result ) ) {
732+ return $ this ->output_select_dropdown ( $ forms , $ sequences , $ tags , $ value , $ connection_id , $ result ->get_error_message () );
733+ }
714734
715735 // Output <select> dropdown.
736+ return $ this ->output_select_dropdown ( $ forms , $ sequences , $ tags , $ value , $ connection_id );
737+
738+ }
739+
740+ /**
741+ * Outputs the <select> dropdown.
742+ *
743+ * @since 1.8.9
744+ *
745+ * @param Integrate_ConvertKit_WPForms_Resource_Forms $forms Forms resource.
746+ * @param Integrate_ConvertKit_WPForms_Resource_Sequences $sequences Sequences resource.
747+ * @param Integrate_ConvertKit_WPForms_Resource_Tags $tags Tags resource.
748+ * @param string $value Selected value.
749+ * @param string $connection_id Connection ID.
750+ * @param string $error_message Error message.
751+ * @return string
752+ */
753+ private function output_select_dropdown ( $ forms , $ sequences , $ tags , $ value , $ connection_id , $ error_message = '' ) {
754+
716755 ob_start ();
717756 require INTEGRATE_CONVERTKIT_WPFORMS_PATH . '/views/backend/settings-form-marketing-forms-dropdown.php ' ;
718757 return ob_get_clean ();
@@ -871,6 +910,10 @@ public function maybe_get_and_store_access_token() {
871910 )
872911 );
873912
913+ // Remove any existing persistent notice.
914+ $ admin_notices = Integrate_ConvertKit_WPForms_Admin_Notices::get_instance ();
915+ $ admin_notices ->delete ( 'authorization_failed ' );
916+
874917 // If this request is served in a popup window (i.e. from the form builder),
875918 // serve a view that will close the popup.
876919 if ( array_key_exists ( 'convertkit-modal ' , $ _REQUEST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
@@ -974,6 +1017,11 @@ public function api_fields( $connection_id = '', $account_id = '', $list_id = ''
9741017 $ resource_custom_fields = new Integrate_ConvertKit_WPForms_Resource_Custom_Fields ( $ api , $ account_id );
9751018 $ custom_fields = $ resource_custom_fields ->refresh ();
9761019
1020+ // Just return fields if an error occurred.
1021+ if ( is_wp_error ( $ custom_fields ) ) {
1022+ return $ provider_fields ;
1023+ }
1024+
9771025 // Just return fields if no custom fields exist in ConvertKit.
9781026 if ( ! count ( $ custom_fields ) ) {
9791027 return $ provider_fields ;
0 commit comments