From 474893f771f27062bceb177a7569e3f8a8ebabc2 Mon Sep 17 00:00:00 2001
From: Sultan Nasir Uddin
After purchase"
msgid_plural "%s Days
After purchase"
msgstr[0] ""
msgstr[1] ""
-#: src/Admin/ListTables/KeysTable.php:495 src/Admin/Orders.php:197
+#: src/Admin/ListTables/KeysTable.php:531 src/Admin/Orders.php:197
#: src/Functions/Template.php:63 src/functions.php:1030
msgid "Lifetime"
msgstr ""
@@ -484,8 +488,8 @@ msgstr ""
msgid "Reports"
msgstr ""
-#: src/Admin/Menus.php:189 src/Admin/Metaboxes.php:135
-#: src/Admin/Metaboxes.php:156
+#: src/Admin/Menus.php:189 src/Admin/Metaboxes.php:136
+#: src/Admin/Metaboxes.php:157
msgid "Upgrade to Pro"
msgstr ""
@@ -548,55 +552,55 @@ msgstr ""
msgid "Not scheduled"
msgstr ""
-#: src/Admin/Metaboxes.php:56
+#: src/Admin/Metaboxes.php:57
msgid "Sell keys"
msgstr ""
-#: src/Admin/Metaboxes.php:57
+#: src/Admin/Metaboxes.php:58
msgid "Enable this if you are selling keys or licensing this product."
msgstr ""
-#: src/Admin/Metaboxes.php:70
+#: src/Admin/Metaboxes.php:71
msgid "Delivery quantity"
msgstr ""
-#: src/Admin/Metaboxes.php:71
+#: src/Admin/Metaboxes.php:72
msgid "Number of key(s) will be delivered per item. Available in PRO."
msgstr ""
-#: src/Admin/Metaboxes.php:91 src/Admin/Metaboxes.php:123
+#: src/Admin/Metaboxes.php:92 src/Admin/Metaboxes.php:124
msgid "Key source"
msgstr ""
-#: src/Admin/Metaboxes.php:109
+#: src/Admin/Metaboxes.php:110
msgid "Software version"
msgstr ""
-#: src/Admin/Metaboxes.php:110
+#: src/Admin/Metaboxes.php:111
msgid "Version number for the software. Ignore if it's not a software."
msgstr ""
-#: src/Admin/Metaboxes.php:111
+#: src/Admin/Metaboxes.php:112
msgid "e.g. 1.0"
msgstr ""
-#: src/Admin/Metaboxes.php:125
+#: src/Admin/Metaboxes.php:126
msgid "key available."
msgid_plural "keys available."
msgstr[0] ""
msgstr[1] ""
-#: src/Admin/Metaboxes.php:133
+#: src/Admin/Metaboxes.php:134
msgid "Want to sell keys for variable products?"
msgstr ""
-#: src/Admin/Metaboxes.php:154
+#: src/Admin/Metaboxes.php:155
msgid ""
"The free version of Serial Numbers for WooCommerce does not support product "
"variation."
msgstr ""
-#: src/Admin/Metaboxes.php:229
+#: src/Admin/Metaboxes.php:230
msgid "Order missing serial numbers for this item."
msgstr ""
@@ -1135,7 +1139,7 @@ msgstr ""
#: src/Admin/views/html-api-actions.php:162
#: src/Admin/views/html-api-validation.php:144
#: src/Admin/views/html-edit-key.php:154 src/Deprecated/Functions.php:360
-#: src/Frontend/Shortcodes.php:43 src/Frontend/Shortcodes.php:139
+#: src/Frontend/Shortcodes.php:43 src/Frontend/Shortcodes.php:140
msgid "Email"
msgstr ""
@@ -1151,15 +1155,15 @@ msgid ""
"ignored."
msgstr ""
-#: src/Admin/views/html-api-actions.php:172 src/Frontend/Shortcodes.php:145
+#: src/Admin/views/html-api-actions.php:172 src/Frontend/Shortcodes.php:146
msgid "Action"
msgstr ""
-#: src/Admin/views/html-api-actions.php:175 src/Frontend/Shortcodes.php:152
+#: src/Admin/views/html-api-actions.php:175 src/Frontend/Shortcodes.php:153
msgid "Activate"
msgstr ""
-#: src/Admin/views/html-api-actions.php:176 src/Frontend/Shortcodes.php:153
+#: src/Admin/views/html-api-actions.php:176 src/Frontend/Shortcodes.php:154
msgid "Deactivate"
msgstr ""
@@ -1172,7 +1176,7 @@ msgstr ""
msgid "API response"
msgstr ""
-#: src/Admin/views/html-api-actions.php:195 src/Frontend/Shortcodes.php:146
+#: src/Admin/views/html-api-actions.php:195 src/Frontend/Shortcodes.php:147
#: vendor/lucatume/wp-browser/src/data/plugins/wordpress-importer/wordpress-importer.php:284
msgid "Submit"
msgstr ""
@@ -1373,16 +1377,16 @@ msgstr ""
msgid "Serial Key Validation"
msgstr ""
-#: src/Frontend/Shortcodes.php:41 src/Frontend/Shortcodes.php:137
+#: src/Frontend/Shortcodes.php:41 src/Frontend/Shortcodes.php:138
msgid "Serial Key"
msgstr ""
-#: src/Frontend/Shortcodes.php:42 src/Frontend/Shortcodes.php:138
+#: src/Frontend/Shortcodes.php:42 src/Frontend/Shortcodes.php:139
msgid "Enter your serial key"
msgstr ""
#: src/Frontend/Shortcodes.php:44 src/Frontend/Shortcodes.php:105
-#: src/Frontend/Shortcodes.php:140 src/Frontend/Shortcodes.php:216
+#: src/Frontend/Shortcodes.php:141 src/Frontend/Shortcodes.php:217
msgid "Enter your email"
msgstr ""
@@ -1390,23 +1394,23 @@ msgstr ""
msgid "No products found."
msgstr ""
-#: src/Frontend/Shortcodes.php:90 src/Frontend/Shortcodes.php:200
+#: src/Frontend/Shortcodes.php:90 src/Frontend/Shortcodes.php:201
msgid "Select a product"
msgstr ""
-#: src/Frontend/Shortcodes.php:135
+#: src/Frontend/Shortcodes.php:136
msgid "Activate/Deactivate Serial Key"
msgstr ""
-#: src/Frontend/Shortcodes.php:142
+#: src/Frontend/Shortcodes.php:143
msgid "Enter your instance"
msgstr ""
-#: src/Frontend/Shortcodes.php:144
+#: src/Frontend/Shortcodes.php:145
msgid "Enter platform"
msgstr ""
-#: src/Frontend/Shortcodes.php:186
+#: src/Frontend/Shortcodes.php:187
msgid "Could not find any products with serial numbers enabled."
msgstr ""
@@ -1479,12 +1483,12 @@ msgstr ""
msgid "Order automatically completed by the Serial Numbers for WooCommerce."
msgstr ""
-#: src/Plugin.php:69
+#: src/Plugin.php:63
#. translators: 1: plugin name 2: WooCommerce
msgid "%1$s requires %2$s to be installed and active."
msgstr ""
-#: src/Plugin.php:71
+#: src/Plugin.php:65
msgid "WooCommerce"
msgstr ""
diff --git a/package.json b/package.json
index e1f8c560..2d2a9c4d 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "wc-serial-numbers",
"title": "Serial Numbers for WooCommerce",
- "version": "1.6.3",
+ "version": "1.6.4",
"description": "The best WooCommerce extension to sell license & serial keys, gift cards and other secret numbers!",
"homepage": "https://pluginever.com/plugins/wc-serial-numbers/",
"license": "GPL-3.0+",
diff --git a/readme.txt b/readme.txt
index 8b3442e7..5434bb38 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: license manager, license, license number, serial number, activation number
Requires at least: 5.0
Tested up to: 6.3
Requires PHP: 5.6
-Stable tag: 1.6.3
+Stable tag: 1.6.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -252,6 +252,9 @@ Yes, you are always welcome to [provide suggestions](https://github.com/pluginev
== Changelog ==
+= 1.6.4 (25 Oct 2023) =
+* Enhance: Optimize and improve code for better performance & security.
+
= 1.6.3 (8 Oct 2023) =
* Fix: Dropdown active color is not working.
* Enhance: Allow keys to be sold without checking key source.
diff --git a/src/API.php b/src/API.php
index 6f4270f3..987e8105 100644
--- a/src/API.php
+++ b/src/API.php
@@ -35,11 +35,32 @@ public function __construct() {
* @since 1.0.0
*/
public static function process_request() {
- $product_id = isset( $_REQUEST['product_id'] ) ? absint( $_REQUEST['product_id'] ) : 0;
- $key = isset( $_REQUEST['serial_key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['serial_key'] ) ) : '';
- $action = isset( $_REQUEST['request'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['request'] ) ) : '';
- $email = isset( $_REQUEST['email'] ) ? strtolower( sanitize_text_field( wp_unslash( $_REQUEST['email'] ) ) ) : '';
+ $method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_SPECIAL_CHARS );
+ if ( 'POST' === strtoupper( $method ) ) {
+ $product_id = filter_input( INPUT_POST, 'product_id', FILTER_SANITIZE_NUMBER_INT );
+ $key = filter_input( INPUT_POST, 'serial_key', FILTER_SANITIZE_SPECIAL_CHARS );
+ $action = filter_input( INPUT_POST, 'request', FILTER_SANITIZE_SPECIAL_CHARS );
+ $email = filter_input( INPUT_POST, 'email', FILTER_SANITIZE_SPECIAL_CHARS );
+ } elseif ( 'GET' === strtoupper( $method ) ) {
+ $product_id = filter_input( INPUT_GET, 'product_id', FILTER_SANITIZE_NUMBER_INT );
+ $key = filter_input( INPUT_GET, 'serial_key', FILTER_SANITIZE_SPECIAL_CHARS );
+ $action = filter_input( INPUT_GET, 'request', FILTER_SANITIZE_SPECIAL_CHARS );
+ $email = filter_input( INPUT_GET, 'email', FILTER_SANITIZE_SPECIAL_CHARS );
+ } else {
+ // its unknown request method.
+ wp_send_json_error(
+ array(
+ 'code' => 'invalid_request_method',
+ 'message' => __( 'Invalid request method.', 'wc-serial-numbers' ),
+ )
+ );
+ }
+ // Clean up properties.
+ $product_id = absint( $product_id );
+ $key = sanitize_text_field( wp_unslash( $key ) );
+ $action = sanitize_key( wp_unslash( $action ) );
+ $email = strtolower( sanitize_email( wp_unslash( $email ) ) );
WCSN()->log(
'API request',
'debug',
diff --git a/src/Admin/ListTables/ActivationsTable.php b/src/Admin/ListTables/ActivationsTable.php
index c90d2fdf..b7bb8755 100644
--- a/src/Admin/ListTables/ActivationsTable.php
+++ b/src/Admin/ListTables/ActivationsTable.php
@@ -55,14 +55,14 @@ public function prepare_items() {
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$current_page = $this->get_pagenum();
- $orderby = isset( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'order_date';
- $order = isset( $_GET['order'] ) ? sanitize_key( $_GET['order'] ) : 'desc';
- $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null;
- $product_id = isset( $_GET['product_id'] ) ? absint( $_GET['product_id'] ) : '';
- $order_id = isset( $_GET['order_id'] ) ? absint( $_GET['order_id'] ) : '';
- $customer_id = isset( $_GET['customer_id'] ) ? absint( $_GET['customer_id'] ) : '';
- $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : '';
- $serial_id = isset( $_GET['serial_id'] ) ? absint( $_GET['serial_id'] ) : '';
+ $orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_SPECIAL_CHARS );
+ $order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_SPECIAL_CHARS );
+ $search = filter_input( INPUT_GET, 's', FILTER_SANITIZE_SPECIAL_CHARS );
+ $product_id = filter_input( INPUT_GET, 'product_id', FILTER_SANITIZE_NUMBER_INT );
+ $order_id = filter_input( INPUT_GET, 'order_id', FILTER_SANITIZE_NUMBER_INT );
+ $customer_id = filter_input( INPUT_GET, 'customer_id', FILTER_SANITIZE_NUMBER_INT );
+ $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
+ $serial_id = filter_input( INPUT_GET, 'serial_id', FILTER_SANITIZE_NUMBER_INT );
if ( array_key_exists( $orderby, $this->get_sortable_columns() ) && 'order_date' !== $orderby ) {
$args['orderby'] = $orderby;
@@ -123,7 +123,7 @@ protected function extra_tablenav( $which ) {
* @since 1.4.6
*/
public function process_bulk_actions( $doaction ) {
- if ( $doaction ) {
+ if ( $doaction && check_ajax_referer( 'bulk-activations' ) ) {
if ( isset( $_REQUEST['id'] ) ) {
$ids = wp_parse_id_list( wp_unslash( $_REQUEST['id'] ) );
$doaction = ( - 1 !== $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2']; // phpcs:ignore
@@ -237,7 +237,7 @@ protected function column_instance( $activation ) {
),
admin_url( 'admin.php?page=wc-serial-numbers-activations' )
);
- $actions['delete'] = sprintf( '%2$s', esc_url( $delete_url ), __( 'Delete', 'wc-serial-numbers' ) );
+ $actions['delete'] = sprintf( '%2$s', wp_nonce_url( $delete_url, 'bulk-activations' ), __( 'Delete', 'wc-serial-numbers' ) );
return sprintf( '%1$s
%2$s', esc_html( $activation->get_instance() ), $this->row_actions( $actions ) );
}
diff --git a/src/Admin/ListTables/KeysTable.php b/src/Admin/ListTables/KeysTable.php
index 0f914244..4a6c5ae6 100644
--- a/src/Admin/ListTables/KeysTable.php
+++ b/src/Admin/ListTables/KeysTable.php
@@ -94,14 +94,14 @@ public function prepare_items() {
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$current_page = $this->get_pagenum();
- $status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
- $orderby = isset( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'order_date';
- $order = isset( $_GET['order'] ) ? sanitize_key( $_GET['order'] ) : 'desc';
- $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null;
- $product_id = isset( $_GET['product_id'] ) ? absint( $_GET['product_id'] ) : '';
- $order_id = isset( $_GET['order_id'] ) ? absint( $_GET['order_id'] ) : '';
- $customer_id = isset( $_GET['customer_id'] ) ? absint( $_GET['customer_id'] ) : '';
- $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : '';
+ $status = filter_input( INPUT_GET, 'status', FILTER_SANITIZE_SPECIAL_CHARS );
+ $orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_SPECIAL_CHARS );
+ $order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_SPECIAL_CHARS );
+ $search = filter_input( INPUT_GET, 's', FILTER_SANITIZE_SPECIAL_CHARS );
+ $product_id = filter_input( INPUT_GET, 'product_id', FILTER_SANITIZE_NUMBER_INT );
+ $order_id = filter_input( INPUT_GET, 'order_id', FILTER_SANITIZE_NUMBER_INT );
+ $customer_id = filter_input( INPUT_GET, 'customer_id', FILTER_SANITIZE_NUMBER_INT );
+ $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
if ( ! empty( $status ) && ! array_key_exists( $status, wcsn_get_key_statuses() ) ) {
$status = 'available';
}
@@ -290,7 +290,7 @@ protected function extra_tablenav( $which ) {
* @since 1.4.6
*/
public function process_bulk_actions( $doaction ) {
- if ( $doaction ) {
+ if ( $doaction && check_ajax_referer( 'bulk-' . $this->_args['plural'] ) ) {
if ( wp_unslash( isset( $_REQUEST['id'] ) ) ) {
$ids = wp_parse_id_list( wp_unslash( $_REQUEST['id'] ) );
$doaction = ( - 1 !== $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2']; // phpcs:ignore
@@ -424,7 +424,7 @@ protected function column_key( $item ) {
// translators: %d: key id.
$actions['id'] = sprintf( __( 'ID: %d', 'wc-serial-numbers' ), esc_html( $item->id ) );
$actions['edit'] = sprintf( '%2$s', $edit_url, __( 'Edit', 'wc-serial-numbers' ) );
- $actions['delete'] = sprintf( '%2$s', $delete_url, __( 'Delete', 'wc-serial-numbers' ) );
+ $actions['delete'] = sprintf( '%2$s', wp_nonce_url( $delete_url, 'bulk-keys' ), __( 'Delete', 'wc-serial-numbers' ) );
return sprintf( '%1$s %2$s', $item->print_key( $is_hidden ), $this->row_actions( $actions ) );
}
diff --git a/src/Admin/ListTables/ListTable.php b/src/Admin/ListTables/ListTable.php
index 56895364..3539c210 100644
--- a/src/Admin/ListTables/ListTable.php
+++ b/src/Admin/ListTables/ListTable.php
@@ -202,17 +202,6 @@ public function customer_dropdown() {
* @since 1.4.6
*/
public function process_bulk_actions( $doaction ) {
- if ( isset( $_GET['_wp_http_referer'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
- wp_safe_redirect(
- remove_query_arg(
- array(
- '_wp_http_referer',
- '_wpnonce',
- ),
- wp_get_referer()
- )
- );
- exit;
- }
+ $referer = wp_get_referer();
}
}
diff --git a/src/Admin/ListTables/StockTable.php b/src/Admin/ListTables/StockTable.php
index 4fc2b87b..6e08b512 100644
--- a/src/Admin/ListTables/StockTable.php
+++ b/src/Admin/ListTables/StockTable.php
@@ -30,17 +30,16 @@ public function __construct() {
* @since 1.4.6
*/
public function prepare_items() {
- check_admin_referer( 'wc-serial-numbers-stock' );
$per_page = 20;
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$current_page = $this->get_pagenum();
- $orderby = isset( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'order_date';
- $order = isset( $_GET['order'] ) ? sanitize_key( $_GET['order'] ) : 'desc';
- $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null;
- $product_id = isset( $_GET['product_id'] ) ? absint( $_GET['product_id'] ) : '';
+ $orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_SPECIAL_CHARS );
+ $order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_SPECIAL_CHARS );
+ $search = filter_input( INPUT_GET, 's', FILTER_SANITIZE_SPECIAL_CHARS );
+ $product_id = filter_input( INPUT_GET, 'product_id', FILTER_SANITIZE_NUMBER_INT );
$query_args = array(
'posts_per_page' => $per_page,
diff --git a/src/Admin/Menus.php b/src/Admin/Menus.php
index 9c790cb9..5399f067 100644
--- a/src/Admin/Menus.php
+++ b/src/Admin/Menus.php
@@ -44,7 +44,7 @@ public function __construct() {
* @since 1.4.6
*/
public function setup_screen() {
- if ( isset( $_GET['edit'] ) || isset( $_GET['delete'] ) || isset( $_GET['add'] ) || isset( $_GET['generate'] ) ) {
+ if ( isset( $_GET['edit'] ) || isset( $_GET['delete'] ) || isset( $_GET['add'] ) || isset( $_GET['generate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
@@ -253,8 +253,8 @@ public function output_tools_page() {
$tabs = apply_filters( 'wc_serial_numbers_tools_tabs', $tabs );
$tab_ids = array_keys( $tabs );
- $current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids );
- $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
+ $current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
Admin::view(
'html-tools.php',
@@ -279,8 +279,8 @@ public function output_reports_page() {
$tabs = apply_filters( 'wc_serial_numbers_reports_tabs', $tabs );
$tab_ids = array_keys( $tabs );
- $current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids );
- $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
+ $current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
Admin::view(
'html-reports.php',
diff --git a/src/Frontend/Shortcodes.php b/src/Frontend/Shortcodes.php
index 05ab957f..3ecac7b3 100644
--- a/src/Frontend/Shortcodes.php
+++ b/src/Frontend/Shortcodes.php
@@ -110,6 +110,7 @@ public function validation_form( $atts ) {