PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.4
3.4.4 3.4.3 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 All 197 releases
convertkit / admin / importers / class-convertkit-admin-importer-aweber.php

class-convertkit-admin-importer-aweber.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.4, at admin/importers/class-convertkit-admin-importer-aweber.php

150 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Admin Importer AWeber class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Import and migrate data from AWeber to Kit.
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 */
15 class ConvertKit_Admin_Importer_AWeber extends ConvertKit_Admin_Importer {
16
17 /**
18 * Holds the programmatic name of the importer (lowercase, no spaces).
19 *
20 * @since 3.1.7
21 *
22 * @var string
23 */
24 public $name = 'aweber';
25
26 /**
27 * Holds the title of the importer (for display in the importer list).
28 *
29 * @since 3.1.7
30 *
31 * @var string
32 */
33 public $title = 'AWeber';
34
35 /**
36 * Holds the shortcode name for AWeber forms.
37 *
38 * @since 3.1.5
39 *
40 * @var string
41 */
42 public $shortcode_name = 'aweber';
43
44 /**
45 * Holds the ID attribute name for AWeber forms.
46 *
47 * @since 3.1.5
48 *
49 * @var string
50 */
51 public $shortcode_id_attribute = 'formid';
52
53 /**
54 * Holds the block name for AWeber forms.
55 *
56 * @since 3.1.6
57 *
58 * @var string
59 */
60 public $block_name = 'aweber-signupform-block/aweber-shortcode';
61
62 /**
63 * Holds the ID attribute name for AWeber forms.
64 *
65 * @since 3.1.6
66 *
67 * @var string
68 */
69 public $block_id_attribute = 'selectedShortCode';
70
71 /**
72 * Constructor
73 *
74 * @since 3.1.7
75 */
76 public function __construct() {
77
78 // Register this as an importer, if AWeber forms exist.
79 add_filter( 'convertkit_get_form_importers', array( $this, 'register' ) );
80
81 }
82
83 /**
84 * Returns an array of AWeber form IDs and titles.
85 *
86 * @since 3.1.5
87 *
88 * @return array
89 */
90 public function get_forms() {
91
92 global $aweber_webform_plugin;
93
94 // If the AWeber Plugin is not active, fall back to showing the AWeber Form IDs found in the posts, if any.
95 if ( is_null( $aweber_webform_plugin ) ) {
96 return $this->get_forms_detected_in_posts();
97 }
98
99 // Fetch AWeber account, using OAuth1 or OAuth2.
100 // This is how the AWeber Plugin fetches the account data, as nothing is cached in their Plugin or the database.
101 $response = $aweber_webform_plugin->getAWeberAccount(
102 get_option( $aweber_webform_plugin->adminOptionsName ), // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
103 get_option( $aweber_webform_plugin->oauth2TokensOptions ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
104 );
105
106 // If no account is returned, fall back to showing the AWeber Form IDs found in the posts, if any.
107 if ( ! isset( $response['account'] ) ) {
108 return $this->get_forms_detected_in_posts();
109 }
110
111 // Get account, which contains forms and form split tests.
112 $account = $response['account'];
113 $web_forms = $account->getWebForms();
114 $web_form_split_tests = $account->getWebFormSplitTests();
115
116 // Build array of forms.
117 $forms = array();
118 foreach ( $web_forms as $form ) {
119 $forms[ $form->id ] = sprintf( '%s: %s', __( 'Sign Up Form', 'convertkit' ), $form->name );
120 }
121 foreach ( $web_form_split_tests as $form ) {
122 $forms[ $form->id ] = sprintf( '%s: %s', __( 'Split Tests', 'convertkit' ), $form->name );
123 }
124
125 // Return forms.
126 return $forms;
127
128 }
129
130 /**
131 * Returns an array of AWeber form IDs and titles found in the posts.
132 *
133 * @since 3.1.5
134 *
135 * @return array
136 */
137 private function get_forms_detected_in_posts() {
138
139 $forms = array();
140
141 foreach ( $this->get_form_ids_in_posts() as $form_id ) {
142 $forms[ $form_id ] = sprintf( 'AWeber Form ID #%s', $form_id );
143 }
144
145 return $forms;
146
147 }
148
149 }
150