| 1 |
<?php |
| 2 |
/** |
| 3 |
* AI Initialization. |
| 4 |
* |
| 5 |
* @package cartflows |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
/** |
| 13 |
* AI Initialization. |
| 14 |
* |
| 15 |
* @since x.x.x |
| 16 |
*/ |
| 17 |
class Cartflows_Ai_Init { |
| 18 |
|
| 19 |
/** |
| 20 |
* Member Variable |
| 21 |
* |
| 22 |
* @var object instance |
| 23 |
*/ |
| 24 |
private static $instance; |
| 25 |
|
| 26 |
/** |
| 27 |
* Initiator |
| 28 |
*/ |
| 29 |
public static function get_instance() { |
| 30 |
|
| 31 |
if ( ! isset( self::$instance ) ) { |
| 32 |
self::$instance = new self(); |
| 33 |
} |
| 34 |
|
| 35 |
return self::$instance; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructor |
| 40 |
* |
| 41 |
* @since x.x.x |
| 42 |
*/ |
| 43 |
public function __construct() { |
| 44 |
if ( apply_filters( 'cartflows_ai_auth_enabled', true ) ) { |
| 45 |
include_once CARTFLOWS_DIR . 'modules/content-generation/class-cartflows-ai-utils.php'; |
| 46 |
include_once CARTFLOWS_DIR . 'modules/content-generation/class-cartflows-ai-auth.php'; |
| 47 |
include_once CARTFLOWS_DIR . 'modules/content-generation/class-cartflows-ai-api.php'; |
| 48 |
|
| 49 |
add_action( 'admin_notices', array( $this, 'render_auth_connected_notice' ) ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Render a one-shot success banner right after the account is connected. |
| 55 |
* |
| 56 |
* @since x.x.x |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
public function render_auth_connected_notice() { |
| 60 |
if ( ! get_transient( 'cartflows_auth_connected_notice' ) ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
delete_transient( 'cartflows_auth_connected_notice' ); |
| 65 |
|
| 66 |
printf( |
| 67 |
'<div class="notice notice-success is-dismissible"><p>%s</p></div>', |
| 68 |
esc_html__( 'Your CartFlows account is now connected. Auto Suggest and related Pro features are ready to use.', 'cartflows' ) |
| 69 |
); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Kicking this off by calling 'get_instance()' method |
| 75 |
*/ |
| 76 |
Cartflows_Ai_Init::get_instance(); |
| 77 |
|