Skip to content

Commit

Permalink
Release version 2.4.0
Browse files Browse the repository at this point in the history
Merge branch 'v2.4.0'
  • Loading branch information
jakubboucek committed May 26, 2021
2 parents 9f4d143 + be395a8 commit 51928f1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 53 deletions.
10 changes: 5 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Stable tag: trunk
License: MIT
License URI: https://github.com/redbitcz/simpleshop-wp-plugin/blob/master/LICENSE

Plugin pro propojení WordPress a SimpleShop.cz
Plugin to connection WordPress and SimpleShop.cz

== Screenshots ==
1. Rozšířený editor
2. Vložení formuláře v administraci
3. Zobrazený formulář ve stránce
1. Extended editor
2. Insert form in administration
3. Form rendered in a page

== Changelog ==
See https://github.com/redbitcz/simpleshop-wp-plugin/releases
See [Release notes](https://github.com/redbitcz/simpleshop-wp-plugin/releases)
13 changes: 10 additions & 3 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,18 @@ protected function load_simpleshop_products() {

if ( is_iterable( $ret ) ) {
foreach ( $ret as $product ) {
if ( isset( $product['code'], $product['name'] ) ) {
if ( isset( $product['code'], $product['name'], $product['archived'] ) && $product['archived'] === false ) {
$values[ $product['code'] ] = $product['name'];
}
}
}

// Sort by name - Collator support UTF-8, but requires `intl` extension
if ( class_exists( \Collator::class ) ) {
( new Collator( 'cz_CZ' ) )->asort( $values );
} else {
asort( $values, SORT_FLAG_CASE | SORT_NATURAL );
}
}

return $values;
Expand Down Expand Up @@ -158,10 +165,10 @@ public function publishing_actions() {
$group = new Group();
$groups = $group->get_groups();

$outputGroups = [[ 'text' => __( 'Doesn\'t matter', 'simpleshop-cz' ), 'value' => '' ]];
$outputGroups = [ [ 'text' => __( 'Doesn\'t matter', 'simpleshop-cz' ), 'value' => '' ] ];

foreach ( $groups as $value => $text ) {
$outputGroups[] = [ 'text' => $text, 'value' => (string)$value ];
$outputGroups[] = [ 'text' => $text, 'value' => (string) $value ];
}
?>

Expand Down
63 changes: 37 additions & 26 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct( $mainFile ) {
$this->secure_key = $this->load_api_key();
$this->email = $this->load_email();

register_activation_hook( plugin_dir_path( $this->pluginMainFile ), [ $this, 'ssc_activation_hook' ] );
$this->reactivate_updated_plugin();
}

private function init() {
Expand All @@ -67,14 +67,6 @@ private function init_gutenberg() {
new Gutenberg( $this->admin, $this->group, $this->access, $this->pluginMainFile, $this->shortcodes );
}

public function generate_secure_key() {
return bin2hex( random_bytes( 22 ) );
}

public function save_secure_key( $key ) {
update_option( 'ssc_secure_key', $key );
}

public function has_credentials() {
return $this->email && $this->secure_key;
}
Expand Down Expand Up @@ -111,7 +103,7 @@ public function get_settings() {
public function get_access() {
return $this->access;
}

public function get_post_types() {
$args = [
'public' => true
Expand All @@ -120,22 +112,6 @@ public function get_post_types() {
return get_post_types( $args );
}


public function ssc_activation_hook() {
if ( ! function_exists( 'curl_init' ) || ! function_exists( 'random_bytes' ) ) {
echo '<h3>' . __( 'Plugin activation failed. Please contact your provider and ask to install PHP extensions: cUrl and Mcrypt.',
'simpleshop-cz' ) . '</h3>';

//Adding @ before will prevent XDebug output
@trigger_error( __( 'Plugin activation failed. Please contact your provider and ask to install PHP extensions: cUrl and Mcrypt.',
'simpleshop-cz' ), E_USER_ERROR );
}

// Generate and save the secure key
$key = $this->generate_secure_key();
$this->save_secure_key( $key );
}

public function get_plugin_main_file() {
return $this->pluginMainFile;
}
Expand All @@ -161,4 +137,39 @@ public function get_api_client( $overrideLogin = null, $overrideApiKey = null )

return $client;
}

/**
* Detects plugin update (compare current and last known plugin version) and re-activate it when version changed
*
* @link https://wordpress.stackexchange.com/a/144873
*/
public function reactivate_updated_plugin( ) {
$current_version = SIMPLESHOP_PLUGIN_VERSION;
$previous_version = get_option('ssc_plugin_version', null);

/** @noinspection TypeUnsafeComparisonInspection */
if( $current_version != $previous_version) {
update_option('ssc_plugin_version', $current_version);
$this->init_plugin_activation();
}
}

/**
* Init plugin activation at SimpleShop API
*
* @param VyfakturujAPI|null $api_client
*
* @return array|false|mixed
*/
public function init_plugin_activation( VyfakturujAPI $api_client = null ) {
if($api_client === null && $this->has_credentials()) {
$api_client = $this->get_api_client();
}

if($api_client === null) {
return false;
}

return $api_client->initWPPlugin( site_url() );
}
}
18 changes: 9 additions & 9 deletions src/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Redbit\SimpleShop\WpPlugin;

use WP_Error;
use WP_Post;
use WP_REST_Controller;
use WP_REST_Request;
use WP_REST_Response;
Expand Down Expand Up @@ -90,8 +89,6 @@ public function create_item( $request ) {
}

// Check if user with this email exists, if not, create a new user
$_login = $email;
$_password = '<a href="' . wp_lostpassword_url( get_bloginfo( 'url' ) ) . '">Změnit ho můžete zde</a>';
if ( ! email_exists( $email ) ) {
$_password = wp_generate_password( 8, false );

Expand All @@ -106,7 +103,6 @@ public function create_item( $request ) {
$userdata = apply_filters( 'ssc_new_user_data', $userdata );

$user_id = wp_insert_user( $userdata );
// wp_new_user_notification($user_id,$userdata['user_pass']); // poslani notifikacniho e-mailu

do_action( 'ssc_new_user_created', $user_id );

Expand All @@ -115,13 +111,19 @@ public function create_item( $request ) {
[ 'status' => 500, 'plugin_version' => SIMPLESHOP_PLUGIN_VERSION ] );
}
} else {
$_password = '<i>' . sprintf(
__(
'Your current password (which you set or we sent to you in a previous email). If you have lost your password, <a href="%s">you can reset it here</a>.',
'simpleshop-cz'
),
esc_attr( wp_lostpassword_url( get_bloginfo( 'url' ) ) )
) . '</i>';

// Get user_by email
$user = get_user_by( 'email', $email );
$user_id = $user->ID;
}

// Check if group exists
$user_groups = [];
foreach ( $request->get_param( 'user_group' ) as $group ) {
$ssc_group = new Group( $group );

Expand All @@ -133,8 +135,6 @@ public function create_item( $request ) {
$membership = new Membership( $user_id );
$valid_to = $request->get_param( 'valid_to' ) ?: '';
$membership->set_valid_to( $group, $valid_to );

$user_groups[] = $group;
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public function create_item_permissions_check( $request ) {
/**
* Prepare the item for the REST response
*
* @param mixed $item WordPress representation of the item.
* @param mixed $item WordPress representation of the item.
* @param WP_REST_Request $request Request object.
*
* @return mixed
Expand Down
12 changes: 2 additions & 10 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,6 @@ public function add_options_page_metabox() {
'classes_cb' => [ $this, 'hide_when_invalid_keys' ],
]
);
$cmb->add_field(
[
'name' => __( 'Redirect after login', 'simpleshop-cz' ),
'type' => 'text',
'id' => 'ssc_redirect_url',
'classes_cb' => [ $this, 'hide_when_invalid_keys' ],
]
);
$cmb->add_field(
[
'name' => __( 'Remove secured items from RSS', 'simpleshop-cz' ),
Expand Down Expand Up @@ -380,8 +372,8 @@ public function settings_notices( $object_id, $updated ) {

$vyfakturuj_api = $this->loader->get_api_client( $api_email, $api_key );
try {
$result = $vyfakturuj_api->initWPPlugin( site_url() );
if ( isset( $result['status'] ) && $result['status'] == 'success' ) {
$result = $this->loader->init_plugin_activation($vyfakturuj_api);
if ( isset( $result['status'] ) && $result['status'] === 'success' ) {
update_option( 'ssc_valid_api_keys', 1 );
} else {
update_option( 'ssc_valid_api_keys', 0 );
Expand Down

0 comments on commit 51928f1

Please sign in to comment.