|
41 | 41 | define( 'GLUE_LINK_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
42 | 42 | } |
43 | 43 |
|
| 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 | + |
44 | 69 | // Autoloader. |
45 | 70 | require_once GLUE_LINK_PLUGIN_DIR . 'includes/autoloader.php'; |
46 | 71 |
|
47 | 72 | // 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' ) ); |
49 | 74 |
|
50 | 75 | /** |
51 | 76 | * Global variable holding the current instance of Glue Link |
52 | 77 | * |
53 | 78 | * @since 1.0.0 |
54 | 79 | * |
55 | | - * @var \WebberZone\Glue_Link\Core |
| 80 | + * @var \WebberZone\Glue_Link\Main |
56 | 81 | */ |
57 | 82 | global $glue_link; |
58 | 83 |
|
|
65 | 90 | * @return void |
66 | 91 | */ |
67 | 92 | 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() { |
68 | 106 | 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; |
70 | 125 | } |
71 | 126 | } |
72 | | -add_action( 'plugins_loaded', __NAMESPACE__ . '\\load' ); |
73 | 127 |
|
74 | 128 | /** |
75 | | - * Global variable holding the current settings for Glue Link |
| 129 | + * Show plugin bootstrap errors in wp-admin. |
76 | 130 | * |
77 | 131 | * @since 1.0.0 |
78 | 132 | * |
79 | | - * @var array<string, mixed> |
| 133 | + * @return void |
80 | 134 | */ |
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