Skip to content

Commit fc91d1c

Browse files
committed
feat: Integrate Kit OAuth v4 API and refactor admin architecture
- Add Kit OAuth v4 authentication with shared ConvertKit libraries - Replace API key/secret with OAuth flow using official Kit WordPress client - Refactor Core class to Main with enhanced error handling and boot error notices - Implement Admin_Notices_API and Admin_Banner for improved admin UI - Add connection testing for Kit API credentials via AJAX - Introduce Freemius event type configuration for free/paid user mappings
1 parent 49d8cae commit fc91d1c

47 files changed

Lines changed: 5130 additions & 1222 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

glue-link.php

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,43 @@
4141
define( 'GLUE_LINK_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
4242
}
4343

44+
// Kit OAuth defaults (same OAuth application used by the official Kit WordPress flow).
45+
if ( ! defined( 'GLUE_LINK_KIT_OAUTH_CLIENT_ID' ) ) {
46+
define( 'GLUE_LINK_KIT_OAUTH_CLIENT_ID', 'HXZlOCj-K5r0ufuWCtyoyo3f688VmMAYSsKg1eGvw0Y' );
47+
}
48+
if ( ! defined( 'GLUE_LINK_KIT_OAUTH_REDIRECT_URI' ) ) {
49+
define( 'GLUE_LINK_KIT_OAUTH_REDIRECT_URI', 'https://app.kit.com/wordpress/redirect' );
50+
}
51+
52+
// Load Kit shared library classes if not already loaded by another plugin.
53+
if ( ! trait_exists( 'ConvertKit_API_Traits' ) ) {
54+
require_once GLUE_LINK_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php';
55+
}
56+
if ( ! class_exists( 'ConvertKit_API_V4' ) ) {
57+
require_once GLUE_LINK_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-v4.php';
58+
}
59+
if ( ! class_exists( 'ConvertKit_Log' ) ) {
60+
require_once GLUE_LINK_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php';
61+
}
62+
if ( ! class_exists( 'ConvertKit_Resource_V4' ) ) {
63+
require_once GLUE_LINK_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource-v4.php';
64+
}
65+
if ( ! class_exists( 'ConvertKit_Review_Request' ) ) {
66+
require_once GLUE_LINK_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php';
67+
}
68+
4469
// Autoloader.
4570
require_once GLUE_LINK_PLUGIN_DIR . 'includes/autoloader.php';
4671

4772
// Register activation hook.
48-
register_activation_hook( __FILE__, array( 'WebberZone\Glue_Link\Core', 'activate' ) );
73+
register_activation_hook( __FILE__, array( 'WebberZone\Glue_Link\Main', 'activate' ) );
4974

5075
/**
5176
* Global variable holding the current instance of Glue Link
5277
*
5378
* @since 1.0.0
5479
*
55-
* @var \WebberZone\Glue_Link\Core
80+
* @var \WebberZone\Glue_Link\Main
5681
*/
5782
global $glue_link;
5883

@@ -65,18 +90,61 @@
6590
* @return void
6691
*/
6792
function load() {
93+
glue_link();
94+
}
95+
add_action( 'plugins_loaded', __NAMESPACE__ . '\\load' );
96+
}
97+
98+
if ( ! function_exists( __NAMESPACE__ . '\\glue_link' ) ) {
99+
/**
100+
* Get the main Glue Link instance.
101+
*
102+
* @since 1.0.0
103+
* @return Main Main instance.
104+
*/
105+
function glue_link() {
68106
global $glue_link;
69-
$glue_link = Core::get_instance();
107+
delete_option( 'glue_link_boot_error' );
108+
109+
try {
110+
$glue_link = Main::get_instance();
111+
} catch ( \Throwable $e ) {
112+
update_option(
113+
'glue_link_boot_error',
114+
sprintf(
115+
/* translators: 1: Error message, 2: File, 3: Line. */
116+
__( 'Glue Link failed to initialize: %1$s in %2$s on line %3$d', 'glue-link' ),
117+
$e->getMessage(),
118+
$e->getFile(),
119+
$e->getLine()
120+
)
121+
);
122+
}
123+
124+
return $glue_link;
70125
}
71126
}
72-
add_action( 'plugins_loaded', __NAMESPACE__ . '\\load' );
73127

74128
/**
75-
* Global variable holding the current settings for Glue Link
129+
* Show plugin bootstrap errors in wp-admin.
76130
*
77131
* @since 1.0.0
78132
*
79-
* @var array<string, mixed>
133+
* @return void
80134
*/
81-
global $glue_link_settings;
82-
$glue_link_settings = Options_API::get_settings();
135+
function show_boot_error_notice() {
136+
if ( ! current_user_can( 'manage_options' ) ) {
137+
return;
138+
}
139+
140+
$error = get_option( 'glue_link_boot_error' );
141+
if ( empty( $error ) ) {
142+
return;
143+
}
144+
145+
printf(
146+
'<div class="notice notice-error"><p>%s</p></div>',
147+
esc_html( (string) $error )
148+
);
149+
}
150+
add_action( 'admin_notices', __NAMESPACE__ . '\\show_boot_error_notice' );

0 commit comments

Comments
 (0)