Skip to content

Conversation

@n7studios
Copy link
Contributor

@n7studios n7studios commented Nov 27, 2025

Summary

#964 did not reduce the number of 401 requests made by Plugins. To address this, this PR:

  • checks the result of any refresh() call, forcibly removing credentials from the Plugin's settings if the failure is a 401
  • on initialization of a resource class, such as ConvertKit_Resource_Forms, removes the ConvertKit_Resource_V4 init() call and loads cached resources.

All calls made to refresh() from the Plugin are made by the user:

  • They are on the Kit > Settings screen (either going through OAuth or loading the already authenticated screen to change some settings),
  • They click a refresh button in Quick Edit, Bulk Edit, Post settings or a Block
  • They are walking through a Setup Wizard

Testing

Existing tests pass.
Existing integration tests confirm deletion of tokens when a 401 occurs, but this will need a PR of end to end tests to check that tokens are truly deleted when using the Plugin and a 401 occurs.

Checklist

@n7studios n7studios self-assigned this Nov 27, 2025
@n7studios n7studios added the bug label Nov 27, 2025
@n7studios n7studios changed the base branch from main to tests-non-inline-forms-setup-resources November 27, 2025 11:13
composer.json Outdated
"license": "GPLv3",
"require": {
"convertkit/convertkit-wordpress-libraries": "2.1.1"
"convertkit/convertkit-wordpress-libraries": "dev-return-refresh-result"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be changed to the published version of the Kit WordPress LIbraries when released e.g. 2.1.2

}

// Call parent initialization function.
parent::init();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drops the init() call, so refresh() can only occur if called directly by the Plugin.

parent::init();
// Get last query time and existing resources.
$this->last_queried = get_option( $this->settings_name . '_last_queried' );
$this->resources = get_option( $this->settings_name );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes certain any existing cached resources are available, if the API isn't available.

$id
)
),
404
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provides context to the error i.e. a Kit Form ID was specified that either does not exist in the cached resources, is an ID for a legacy form, or truly doesn't exist (the user entered the wrong ID in the shortcode).

* 1.6.1: Refresh Forms, Landing Pages and Tags data stored in settings,
* to get new Forms Builder Settings.
*/
private function refresh_resources() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most 401 errors have the context of block_edit, so this isn't likely to be a culprit. However, it's unlikely many users are upgrading from 1.6.1 to 3.1.0 at this stage, so it shouldn't hut to remove this upgrade path.

@n7studios n7studios requested review from a team, ciccio-kit and noelherrick and removed request for a team November 27, 2025 15:31
@n7studios n7studios marked this pull request as ready for review November 27, 2025 15:31
@github-actions
Copy link

WordPress Playground

🚀 Your PR has been built and is ready for testing in WordPress Playground!

Click here to test your changes in WordPress Playground

@n7studios n7studios changed the base branch from tests-non-inline-forms-setup-resources to main December 2, 2025 01:32
@github-actions
Copy link

github-actions bot commented Dec 2, 2025

WordPress Playground

🚀 Your PR has been built and is ready for testing in WordPress Playground!

Click here to test your changes in WordPress Playground

@n7studios n7studios requested a review from noelherrick December 2, 2025 07:53
Copy link
Contributor

@noelherrick noelherrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this out, and if this turns out to be a good solution, let's put the credential deletion logic in all the resource classes refresh methods. If we don't want to put it into ConvertKit_Resource_V4 in convertkit-wordpress-libraries because we define the deletion logic in this repo, we could have another class in this repo that all the resources inherit from that adds the deletion check in the refresh method.

@n7studios n7studios merged commit fe82e86 into main Dec 3, 2025
218 of 227 checks passed
@n7studios n7studios deleted the remove-refresh-resources-calls branch December 5, 2025 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants