-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmind.php
More file actions
168 lines (146 loc) · 3.66 KB
/
Copy pathmind.php
File metadata and controls
168 lines (146 loc) · 3.66 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* Plugin Name: AI Mind
* Description: AI Page Builder via WordPress Connectors. Build, design, improve, and rewrite your page sections and blocks.
* Requires at least: 7.0
* Requires PHP: 7.4
* Version: 1.0.0
* Plugin URI: https://www.wp-mind.com/
* Author: Mind Team
* Author URI: https://www.wp-mind.com/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: mind
*
* @package mind
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'MIND_VERSION' ) ) {
define( 'MIND_VERSION', '1.0.0' );
}
if ( ! defined( 'MIND_SETTINGS_OPTION' ) ) {
define( 'MIND_SETTINGS_OPTION', 'mind_settings' );
}
/**
* Mind Class
*/
class Mind {
/**
* Settings keys still persisted by the plugin UI.
*
* @var string[]
*/
private const SUPPORTED_SETTINGS_KEYS = array( 'ai_provider', 'ai_model' );
/**
* The single class instance.
*
* @var $instance
*/
private static $instance = null;
/**
* Main Instance
* Ensures only one instance of this class exists in memory at any one time.
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->init();
}
return self::$instance;
}
/**
* Path to the plugin directory
*
* @var $plugin_path
*/
public $plugin_path;
/**
* URL to the plugin directory
*
* @var $plugin_url
*/
public $plugin_url;
/**
* Mind constructor.
*/
public function __construct() {
/* We do nothing here! */
}
/**
* Init options
*/
public function init() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
// include helper files.
$this->include_dependencies();
// hooks.
add_action( 'init', [ $this, 'init_hook' ] );
}
/**
* Include dependencies
*/
private function include_dependencies() {
require_once $this->plugin_path . 'classes/class-prompts.php';
require_once $this->plugin_path . 'classes/class-ai-settings.php';
require_once $this->plugin_path . 'classes/class-ai-stream.php';
require_once $this->plugin_path . 'classes/class-ai-request.php';
require_once $this->plugin_path . 'classes/class-admin.php';
require_once $this->plugin_path . 'classes/class-assets.php';
require_once $this->plugin_path . 'classes/class-rest.php';
}
/**
* Init Hook
*/
public function init_hook() {
// load textdomain.
load_plugin_textdomain( 'mind', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Activation Hook
*/
public function activation_hook() {
// Full settings reset — intentional breaking change on upgrade.
update_option(
MIND_SETTINGS_OPTION,
array(
'ai_provider' => '',
'ai_model' => '',
)
);
delete_option( 'mind_db_version' );
set_transient( '_mind_welcome_screen_activation_redirect', true, 30 );
}
/**
* Get settings that are still part of the public plugin contract.
*
* @param mixed $settings Raw settings option value.
*
* @return array
*/
public static function get_supported_settings( $settings ) {
if ( ! is_array( $settings ) ) {
return array();
}
return array_intersect_key( $settings, array_flip( self::SUPPORTED_SETTINGS_KEYS ) );
}
/**
* Deactivation Hook
*/
public function deactivation_hook() {
// Nothing here yet.
}
}
/**
* Function works with the Mind class instance
*
* @return object Mind
*/
function mind() {
return Mind::instance();
}
add_action( 'plugins_loaded', 'mind' );
register_activation_hook( __FILE__, [ mind(), 'activation_hook' ] );
register_deactivation_hook( __FILE__, [ mind(), 'deactivation_hook' ] );