-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.php
100 lines (82 loc) · 2.84 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Plugin Name: Chat with GPT
* Description: The Ultimate Plugin for Engaging Chat and Conversations with AI
* Plugin URI: https://qbein.net/chat-with-gpt
* Requires at least: 5.0
* Requires PHP: 7.4
* Author: Qbein
* Author URI: https://qbein.net/
* Version: 1.0.2
* License: GPLv2 or later
* Text Domain: chat-with-gpt
* Domain Path: /languages
*
* Network: false
*/
defined( 'ABSPATH' ) || exit;
define( 'QCG_REQUIRED_PHP_VERSION', '7.3' );
define( 'QCG_REQUIRED_WP_VERSION', '5.0' );
/**
* Checks if the system requirements are met
*
* @return array Array of errors or false if all is ok
*/
function qcg_requirements_met(): array {
global $wp_version;
$errors = [];
if ( version_compare( PHP_VERSION, QCG_REQUIRED_PHP_VERSION, '<' ) ) {
$errors[] = printf(
esc_html__( 'Your server is running PHP version %1$s but this plugin requires at least PHP %2$s. Please run an upgrade.', 'chat-with-gpt' ),
PHP_VERSION,
QCG_REQUIRED_PHP_VERSION
);
}
if ( version_compare( $wp_version, QCG_REQUIRED_WP_VERSION, '<' ) ) {
$errors[] = printf(
esc_html__( 'Your Wordpress running version is %1$s but this plugin requires at least version %2$s. Please run an upgrade.', 'chat-with-gpt' ),
esc_html( $wp_version ),
QCG_REQUIRED_WP_VERSION
);
}
$extensions = get_loaded_extensions();
if ( ! in_array( 'curl', $extensions ) ) {
$errors[] = esc_html__( 'Your need to install curl php extension to continue plugin use. Please install it first.', 'chat-with-gpt' );
}
if ( ! in_array( 'json', $extensions ) ) {
$errors[] = esc_html__( 'Your need to install json php extension to continue plugin use. Please install it first.', 'chat-with-gpt' );
}
return $errors;
}
/**
* Begins execution of the plugin.
*
* Plugin run entry point
*/
function qcg_run() {
$plugin = new QCG_Common();
$plugin->run();
}
/**
* Check requirements and load main class
* The main program needs to be in a separate file that only gets loaded if the plugin requirements are met.
* Otherwise, older PHP installations could crash when trying to parse it.
*/
require_once( __DIR__ . '/controller/class-qcg-common.php' );
$errors = qcg_requirements_met();
if ( ! $errors ) {
if ( method_exists( QCG_Common::class, 'activate' ) ) {
register_activation_hook( __FILE__, 'QCG_Common::activate' );
}
qcg_run();
} else {
add_action( 'admin_notices', function () use ( $errors ) {
require_once( dirname( __FILE__ ) . '/views/requirements-error.php' );
} );
}
if ( method_exists( QCG_Common::class, 'deactivate' ) ) {
register_deactivation_hook( __FILE__, array( QCG_Common::class, 'deactivate' ) );
}
if ( method_exists( QCG_Common::class, 'uninstall' ) ) {
register_uninstall_hook( __FILE__, array( QCG_Common::class, 'uninstall' ) );
}