diff --git a/languages/simpleshop-cz-cs_CZ.mo b/languages/simpleshop-cz-cs_CZ.mo index 69ae044..20d3d47 100644 Binary files a/languages/simpleshop-cz-cs_CZ.mo and b/languages/simpleshop-cz-cs_CZ.mo differ diff --git a/languages/simpleshop-cz-cs_CZ.po b/languages/simpleshop-cz-cs_CZ.po index 883f580..7460472 100644 --- a/languages/simpleshop-cz-cs_CZ.po +++ b/languages/simpleshop-cz-cs_CZ.po @@ -3,14 +3,15 @@ msgid "" msgstr "" "Project-Id-Version: SimpleShop.cz 2.0\n" -"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/simpleshop-cz" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/simpleshop-cz\n" "POT-Creation-Date: 2018-10-01 06:22:45+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2018-10-01 06:22:45+00:00\n" +"PO-Revision-Date: 2021-01-28 09:53:32+01:00\n" "Last-Translator: Jakub Bouček \n" "Language-Team: Redbit s.r.o. \n" +"Language: cs_CZ\n" #: src/Admin.php:152 src/Admin.php:154 src/Admin.php:155 src/Admin.php:161 msgid "Member sections" @@ -237,3 +238,9 @@ msgstr "Nastavení upraveno" #. Description of the plugin/theme msgid "Plugin implement SimpleShop.cz into Wordpress" msgstr "Plugin pro propojení Wordpress a SimpleShop.cz" + +#: src/Settings.php:392 +msgid "Error during communication with SimpleShop API, please try it later" +msgstr "Při komunikaci se SimpleShop API došlo k chybě, prosíme zkuste to později" + + diff --git a/src/Access.php b/src/Access.php index 048825c..bc7c949 100644 --- a/src/Access.php +++ b/src/Access.php @@ -43,6 +43,15 @@ public function __construct( Settings $settings ) { * @return mixed */ public function login_redirect( $redirect, $request, $user ) { + if ( ! $user || is_wp_error( $user ) ) { + return $redirect; + } + + if ( isset( $user->roles ) && is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) { + // redirect admins to the default place + return $redirect; + } + $redirect_url = $this->settings->ssc_get_option( 'ssc_redirect_url' ); if ( $redirect_url ) { $redirect = remove_query_arg( [ 'redirect_to' ], $redirect_url ); @@ -66,6 +75,7 @@ public function check_access() { // If the post is protected and user is not logged in, redirect him to login if ( $post_groups && ! is_user_logged_in() ) { + nocache_headers(); wp_safe_redirect( wp_login_url( site_url( $_SERVER['REQUEST_URI'] ) ) ); exit(); } @@ -76,6 +86,7 @@ public function check_access() { $main_redirect_url = is_user_logged_in() ? site_url() : wp_login_url(); $url = $no_access_url ?: $main_redirect_url; + nocache_headers(); wp_redirect( $url ); exit(); } diff --git a/src/Admin.php b/src/Admin.php index d8f4884..bed05c6 100644 --- a/src/Admin.php +++ b/src/Admin.php @@ -41,6 +41,7 @@ public function __construct( Plugin $loader ) { /** * Get products from simple shop via API + * TODO: Show message if loading pf products failed */ public function wp_ajax_load_simple_shop_products() { $this->update_simpleshop_products_cache(); @@ -52,7 +53,6 @@ public function wp_ajax_load_simple_shop_products() { * Return products. If you need force refresh products from API, call `update_simpleshop_products_cache()` before * * @return array - * @throws VyfakturujAPIException */ public function get_simpleshop_products() { $products = $this->get_simpleshop_products_cache(); @@ -90,23 +90,24 @@ protected function get_simpleshop_products_cache() { /** * Update Products cache from Vyfakturuj API - * - * @throws VyfakturujAPIException */ public function update_simpleshop_products_cache() { - $products = $this->load_simpleshop_products(); - - $cacheKey = $this->loader->get_cache_user_key(); - $cachedTime = time(); - - $cache = [ - $cacheKey => array_merge( - $products, - [ self::PRODUCTS_CACHE_FIELD => $cachedTime ] - ) - ]; - - update_option( 'ssc_cache_products', $cache ); + try { + $products = $this->load_simpleshop_products(); + $cacheKey = $this->loader->get_cache_user_key(); + $cachedTime = time(); + + $cache = [ + $cacheKey => array_merge( + $products, + [ self::PRODUCTS_CACHE_FIELD => $cachedTime ] + ) + ]; + + return update_option( 'ssc_cache_products', $cache ); + } catch ( VyfakturujAPIException $e ) { + return new \WP_Error( 'api-error', $e->getMessage() ); + } } diff --git a/src/Settings.php b/src/Settings.php index 3012ccc..0b05c67 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -9,6 +9,7 @@ namespace Redbit\SimpleShop\WpPlugin; use Exception; +use VyfakturujAPIException; /** * CMB2 Theme Options @@ -378,11 +379,19 @@ public function settings_notices( $object_id, $updated ) { } $vyfakturuj_api = $this->loader->get_api_client( $api_email, $api_key ); - $result = $vyfakturuj_api->initWPPlugin( site_url() ); - if ( isset( $result['status'] ) && $result['status'] == 'success' ) { - update_option( 'ssc_valid_api_keys', 1 ); - } else { + try { + $result = $vyfakturuj_api->initWPPlugin( site_url() ); + if ( isset( $result['status'] ) && $result['status'] == 'success' ) { + update_option( 'ssc_valid_api_keys', 1 ); + } else { + update_option( 'ssc_valid_api_keys', 0 ); + } + } catch ( VyfakturujAPIException $e ) { update_option( 'ssc_valid_api_keys', 0 ); + + add_settings_error( $this->key . '-error', '', __( 'Error during communication with SimpleShop API, please try it later', 'simpleshop-cz' ), 'error' ); + settings_errors( $this->key . '-error' ); + return; }