Repository navigation
Expand file tree
/
Copy pathmain.php
More file actions
358 lines (337 loc) · 13.6 KB
/
Copy pathmain.php
File metadata and controls
358 lines (337 loc) · 13.6 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
/**
* Plugin Name: MemberCore CLI
* Plugin URI: https://membercore.com/
* Description: Extended WP-CLI commands for MemberCore management including membership assignment, user management, and more.
* Author: MemberCore
* Author URI: https://membercore.com/
* Text Domain: membercore-cli
* Domain Path: /languages
* Version: 1.0.0
*
* @package membercore/cli
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Make this file safe to load more than once. The mu-plugin loader
// (mu-plugins/membercore-cli-ui.php) require()s this file when the plugin is
// inactive; if WordPress later loads the active plugin too, this guard prevents
// a fatal "constant already defined" and double command registration.
if (defined('MEMBERCORE_CLI_VERSION')) {
return;
}
// Define plugin constants
define('MEMBERCORE_CLI_VERSION', '1.0.0');
define('MEMBERCORE_CLI_PLUGIN_FILE', __FILE__);
define('MEMBERCORE_CLI_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('MEMBERCORE_CLI_PLUGIN_URL', plugin_dir_url(__FILE__));
// Only run if WP-CLI is available.
if (!defined('WP_CLI') || !WP_CLI) {
return;
}
// Autoload dependencies (CLI only — avoids loading tightenco/collect on web requests).
if (file_exists(MEMBERCORE_CLI_PLUGIN_DIR . '/vendor/autoload.php')) {
require MEMBERCORE_CLI_PLUGIN_DIR . '/vendor/autoload.php';
} else {
// Fallback: require files manually if no autoloader
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/helpers/UserHelper.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/helpers/MembershipHelper.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Base.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Membership.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/User.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Transaction.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Coaching.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Courses.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Directory.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Snippet.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/StripeSetup.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/MeprStripeSetup.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Group.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Stripe.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/PayPal.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Connect.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Circles.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/CoreLaunch.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Reset.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/License.php';
require_once MEMBERCORE_CLI_PLUGIN_DIR . '/app/commands/Ui.php';
}
/**
* Initialize MemberCore CLI commands
*/
add_action('plugins_loaded', function() {
// Command configuration
$commands = [
[
'slug' => 'meco',
'class' => 'Base',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoTransaction',
'description' => 'Base MemberCore commands for system management',
],
[
'slug' => 'meco membership',
'class' => 'Membership',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoTransaction',
'description' => 'Membership assignment and management commands',
],
[
'slug' => 'meco user',
'class' => 'User',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoTransaction',
'description' => 'User management commands with membership integration',
],
[
'slug' => 'meco transaction',
'class' => 'Transaction',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoTransaction',
'description' => 'Transaction management commands',
],
[
'slug' => 'mpcs',
'class' => 'Courses',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'membercore\\courses\\models\\Course',
'description' => 'MemberCore Courses management commands',
],
[
'slug' => 'mcch',
'class' => 'Coaching',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'membercore\\coachkit\\models\\Program',
'description' => 'MemberCore Coaching management commands',
],
[
'slug' => 'meco directory',
'class' => 'Directory',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'membercore\\directory\\models\\Directory',
'description' => 'Directory enrollment management commands',
],
[
'slug' => 'meco jobs',
'class' => 'Directory',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'membercore\\directory\\models\\Directory',
'description' => 'Directory job management commands',
],
// Backwards compatibility for old mcdir commands
[
'slug' => 'mcdir directory',
'class' => 'Directory',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'membercore\\directory\\models\\Directory',
'description' => 'Directory enrollment management commands (legacy)',
],
[
'slug' => 'mcdir jobs',
'class' => 'Directory',
'namespace' => 'membercore\\cli\\commands',
'dependency' => null,
'description' => 'Directory job management commands (legacy)',
],
[
'slug' => 'mcdir snippet',
'class' => 'Snippet',
'namespace' => 'membercore\\cli\\commands',
'dependency' => null,
'description' => 'Code Snippets management commands (requires Code Snippets plugin)',
],
[
'slug' => 'meco stripe-setup',
'class' => 'StripeSetup',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoTransaction',
'description' => 'Configure Stripe settings from wp-config.php constants',
],
[
'slug' => 'mepr stripe-setup',
'class' => 'MeprStripeSetup',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MeprStripeGateway',
'description' => 'Configure MemberPress Stripe settings from wp-config.php constants',
],
[
'slug' => 'mepr group',
'class' => 'Group',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MeprGroup',
'description' => 'Create a MemberPress group and attach memberships to it',
],
[
'slug' => 'meco stripe',
'class' => 'Stripe',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoStripeGateway',
'description' => 'Stripe CLI helpers: forward webhooks locally, print the webhook URL, resend events',
],
[
'slug' => 'mepr stripe',
'class' => 'Stripe',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MeprStripeGateway',
'description' => 'Stripe CLI helpers: forward webhooks locally, print the webhook URL, resend events',
],
[
'slug' => 'meco paypal',
'class' => 'PayPal',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoPayPalStandardGateway',
'description' => 'PayPal IPN helpers: replay an IPN to this site\'s notify URL',
],
[
'slug' => 'mepr paypal',
'class' => 'PayPal',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MeprPayPalStandardGateway',
'description' => 'PayPal IPN helpers: replay an IPN to this site\'s notify URL',
],
[
'slug' => 'mccon',
'class' => 'Connect',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'membercore\\connect\\Models\\Room',
'description' => 'MemberCore Connect messaging system commands',
],
[
'slug' => 'mccirc',
'class' => 'Circles',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'membercore\\circles\\models\\Circle',
'description' => 'MemberCore Circles management commands',
],
[
'slug' => 'meco corelaunch',
'class' => 'CoreLaunch',
'namespace' => 'membercore\\cli\\commands',
'dependency' => 'MecoCoreLaunchRollout',
'description' => 'Toggle the CoreLaunch unified pipeline on/off',
],
[
'slug' => 'meco reset',
'class' => 'Reset',
'namespace' => 'membercore\\cli\\commands',
'dependency' => null,
'description' => 'Reset and re-seed the local site (db reset, reinstall, plugins, products, users)',
],
[
'slug' => 'meco license',
'class' => 'License',
'namespace' => 'membercore\\cli\\commands',
'dependency' => null,
'description' => 'Activate a MemberPress/MemberCore mothership license (--key required)',
],
[
'slug' => 'mepr license',
'class' => 'License',
'namespace' => 'membercore\\cli\\commands',
'dependency' => null,
'description' => 'Activate a MemberPress/MemberCore mothership license (--key required)',
],
];
// Register the interactive TUI
WP_CLI::add_command('meco ui', 'membercore\\cli\\commands\\Ui');
// Register commands
foreach ($commands as $command) {
$class_name = $command['namespace'] . '\\' . $command['class'];
// Check if command class exists
if (!class_exists($class_name)) {
WP_CLI::debug("Command class {$class_name} not found", 'membercore-cli');
continue;
}
// Check if dependency exists (if specified)
if (isset($command['dependency']) && !class_exists($command['dependency'])) {
WP_CLI::debug("Dependency {$command['dependency']} not found for {$command['slug']}", 'membercore-cli');
continue;
}
// Register the command
try {
WP_CLI::add_command($command['slug'], $class_name);
WP_CLI::debug("Registered command: {$command['slug']}", 'membercore-cli');
} catch (Exception $e) {
WP_CLI::debug("Failed to register command {$command['slug']}: " . $e->getMessage(), 'membercore-cli');
}
}
// Add success message for debugging
WP_CLI::debug('MemberCore CLI commands initialized', 'membercore-cli');
}, 10);
/**
* Show warning if MemberCore is not active
*/
add_action('admin_notices', function() {
if (!class_exists('MecoTransaction') && current_user_can('activate_plugins')) {
?>
<div class="notice notice-warning">
<p>
<strong>MemberCore CLI:</strong>
MemberCore plugin is not active. Some CLI commands may not work properly.
</p>
</div>
<?php
}
});
/**
* Add plugin action links
*/
add_filter('plugin_action_links_' . plugin_basename(__FILE__), function($links) {
$plugin_links = [
'<a href="' . admin_url('admin.php?page=membercore-options') . '">Settings</a>',
];
return array_merge($plugin_links, $links);
});
/**
* Plugin activation hook
*/
register_activation_hook(__FILE__, function() {
// Check if WP-CLI is available
if (!defined('WP_CLI')) {
wp_die(
'MemberCore CLI requires WP-CLI to be installed and available. ' .
'Please install WP-CLI first: https://wp-cli.org/'
);
}
// Check if MemberCore is active
if (!class_exists('MecoTransaction')) {
// Create admin notice for missing MemberCore
set_transient('membercore_cli_missing_membercore', true, 60);
}
});
/**
* Show admin notice if MemberCore is missing on activation
*/
add_action('admin_notices', function() {
if (get_transient('membercore_cli_missing_membercore')) {
?>
<div class="notice notice-error is-dismissible">
<p>
<strong>MemberCore CLI:</strong>
MemberCore plugin is required but not active.
Please install and activate MemberCore first.
</p>
</div>
<?php
delete_transient('membercore_cli_missing_membercore');
}
});
/**
* Plugin deactivation hook
*/
register_deactivation_hook(__FILE__, function() {
// Clean up any transients
delete_transient('membercore_cli_missing_membercore');
});
/**
* Load text domain for translations
*/
add_action('init', function() {
load_plugin_textdomain(
'membercore-cli',
false,
dirname(plugin_basename(__FILE__)) . '/languages/'
);
});