run(); } // Use a higher priority to ensure all dependencies are loaded. add_action('plugins_loaded', 'boomdevs_ai_image_alt_text_generator_run', 2); /** * Initialize the plugin tracker * * @return void */ function appsero_init_tracker_ai_image_alt_text_generator_for_wp() { if (! class_exists('Appsero\Client')) { require_once __DIR__ . '/appsero/src/Client.php'; } $client = new Appsero\Client('c4a40d12-68e8-4f57-984c-bc744c2e45d0', 'Ai Image Alt Text Generator for WP', __FILE__); // Active insights $client->insights()->init(); } add_action('init', 'appsero_init_tracker_ai_image_alt_text_generator_for_wp'); /** * 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) { if (!current_user_can('manage_options')) { return esc_html__('Permission denied!', 'ai-image-alt-text-generator-for-wp'); } $api_key = $value; $url = 'https://aialttextgenerator.com/wp-json/alt-text-generator/v1/available-token'; $body_data = array( 'token' => $api_key, ); $args = array( 'headers' => array( 'Content-Type' => 'application/json', ), 'body' => wp_json_encode($body_data), ); $response = wp_remote_post($url, $args); $response_body = wp_remote_retrieve_body($response); $decoded_response = json_decode($response_body); if (!$decoded_response->data->available_token) { return esc_html__('This api key is not valid!', 'ai-image-alt-text-generator-for-wp'); } } }