-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaiwp-copilot.php
More file actions
214 lines (185 loc) · 5.87 KB
/
aiwp-copilot.php
File metadata and controls
214 lines (185 loc) · 5.87 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
* Plugin Name: AIWP Copilot
* Plugin URI: https://antigravity.dev/aiwp-copilot
* Description: AI-powered WordPress content assistant with specialist modes for frontend design, SEO, copywriting, and more. Works seamlessly with Elementor and block editor.
* Version: 2.0.0
* Author: Antigravity
* Author URI: https://antigravity.dev
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: aiwp-copilot
* Domain Path: /languages
* Requires at least: 6.0
* Requires PHP: 7.4
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('AIWP_VERSION', '2.0.0');
define('AIWP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('AIWP_PLUGIN_URL', plugin_dir_url(__FILE__));
define('AIWP_PLUGIN_FILE', __FILE__);
/**
* Main AIWP Copilot Class
*/
class AIWP_Copilot
{
/**
* Single instance
*/
private static $instance = null;
/**
* Get instance
*/
public static function get_instance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct()
{
$this->load_dependencies();
$this->init_hooks();
}
/**
* Load required files
*/
private function load_dependencies()
{
// Core classes
require_once AIWP_PLUGIN_DIR . 'includes/core/class-copilot-indexer.php';
require_once AIWP_PLUGIN_DIR . 'includes/core/class-copilot-filesystem.php';
// Provider system
require_once AIWP_PLUGIN_DIR . 'includes/providers/interface-provider.php';
require_once AIWP_PLUGIN_DIR . 'includes/providers/class-provider-registry.php';
require_once AIWP_PLUGIN_DIR . 'includes/providers/class-openai-provider.php';
require_once AIWP_PLUGIN_DIR . 'includes/providers/class-groq-provider.php';
require_once AIWP_PLUGIN_DIR . 'includes/providers/class-openrouter-provider.php';
require_once AIWP_PLUGIN_DIR . 'includes/providers/class-gemini-provider.php';
// NEW: Specialist system
require_once AIWP_PLUGIN_DIR . 'includes/specialists/class-specialist-registry.php';
require_once AIWP_PLUGIN_DIR . 'includes/specialists/class-specialist-engine.php';
// Error handling
require_once AIWP_PLUGIN_DIR . 'includes/class-error-handler.php';
// REST API
require_once AIWP_PLUGIN_DIR . 'includes/rest-endpoints.php';
// Settings
require_once AIWP_PLUGIN_DIR . 'includes/settings-page.php';
}
/**
* Initialize hooks
*/
private function init_hooks()
{
// Enqueue scripts
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
// Initialize settings page
if (is_admin()) {
new AIWP_Settings_Page();
}
// Initialize REST endpoints
add_action('rest_api_init', array('AIWP_REST_Endpoints', 'register_routes'));
// Initialize provider registry
AIWP_Provider_Registry::init();
// Initialize specialist registry
AIWP_Specialist_Registry::init();
}
/**
* Enqueue admin scripts and styles
*/
public function enqueue_admin_scripts($hook)
{
// Only load on post editor and settings page
$allowed_hooks = array('post.php', 'post-new.php', 'settings_page_aiwp-copilot');
if (!in_array($hook, $allowed_hooks)) {
return;
}
// Main CSS
wp_enqueue_style(
'aiwp-copilot-styles',
AIWP_PLUGIN_URL . 'assets/css/copilot.css',
array(),
AIWP_VERSION
);
// Main JS
wp_enqueue_script(
'aiwp-copilot',
AIWP_PLUGIN_URL . 'assets/js/copilot.js',
array('jquery', 'wp-element', 'wp-components'),
AIWP_VERSION,
true
);
// Elementor scanner (if Elementor is active)
if (defined('ELEMENTOR_VERSION')) {
wp_enqueue_script(
'aiwp-elementor-scanner',
AIWP_PLUGIN_URL . 'assets/js/elementor-scanner.js',
array('jquery'),
AIWP_VERSION,
true
);
}
// Pass data to JS
wp_localize_script('aiwp-copilot', 'aiwpCopilot', array(
'apiUrl' => rest_url('aiwp/v1'),
'nonce' => wp_create_nonce('wp_rest'),
'debugMode' => get_option('aiwp_debug_mode', false),
'specialist' => get_option('aiwp_specialist', 'default'),
'specialistName' => AIWP_Specialist_Registry::get_specialist_name(get_option('aiwp_specialist', 'default'))
));
}
}
/**
* Initialize the plugin
*/
function aiwp_copilot_init()
{
return AIWP_Copilot::get_instance();
}
// Start the plugin
add_action('plugins_loaded', 'aiwp_copilot_init');
/**
* Activation hook
*/
register_activation_hook(__FILE__, function () {
// Initialize provider configuration
$providers = array(
'groq' => array(
'api_key' => '',
'model' => 'llama-3.3-70b-versatile'
),
'openrouter' => array(
'api_key' => '',
'model' => 'google/gemini-flash-1.5'
),
'gemini' => array(
'api_key' => '',
'model' => 'gemini-1.5-flash'
),
'openai' => array(
'api_key' => '',
'model' => 'gpt-4o'
)
);
add_option('aiwp_providers', $providers);
add_option('aiwp_active_provider', 'groq'); // Default to Groq (free)
add_option('aiwp_specialist', 'default');
add_option('aiwp_debug_mode', false);
// Flush rewrite rules
flush_rewrite_rules();
});
/**
* Deactivation hook
*/
register_deactivation_hook(__FILE__, function () {
// Flush rewrite rules
flush_rewrite_rules();
});