Skip to content

Commit

Permalink
Merge pull request #228 from wpcraft-ru/issue/226
Browse files Browse the repository at this point in the history
Issue/226
  • Loading branch information
uptimizt authored Feb 17, 2020
2 parents ae80d59 + fabcc72 commit 18a29c1
Showing 1 changed file with 54 additions and 19 deletions.
73 changes: 54 additions & 19 deletions inc/SiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,67 @@ public static function init()
{
add_filter('site_status_tests', [__CLASS__, 'new_health_tests']);

add_action('wooms-check_different_versions_of_plugins', [__CLASS__, 'wooms_check_different_versions_of_plugins']);

add_action('wp_ajax_health-check-wooms-check_login_password', [__CLASS__, 'wooms_check_login_password']);

}

/**
* adding ajax hooks for site health
* adding hooks for site health
*
* @param [type] $tests
* @return void
*/
public static function new_health_tests($tests)
{

$tests['async']['wooms_check_credentials'] = [
'test' => 'wooms_check_login_password',
$tests['direct']['wooms_check_WooCommerce_version_for_wooms'] = [
'test' => [__CLASS__, 'wooms_check_WooCommerce_version_for_wooms'],
];

$tests['direct']['wooms_check_different_versions'] = [
'test' => [__CLASS__,'wooms_check_different_versions_of_plugins'],
'test' => [__CLASS__, 'wooms_check_different_versions_of_plugins'],
];

$tests['async']['wooms_check_credentials'] = [
'test' => 'wooms_check_login_password',
];

return $tests;
}

/**
* Checking version WooCommerce
*
* @return void
*/
public static function wooms_check_WooCommerce_version_for_wooms()
{

$wc_version = WC()->version;
$result = [
'label' => 'Проверка версии WooCommerce для работы плагина WooMS & WooMS XT',
'status' => 'good',
'badge' => [
'label' => 'Уведомление WooMS',
'color' => 'blue',
],
'description' => sprintf('Все хорошо! Спасибо что выбрали наш плагин %s', '🙂'),
'test' => 'wooms_check_WooCommerce_version_for_wooms' // this is only for class in html block
];

if ($wc_version < 3.6) {
$result['status'] = 'critical';
$result['badge']['color'] = 'red';
$result['actions'] = sprintf(
'<p><a href="%s">%s</a></p>',
admin_url('plugins.php'),
sprintf("Обновить WooCommerce")
);
$result['description'] = sprintf('Обновите пожалуйста WooCommerce чтобы WooMS & WooMS XT работали ');
}

return $result;
}

/**
* check differences of versions
*
Expand All @@ -74,7 +109,7 @@ public static function wooms_check_different_versions_of_plugins()
'test' => 'wooms_check_different_versions' // this is only for class in html block
];

if($base_version !== $xt_version){
if ($base_version !== $xt_version) {
$result['status'] = 'critical';
$result['badge']['color'] = 'red';
$result['actions'] = sprintf(
Expand All @@ -88,7 +123,7 @@ public static function wooms_check_different_versions_of_plugins()
* if base version is lower
*/
if ($base_version < $xt_version) {

$result['description'] = sprintf('Пожалуйста, обновите плагин %s для лучшей производительности', $base_plugin_data['Name']);
}

Expand All @@ -107,7 +142,8 @@ public static function wooms_check_different_versions_of_plugins()
*
* @return void
*/
public static function wooms_check_login_password(){
public static function wooms_check_login_password()
{
check_ajax_referer('health-check-site-status');

if (!current_user_can('view_site_health_checks')) {
Expand All @@ -116,8 +152,8 @@ public static function wooms_check_login_password(){

$base_plugin_data = get_plugin_data(self::$plugin_dir . self::$base_plugin_url);
$url = 'https://online.moysklad.ru/api/remap/1.2/security/token';
$data_api = wooms_request($url,[],'POST');
$data_api = wooms_request($url, [], 'POST');

$result = [
'label' => "Проверка логина и пароля МойСклад",
'status' => 'good',
Expand All @@ -129,21 +165,21 @@ public static function wooms_check_login_password(){
'test' => 'wooms_check_credentials' // this is only for class in html block
];

if(!array_key_exists('errors', $data_api)){
if (!array_key_exists('errors', $data_api)) {
wp_send_json_success($result);
}

if(array_key_exists('errors', $data_api)){
if (array_key_exists('errors', $data_api)) {
$result['status'] = 'critical';
$result['badge']['color'] = 'red';
$result['description'] = sprintf("Что то пошло не так при подключении к МойСклад",'🤔');
}
$result['description'] = sprintf("Что то пошло не так при подключении к МойСклад", '🤔');
}

/**
* 1056 is mean that login or the password is not correct
*/
if($data_api["errors"][0]['code'] === 1056){
$result['description'] = sprintf("Неверный логин или пароль от МойСклад %s",'🤔');
if ($data_api["errors"][0]['code'] === 1056) {
$result['description'] = sprintf("Неверный логин или пароль от МойСклад %s", '🤔');
$result['actions'] = sprintf(
'<p><a href="%s">%s</a></p>',
self::$settings_page_url,
Expand All @@ -153,7 +189,6 @@ public static function wooms_check_login_password(){

wp_send_json_success($result);
}

}

SiteHealth::init();

0 comments on commit 18a29c1

Please sign in to comment.