PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.8.6
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.8.6
3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 All 195 releases
← All changes | includes/cron-functions.php +51 -0 2.2.62.8.6 View file →
@@ -6,8 +6,59 @@
6 6 * @author ConvertKit
7 7 */
8 8
9 9 /**
10 + * Refresh the OAuth access token, triggered by WordPress' Cron.
11 + *
12 + * @since 2.8.3
13 + */
14 +function convertkit_refresh_token() {
15 +
16 + // Get Settings and Log classes.
17 + $settings = new ConvertKit_Settings();
18 +
19 + // Bail if no existing access and refresh token exists.
20 + if ( ! $settings->has_access_token() ) {
21 + return;
22 + }
23 + if ( ! $settings->has_refresh_token() ) {
24 + return;
25 + }
26 +
27 + // Initialize the API.
28 + $api = new ConvertKit_API_V4(
29 + CONVERTKIT_OAUTH_CLIENT_ID,
30 + CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI,
31 + $settings->get_access_token(),
32 + $settings->get_refresh_token(),
33 + $settings->debug_enabled(),
34 + 'cron_refresh_token'
35 + );
36 +
37 + // Refresh the token.
38 + $result = $api->refresh_token();
39 +
40 + // If an error occured, don't save the new tokens.
41 + // Logging is handled by the ConvertKit_API_V4 class.
42 + if ( is_wp_error( $result ) ) {
43 + return;
44 + }
45 +
46 + $settings->save(
47 + array(
48 + 'access_token' => $result['access_token'],
49 + 'refresh_token' => $result['refresh_token'],
50 + 'token_expires' => ( time() + $result['expires_in'] ),
51 + )
52 + );
53 +
54 +}
55 +
56 +// Register action to run above function; this action is created by WordPress' wp_schedule_event() function
57 +// in update_credentials() in the ConvertKit_Settings class.
58 +add_action( 'convertkit_refresh_token', 'convertkit_refresh_token' );
59 +
60 +/**
10 61 * Refresh the Posts Resource cache, triggered by WordPress' Cron.
11 62 *
12 63 * @since 1.9.7.4
13 64 */