|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Plugin integration between Freemius and Kit |
| 4 | + * |
| 5 | + * @package WebberZone\FreemKit |
| 6 | + * @author WebberZone |
| 7 | + * @license GPL-2.0+ |
| 8 | + * @link https://webberzone.com |
| 9 | + * |
| 10 | + * @wordpress-plugin |
| 11 | + * Plugin Name: WebberZone FreemKit - Glue for Freemius and Kit |
| 12 | + * Plugin URI: https://webberzone.com/plugins/freemkit/ |
| 13 | + * Description: Easily subscribe Freemius customers to Kit email lists. |
| 14 | + * Version: 1.0.0-beta1 |
| 15 | + * Author: WebberZone |
| 16 | + * Author URI: https://webberzone.com |
| 17 | + * License: GPL-2.0+ |
| 18 | + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 19 | + * Text Domain: freemkit |
| 20 | + * Domain Path: /languages |
| 21 | + */ |
| 22 | + |
| 23 | +namespace WebberZone\FreemKit; |
| 24 | + |
| 25 | +if ( ! defined( 'WPINC' ) ) { |
| 26 | + die; |
| 27 | +} |
| 28 | + |
| 29 | +// Define plugin constants. |
| 30 | +if ( ! defined( 'FREEMKIT_VERSION' ) ) { |
| 31 | + define( 'FREEMKIT_VERSION', '1.0.0' ); |
| 32 | +} |
| 33 | +if ( ! defined( 'FREEMKIT_PLUGIN_FILE' ) ) { |
| 34 | + define( 'FREEMKIT_PLUGIN_FILE', __FILE__ ); |
| 35 | +} |
| 36 | +if ( ! defined( 'FREEMKIT_PLUGIN_DIR' ) ) { |
| 37 | + define( 'FREEMKIT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 38 | +} |
| 39 | + |
| 40 | +if ( ! defined( 'FREEMKIT_PLUGIN_URL' ) ) { |
| 41 | + define( 'FREEMKIT_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 42 | +} |
| 43 | + |
| 44 | +// Kit OAuth defaults (same OAuth application used by the official Kit WordPress flow). |
| 45 | +if ( ! defined( 'FREEMKIT_KIT_OAUTH_CLIENT_ID' ) ) { |
| 46 | + define( 'FREEMKIT_KIT_OAUTH_CLIENT_ID', 'HXZlOCj-K5r0ufuWCtyoyo3f688VmMAYSsKg1eGvw0Y' ); |
| 47 | +} |
| 48 | +if ( ! defined( 'FREEMKIT_KIT_OAUTH_REDIRECT_URI' ) ) { |
| 49 | + define( 'FREEMKIT_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 FREEMKIT_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php'; |
| 55 | +} |
| 56 | +if ( ! class_exists( 'ConvertKit_API_V4' ) ) { |
| 57 | + require_once FREEMKIT_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-v4.php'; |
| 58 | +} |
| 59 | +if ( ! class_exists( 'ConvertKit_Log' ) ) { |
| 60 | + require_once FREEMKIT_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php'; |
| 61 | +} |
| 62 | +if ( ! class_exists( 'ConvertKit_Resource_V4' ) ) { |
| 63 | + require_once FREEMKIT_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource-v4.php'; |
| 64 | +} |
| 65 | +if ( ! class_exists( 'ConvertKit_Review_Request' ) ) { |
| 66 | + require_once FREEMKIT_PLUGIN_DIR . 'vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php'; |
| 67 | +} |
| 68 | + |
| 69 | +// Autoloader. |
| 70 | +require_once FREEMKIT_PLUGIN_DIR . 'includes/autoloader.php'; |
| 71 | + |
| 72 | +// Register activation hook. |
| 73 | +register_activation_hook( __FILE__, array( 'WebberZone\FreemKit\Main', 'activate' ) ); |
| 74 | + |
| 75 | +/** |
| 76 | + * Global variable holding the current instance of FreemKit |
| 77 | + * |
| 78 | + * @since 1.0.0 |
| 79 | + * |
| 80 | + * @var \WebberZone\FreemKit\Main |
| 81 | + */ |
| 82 | +global $freemkit; |
| 83 | + |
| 84 | +if ( ! function_exists( __NAMESPACE__ . '\\load' ) ) { |
| 85 | + /** |
| 86 | + * The main function responsible for returning the one true instance of the plugin to functions everywhere. |
| 87 | + * |
| 88 | + * @since 1.0.0 |
| 89 | + * |
| 90 | + * @return void |
| 91 | + */ |
| 92 | + function load() { |
| 93 | + freemkit(); |
| 94 | + } |
| 95 | + add_action( 'plugins_loaded', __NAMESPACE__ . '\\load' ); |
| 96 | +} |
| 97 | + |
| 98 | +if ( ! function_exists( __NAMESPACE__ . '\\freemkit' ) ) { |
| 99 | + /** |
| 100 | + * Get the main FreemKit instance. |
| 101 | + * |
| 102 | + * @since 1.0.0 |
| 103 | + * @return Main Main instance. |
| 104 | + */ |
| 105 | + function freemkit() { |
| 106 | + global $freemkit; |
| 107 | + delete_option( 'freemkit_boot_error' ); |
| 108 | + |
| 109 | + try { |
| 110 | + $freemkit = Main::get_instance(); |
| 111 | + } catch ( \Throwable $e ) { |
| 112 | + update_option( |
| 113 | + 'freemkit_boot_error', |
| 114 | + sprintf( |
| 115 | + /* translators: 1: Error message, 2: File, 3: Line. */ |
| 116 | + __( 'FreemKit failed to initialize: %1$s in %2$s on line %3$d', 'freemkit' ), |
| 117 | + $e->getMessage(), |
| 118 | + $e->getFile(), |
| 119 | + $e->getLine() |
| 120 | + ) |
| 121 | + ); |
| 122 | + } |
| 123 | + |
| 124 | + return $freemkit; |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +/** |
| 129 | + * Show plugin bootstrap errors in wp-admin. |
| 130 | + * |
| 131 | + * @since 1.0.0 |
| 132 | + * |
| 133 | + * @return void |
| 134 | + */ |
| 135 | +function show_boot_error_notice() { |
| 136 | + if ( ! current_user_can( 'manage_options' ) ) { |
| 137 | + return; |
| 138 | + } |
| 139 | + |
| 140 | + $error = get_option( 'freemkit_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