From aaa09a01e7d7ebdc1b4532dbfa6f777084eeef70 Mon Sep 17 00:00:00 2001 From: Alexan Date: Wed, 12 Feb 2020 22:36:59 +0300 Subject: [PATCH 1/3] #226 testing wordpress version --- inc/SiteHealth.php | 73 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/inc/SiteHealth.php b/inc/SiteHealth.php index 70c4262..19f7001 100644 --- a/inc/SiteHealth.php +++ b/inc/SiteHealth.php @@ -24,14 +24,11 @@ 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 @@ -39,17 +36,55 @@ public static function init() public static function new_health_tests($tests) { - $tests['async']['wooms_check_credentials'] = [ - 'test' => 'wooms_check_login_password', + $tests['direct']['wooms_check_wordpress_version_for_wooms'] = [ + 'test' => [__CLASS__, 'wooms_check_wordpress_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 wordpress + * + * @return void + */ + public static function wooms_check_wordpress_version_for_wooms() + { + + global $wp_version; + $result = [ + 'label' => 'Проверка версии Wordpress для работы плагина WooMS & WooMS XT', + 'status' => 'good', + 'badge' => [ + 'label' => 'Уведомление WooMS', + 'color' => 'blue', + ], + 'description' => sprintf('Все хорошо! Спасибо что выбрали наш плагин %s', '🙂'), + 'test' => 'wooms_check_wordpress_version_for_wooms' // this is only for class in html block + ]; + + if ($wp_version > 3.6) { + $result['status'] = 'critical'; + $result['badge']['color'] = 'red'; + $result['actions'] = sprintf( + '

%s

', + admin_url('update-core.php'), + sprintf("Обновить Wordpress") + ); + $result['description'] = sprintf('Обновите пожалуйста Wordpress чтобы WooMS & WooMS XT работали '); + } + + return $result; + } + /** * check differences of versions * @@ -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( @@ -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']); } @@ -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')) { @@ -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', @@ -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( '

%s

', self::$settings_page_url, @@ -153,7 +189,6 @@ public static function wooms_check_login_password(){ wp_send_json_success($result); } - } SiteHealth::init(); From e294522afd21b1e229e5cf0c85c2d57a9f9e26db Mon Sep 17 00:00:00 2001 From: Alexan Date: Wed, 12 Feb 2020 22:38:01 +0300 Subject: [PATCH 2/3] #226 issue solved --- inc/SiteHealth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/SiteHealth.php b/inc/SiteHealth.php index 19f7001..19dcdc8 100644 --- a/inc/SiteHealth.php +++ b/inc/SiteHealth.php @@ -71,7 +71,7 @@ public static function wooms_check_wordpress_version_for_wooms() 'test' => 'wooms_check_wordpress_version_for_wooms' // this is only for class in html block ]; - if ($wp_version > 3.6) { + if ($wp_version < 3.6) { $result['status'] = 'critical'; $result['badge']['color'] = 'red'; $result['actions'] = sprintf( From fabcc72cea070b63c2bb97bf3ceb7ee46387373c Mon Sep 17 00:00:00 2001 From: Alexan Date: Thu, 13 Feb 2020 20:00:17 +0300 Subject: [PATCH 3/3] #226 ready to use checking woocommerce version --- inc/SiteHealth.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/inc/SiteHealth.php b/inc/SiteHealth.php index 19dcdc8..0182535 100644 --- a/inc/SiteHealth.php +++ b/inc/SiteHealth.php @@ -36,8 +36,8 @@ public static function init() public static function new_health_tests($tests) { - $tests['direct']['wooms_check_wordpress_version_for_wooms'] = [ - 'test' => [__CLASS__, 'wooms_check_wordpress_version_for_wooms'], + $tests['direct']['wooms_check_WooCommerce_version_for_wooms'] = [ + 'test' => [__CLASS__, 'wooms_check_WooCommerce_version_for_wooms'], ]; $tests['direct']['wooms_check_different_versions'] = [ @@ -52,34 +52,34 @@ public static function new_health_tests($tests) } /** - * Checking version wordpress + * Checking version WooCommerce * * @return void */ - public static function wooms_check_wordpress_version_for_wooms() + public static function wooms_check_WooCommerce_version_for_wooms() { - global $wp_version; + $wc_version = WC()->version; $result = [ - 'label' => 'Проверка версии Wordpress для работы плагина WooMS & WooMS XT', + 'label' => 'Проверка версии WooCommerce для работы плагина WooMS & WooMS XT', 'status' => 'good', 'badge' => [ 'label' => 'Уведомление WooMS', 'color' => 'blue', ], 'description' => sprintf('Все хорошо! Спасибо что выбрали наш плагин %s', '🙂'), - 'test' => 'wooms_check_wordpress_version_for_wooms' // this is only for class in html block + 'test' => 'wooms_check_WooCommerce_version_for_wooms' // this is only for class in html block ]; - if ($wp_version < 3.6) { + if ($wc_version < 3.6) { $result['status'] = 'critical'; $result['badge']['color'] = 'red'; $result['actions'] = sprintf( '

%s

', - admin_url('update-core.php'), - sprintf("Обновить Wordpress") + admin_url('plugins.php'), + sprintf("Обновить WooCommerce") ); - $result['description'] = sprintf('Обновите пожалуйста Wordpress чтобы WooMS & WooMS XT работали '); + $result['description'] = sprintf('Обновите пожалуйста WooCommerce чтобы WooMS & WooMS XT работали '); } return $result;