insights()->init(); } appsero_init_tracker_ai_co_pilot_for_wp(); /** * The code that runs during plugin activation. * This action is documented in includes/class-ai-content-helper-activator.php */ function activate_ai_content_helper() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-ai-content-helper-activator.php'; Ai_Content_Helper_Activator::activate(); } /** * The code that runs during plugin deactivation. * This action is documented in includes/class-ai-content-helper-deactivator.php */ function deactivate_ai_content_helper() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-ai-content-helper-deactivator.php'; Ai_Content_Helper_Deactivator::deactivate(); } register_activation_hook( __FILE__, 'activate_ai_content_helper' ); register_deactivation_hook( __FILE__, 'deactivate_ai_content_helper' ); /** * The core plugin class that is used to define internationalization, * admin-specific hooks, and public-facing site hooks. */ require plugin_dir_path( __FILE__ ) . 'includes/class-ai-content-helper.php'; do_action( 'wp_ai_co_pilot/loaded' ); /** * Begins execution of the plugin. * * Since everything within the plugin is registered via hooks, * then kicking off the plugin from this point in the file does * not affect the page life cycle. * * @since 1.0.0 */ if( ! function_exists( 'validate_api_key' ) ) { function validate_api_key( $value ) { $api_key = $value; $client = new GuzzleHttp\Client(['verify' => false ]); try { $res = $client->request('GET', 'https://api.openai.com/v1/models', [ 'headers' => [ 'Authorization' => 'Bearer ' . $api_key, 'Content-Type' => 'application/json', ], ]); } catch (GuzzleHttp\Exception\ClientException $e) { return esc_html__( 'This open ai api key is not valid!', 'csf' ); } if ( $res->getStatusCode() !== 200 ) { return esc_html__( 'This open ai api key is not valid!', 'csf' ); } $body = json_decode( $res->getBody(), true ); if ( ! isset( $body['data'] ) ) { return esc_html__( 'This open ai api key is not valid!', 'csf' ); } } } function run_ai_content_helper() { $plugin = new Ai_Content_Helper(); $plugin->run(); } add_action( 'plugins_loaded', 'run_ai_content_helper', 2 );