| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Services\Integrations; |
| 4 |
|
| 5 |
use FluentSupport\App\Services\Helper; |
| 6 |
|
| 7 |
class Maintenance |
| 8 |
{ |
| 9 |
public function maybeProcessData() |
| 10 |
{ |
| 11 |
if (!$this->isAllowed() || !$this->timeMatched()) { |
| 12 |
return false; |
| 13 |
} |
| 14 |
|
| 15 |
$response = wp_remote_post($this->getApiUrl(), [ |
| 16 |
'body' => [ |
| 17 |
'payload' => $this->getData() |
| 18 |
], |
| 19 |
'cookies' => [] |
| 20 |
]); |
| 21 |
|
| 22 |
if (is_wp_error($response)) { |
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
update_option('_fluent_last_m_run', time()); |
| 27 |
|
| 28 |
return true; |
| 29 |
} |
| 30 |
|
| 31 |
private function getData() |
| 32 |
{ |
| 33 |
global $wp_version; |
| 34 |
return [ |
| 35 |
'plugin_version' => FLUENT_SUPPORT_VERSION, |
| 36 |
'php_version' => (defined('PHP_VERSION')) ? PHP_VERSION : phpversion(), |
| 37 |
'wp_version' => $wp_version, |
| 38 |
'plugins' => (array)get_option('active_plugins'), |
| 39 |
'site_lang' => get_bloginfo('language'), |
| 40 |
'site_url' => site_url('/'), |
| 41 |
'theme' => wp_get_theme()->get('Name'), |
| 42 |
'admin_email' => get_bloginfo('admin_email'), |
| 43 |
'site_title' => get_bloginfo('name') |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
private function isAllowed() |
| 48 |
{ |
| 49 |
return apply_filters('fluentsupport_allow_share_essential', Helper::getOption('_share_essential', 'no') == 'yes'); |
| 50 |
} |
| 51 |
|
| 52 |
private function timeMatched() |
| 53 |
{ |
| 54 |
$prevValue = get_option('_fluent_last_m_run'); |
| 55 |
if (!$prevValue) { |
| 56 |
return true; |
| 57 |
} |
| 58 |
|
| 59 |
return (time() - $prevValue) > 518400; // 6 days match |
| 60 |
} |
| 61 |
|
| 62 |
private function getApiUrl() |
| 63 |
{ |
| 64 |
return 'https://api.wpmanageninja.com/plugin-maintenance'; |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
|