-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-integrate-convertkit-wpforms-resource.php
More file actions
74 lines (61 loc) · 1.92 KB
/
class-integrate-convertkit-wpforms-resource.php
File metadata and controls
74 lines (61 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* ConvertKit Resource class.
*
* @package ConvertKit_WPForms
* @author ConvertKit
*/
/**
* Abstract class defining variables and functions for a ConvertKit API Resource
* (forms, sequences, tags).
*
* @since 1.7.0
*/
class Integrate_ConvertKit_WPForms_Resource extends ConvertKit_Resource_V4 {
/**
* The API class
*
* @var bool|Integrate_ConvertKit_WPForms_API
*/
public $api = false;
/**
* Constructor.
*
* @since 1.7.0
*
* @param Integrate_ConvertKit_WPForms_API $api_instance API Instance.
* @param string $account_id WPForms Account ID.
*/
public function __construct( $api_instance, $account_id = '' ) {
// Initialize the API using the supplied Integrate_ConvertKit_WPForms_API instance.
$this->api = $api_instance;
// Append the account ID to the settings key, so that multiple connections can each
// have their own cached resources specific to that account.
if ( $account_id ) {
$this->settings_name .= '_' . $account_id;
}
// Get last query time and existing resources.
$this->last_queried = get_option( $this->settings_name . '_last_queried' );
$this->resources = get_option( $this->settings_name );
}
/**
* Fetches resources (custom fields, forms, sequences or tags) from the API, storing them in the options table
* with a last queried timestamp.
*
* If the refresh results in a 401, removes the access and refresh tokens from the connection.
*
* @since 1.8.9
*
* @return WP_Error|array
*/
public function refresh() {
// Call parent refresh method.
$result = parent::refresh();
// If an error occured, maybe delete credentials from the Plugin's settings
// if the error is a 401 unauthorized.
if ( is_wp_error( $result ) ) {
integrate_convertkit_wpforms_maybe_delete_credentials( $result, INTEGRATE_CONVERTKIT_WPFORMS_OAUTH_CLIENT_ID, $this->api->access_token() );
}
return $result;
}
}