| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\CLI; |
| 4 |
|
| 5 |
|
| 6 |
class Commands |
| 7 |
{ |
| 8 |
public function stats($args, $assoc_args) |
| 9 |
{ |
| 10 |
$overallStats = [ |
| 11 |
[ |
| 12 |
'title' => __('All Forms', 'fluentform'), |
| 13 |
'count' => wpFluent()->table('fluentform_forms')->count(), |
| 14 |
], |
| 15 |
[ |
| 16 |
'title' => __('All Submissions', 'fluentform'), |
| 17 |
'count' => wpFluent()->table('fluentform_submissions')->count(), |
| 18 |
], |
| 19 |
[ |
| 20 |
'title' => __('Unread Submissions', 'fluentform'), |
| 21 |
'count' => wpFluent()->table('fluentform_submissions') |
| 22 |
->where('status', 'unread') |
| 23 |
->count(), |
| 24 |
] |
| 25 |
]; |
| 26 |
|
| 27 |
$format = \WP_CLI\Utils\get_flag_value($assoc_args, 'format', 'table'); |
| 28 |
|
| 29 |
\WP_CLI\Utils\format_items( |
| 30 |
$format, |
| 31 |
$overallStats, |
| 32 |
['title', 'count'] |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
public function activate_license($args, $assoc_args) |
| 37 |
{ |
| 38 |
if (!defined('FLUENTFORMPRO')) { |
| 39 |
\WP_CLI::line('Fluent Forms pro is not available'); |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
if (empty($assoc_args['key'])) { |
| 44 |
\WP_CLI::line('use --key=LICENSE_KEY to activate the license'); |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$licenseKey = trim(sanitize_text_field($assoc_args['key'])); |
| 49 |
|
| 50 |
if (!function_exists('fluentFormProActivateLicense')) { |
| 51 |
\WP_CLI::line('Sorry, fluent forms pro plugin is not up to date'); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
\WP_CLI::line('Validating License, Please wait'); |
| 56 |
|
| 57 |
$response = fluentFormProActivateLicense($licenseKey); |
| 58 |
|
| 59 |
|
| 60 |
if (is_wp_error($response)) { |
| 61 |
\WP_CLI::error($response->get_error_message()); |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
\WP_CLI::success('Your license key has been successfully updated'); |
| 66 |
|
| 67 |
\WP_CLI::line('Your License Status: ' . $response['status']); |
| 68 |
\WP_CLI::line('Expire Date: ' . $response['response']->expires); |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
public function license_status() |
| 73 |
{ |
| 74 |
|
| 75 |
if (!defined('FLUENTFORMPRO')) { |
| 76 |
\WP_CLI::line('Fluent Forms pro is not available'); |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
$instance = \FluentFormAddOnChecker::getInstance(); |
| 81 |
|
| 82 |
if (!$instance) { |
| 83 |
\WP_CLI::line('FluentCRM Pro is not initiated'); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
\WP_CLI::line('Fetching License details, Please wait'); |
| 88 |
|
| 89 |
$response = $instance->getRemoteLicense(); |
| 90 |
|
| 91 |
if (is_wp_error($response)) { |
| 92 |
\WP_CLI::error($response->get_error_message()); |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
if (!$response) { |
| 97 |
\WP_CLI::error('License key has not been set!'); |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
\WP_CLI::line('Your License Status: ' . $response->license); |
| 103 |
\WP_CLI::line('Expires: ' . $response->expires); |
| 104 |
return; |
| 105 |
} |
| 106 |
} |
| 107 |
|