Skip to content

Commit

Permalink
Merge branch 'v2.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubboucek committed Jan 28, 2021
2 parents 8fa68be + 3dd5212 commit 5ad1d46
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
Binary file modified languages/simpleshop-cz-cs_CZ.mo
Binary file not shown.
11 changes: 9 additions & 2 deletions languages/simpleshop-cz-cs_CZ.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>\n"
"Language-Team: Redbit s.r.o. <[email protected]>\n"
"Language: cs_CZ\n"

#: src/Admin.php:152 src/Admin.php:154 src/Admin.php:155 src/Admin.php:161
msgid "Member sections"
Expand Down Expand Up @@ -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"


11 changes: 11 additions & 0 deletions src/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
33 changes: 17 additions & 16 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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() );
}
}


Expand Down
17 changes: 13 additions & 4 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Redbit\SimpleShop\WpPlugin;

use Exception;
use VyfakturujAPIException;

/**
* CMB2 Theme Options
Expand Down Expand Up @@ -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;
}


Expand Down

0 comments on commit 5ad1d46

Please sign in to comment.