Skip to content

Commit be2ed35

Browse files
authored
1.1.2
1.1.2
2 parents 559ea42 + 288b833 commit be2ed35

3 files changed

Lines changed: 939 additions & 744 deletions

File tree

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
Ensure that your website is running PHP 8 or later. This plugin is confirmed to be working with PHP 8.3.
66

7-
1. Clone this repo.
8-
2. Zip `software-licensor-wp-plugin`
9-
3. Upload the plugin to your website.
10-
4. Navigate from the admin dashboard to `WooCommerce>Settings>Integration>Software Licensor`.
7+
1. Clone this repo and zip `software-licensor-wp-plugin`, or download the latest release.
8+
3. Upload the plugin (the zip file) to your website.
9+
4. Navigate from the admin dashboard to `Software Licensor>Store Registration`.
1110
5. Fill out the form and click save. If the form is missing data, the request might not go through and you won't be able to see a store ID in the next step.
1211
6. Navigate from the admin dashboard to `Software Licensor>Software Licensor`. Verify that you can see a roughly 64-character long string at the top under `Store ID`. You will need to include this `store_id` in the client side code.
1312
7. Navigate to `Software Licensor>Create/Update Licensed Product`. Fill out the form fields. Notice the `Allow Offline` checkbox. Offline license activations are not currently supported, but there is more info about them in the `Things not yet implemented in this WordPress Plugin` section. For now, I would recommend setting it to disallow offline licenses, as this setting can be easily changed by pasting the product ID into the `Product ID/prefix` field, and copying or updating the version in the `version` field.

software-licensor-wp-plugin/Software-Licensor-Integration.php

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
* Description: A plugin for handling software licenses through Software Licensor
66
* Author: Noah Stiltner
77
* Author URI: https://www.alteredbrainchemistry.com
8-
* Version: 1.1
8+
* Version: 1.1.2
99
* Requires PHP: 8.0
1010
*
1111
* This program is free software: you can redistribute it and/or modify
1212
* it under the terms of the GNU General Public License as published by
1313
* the Free Software Foundation, either version 3 of the License, or
1414
* (at your option) any later version.
15-
*
15+
*
1616
* Do not attempt to maliciously abuse the Software Licensor API. Doing so
1717
* could result in a ban.
1818
*
@@ -23,11 +23,10 @@
2323
*
2424
* You should have received a copy of the GNU General Public License
2525
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26-
*
2726
*/
2827

2928
if ( ! defined( 'ABSPATH' ) ) {
30-
exit; // Exit if accessed directly
29+
exit;
3130
}
3231

3332
require_once __DIR__ . '/vendor/autoload.php';
@@ -79,34 +78,55 @@
7978
require_once 'includes/api/requests_and_responses.php';
8079

8180
if ( ! class_exists( 'WC_Software_Licensor' ) ) :
82-
class WC_Software_licensor {
83-
/**
84-
* Construct the plugin.
85-
*/
86-
public function __construct() {
87-
add_action( 'plugins_loaded', array( $this, 'init' ) );
88-
}
89-
/**
90-
* Initialize the plugin.
91-
*/
92-
public function init() {
93-
// Checks if WooCommerce is installed.
94-
if ( class_exists( 'WC_Integration' ) ) {
95-
// Include our integration class.
96-
include_once 'includes/class-wc-software-licensor-integration.php';
97-
// Register the integration.
98-
add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) );
99-
} else {
100-
// throw an admin error if you like
101-
}
102-
}
103-
/**
104-
* Add a new integration to WooCommerce.
105-
*/
106-
public function add_integration( $integrations ) {
107-
$integrations[] = 'WC_Software_Licensor_Integration';
108-
return $integrations;
109-
}
81+
82+
class WC_Software_Licensor {
83+
84+
/**
85+
* @var WC_Software_Licensor_Integration|null
86+
*/
87+
private $integration = null;
88+
89+
public function __construct() {
90+
add_action( 'plugins_loaded', array( $this, 'init' ), 20 );
91+
}
92+
93+
/**
94+
* Initialize the plugin after WooCommerce is available.
95+
*
96+
* @return void
97+
*/
98+
public function init() {
99+
if ( ! class_exists( 'WooCommerce' ) ) {
100+
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
101+
return;
102+
}
103+
104+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-software-licensor-integration.php';
105+
106+
if ( class_exists( 'WC_Software_Licensor_Integration' ) ) {
107+
$this->integration = new WC_Software_Licensor_Integration();
108+
}
109+
}
110+
111+
/**
112+
* Display an admin notice if WooCommerce is not active.
113+
*
114+
* @return void
115+
*/
116+
public function woocommerce_missing_notice() {
117+
if ( ! current_user_can( 'activate_plugins' ) ) {
118+
echo '<div class="notice notice-error"><p>';
119+
echo esc_html__('Software Licensor Integration requires WooCommerce to be installed and active, but you do not have permission to activate plugins.', 'software-licensor');
120+
echo '</p></div>';
121+
return;
122+
}
123+
124+
echo '<div class="notice notice-error"><p>';
125+
echo esc_html__( 'Software Licensor Integration requires WooCommerce to be installed and active.', 'software-licensor' );
126+
echo '</p></div>';
127+
}
110128
}
111-
$WC_Software_Licensor = new WC_Software_Licensor( __FILE__ );
129+
130+
new WC_Software_Licensor();
131+
112132
endif;

0 commit comments

Comments
 (0)