diff --git a/assets/css/admin-style.scss b/assets/css/admin-style.scss index 9f1f9cd0..67412ae4 100644 --- a/assets/css/admin-style.scss +++ b/assets/css/admin-style.scss @@ -209,3 +209,21 @@ } } } + +// Product page. +#wc_serial_numbers_data{ + padding-bottom: 20px !important; + .wc-radios { + display: inline-block; + + li { + display: inline-block !important; + margin-right: 15px !important; + } + + + .description { + display: block; + clear: both; + } + } +} diff --git a/languages/wc-serial-numbers.pot b/languages/wc-serial-numbers.pot index 0f236e75..cf462ac7 100644 --- a/languages/wc-serial-numbers.pot +++ b/languages/wc-serial-numbers.pot @@ -2,9 +2,9 @@ # This file is distributed under the GPLv2+. msgid "" msgstr "" -"Project-Id-Version: Serial Numbers for WooCommerce 1.5.3\n" +"Project-Id-Version: Serial Numbers for WooCommerce 1.5.4\n" "Report-Msgid-Bugs-To: https://pluginever.com/plugins/wc-serial-numbers/\n" -"POT-Creation-Date: 2023-06-14 07:17:43+00:00\n" +"POT-Creation-Date: 2023-07-21 10:16:27+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -24,19 +24,20 @@ msgstr "" "X-Textdomain-Support: yes\n" "X-Generator: grunt-wp-i18n 1.0.3\n" -#: lib/Lib/Model.php:810 -msgid "Could not insert item into the database." +#: lib/Lib/Model.php:434 +#. translators: %s: database error message. +msgid "Could not insert item into the database error %s" msgstr "" -#: lib/Lib/Model.php:923 +#: lib/Lib/Model.php:499 msgid "Could not update item in the database." msgstr "" -#: lib/Lib/Plugin.php:239 src/Admin/Menus.php:200 -msgid "Upgrade to Pro" +#: lib/Lib/Plugin.php:239 +msgid "Go Pro" msgstr "" -#: lib/Lib/Plugin.php:585 src/Admin/Settings.php:188 +#: lib/Lib/Plugin.php:585 src/Admin/Settings.php:190 msgid "Documentation" msgstr "" @@ -60,29 +61,29 @@ msgstr "" msgid "Settings saved." msgstr "" -#: lib/Lib/Settings.php:228 lib/Lib/Settings.php:316 lib/Lib/Settings.php:325 -#: lib/Lib/Settings.php:334 +#: lib/Lib/Settings.php:233 lib/Lib/Settings.php:325 lib/Lib/Settings.php:334 +#: lib/Lib/Settings.php:343 msgid "Recommended" msgstr "" -#: lib/Lib/Settings.php:229 lib/Lib/Settings.php:317 lib/Lib/Settings.php:326 -#: lib/Lib/Settings.php:335 +#: lib/Lib/Settings.php:234 lib/Lib/Settings.php:326 lib/Lib/Settings.php:335 +#: lib/Lib/Settings.php:344 msgid "Install Now" msgstr "" -#: lib/Lib/Settings.php:287 +#: lib/Lib/Settings.php:296 msgid "Need Help?" msgstr "" -#: lib/Lib/Settings.php:349 +#: lib/Lib/Settings.php:358 msgid "Join our Community" msgstr "" -#: lib/Lib/Settings.php:353 +#: lib/Lib/Settings.php:362 msgid "Request a Feature" msgstr "" -#: lib/Lib/Settings.php:357 +#: lib/Lib/Settings.php:366 msgid "Report a Bug" msgstr "" @@ -205,7 +206,7 @@ msgstr "" msgid "Invalid product ID." msgstr "" -#: src/API.php:81 src/Models/Key.php:479 +#: src/API.php:81 src/Models/Key.php:496 msgid "Serial key is required." msgstr "" @@ -288,8 +289,8 @@ msgstr "" #: src/Admin/Admin.php:68 #. translators: 1: Plugin name 2: WordPress msgid "" -"Thank you for using %1$s. If you like it, please leave us a %2$s rating. A " -"huge thank you from PluginEver in advance!" +"Thank you for using %1$s! Share your appreciation with a five-star review " +"%2$s." msgstr "" #: src/Admin/Admin.php:70 @@ -309,7 +310,7 @@ msgid "Serial Numbers" msgstr "" #: src/Admin/ListTables/ActivationsTable.php:39 -#: src/Admin/ListTables/KeysTable.php:321 +#: src/Admin/ListTables/KeysTable.php:288 msgid "Activation" msgstr "" @@ -323,15 +324,15 @@ msgid "No activations found. Once a serial key is activated, it will appear here msgstr "" #: src/Admin/ListTables/ActivationsTable.php:125 -#: src/Admin/ListTables/KeysTable.php:244 +#: src/Admin/ListTables/KeysTable.php:211 #: src/Admin/ListTables/StockTable.php:92 msgid "Filter" msgstr "" #: src/Admin/ListTables/ActivationsTable.php:177 #: src/Admin/ListTables/ActivationsTable.php:252 -#: src/Admin/ListTables/KeysTable.php:301 -#: src/Admin/ListTables/KeysTable.php:392 +#: src/Admin/ListTables/KeysTable.php:268 +#: src/Admin/ListTables/KeysTable.php:359 msgid "Delete" msgstr "" @@ -341,7 +342,7 @@ msgid "Instance" msgstr "" #: src/Admin/ListTables/ActivationsTable.php:190 -#: src/Admin/ListTables/KeysTable.php:315 +#: src/Admin/ListTables/KeysTable.php:282 #: src/Admin/ListTables/StockTable.php:105 #: src/Admin/Views/html-api-actions.php:118 #: src/Admin/Views/html-api-validation.php:121 @@ -351,7 +352,7 @@ msgid "Product" msgstr "" #: src/Admin/ListTables/ActivationsTable.php:191 -#: src/Admin/ListTables/KeysTable.php:314 +#: src/Admin/ListTables/KeysTable.php:281 #: src/Admin/Views/html-api-actions.php:131 #: src/Admin/Views/html-api-validation.php:134 src/Functions/Template.php:42 msgid "Key" @@ -382,124 +383,93 @@ msgstr "" msgid "Add new key" msgstr "" -#: src/Admin/ListTables/KeysTable.php:174 -msgid "Keys can have one of the following statuses:" +#: src/Admin/ListTables/KeysTable.php:189 +msgid "All keys." +msgstr "" + +#: src/Admin/ListTables/KeysTable.php:189 +msgid "All" msgstr "" -#: src/Admin/ListTables/KeysTable.php:178 -#: src/Admin/ListTables/KeysTable.php:223 src/functions.php:46 +#: src/Admin/ListTables/KeysTable.php:190 +msgid "Available for sell." +msgstr "" + +#: src/Admin/ListTables/KeysTable.php:190 src/functions.php:46 msgid "Available" msgstr "" -#: src/Admin/ListTables/KeysTable.php:180 -msgid "This means the key is available for purchase." +#: src/Admin/ListTables/KeysTable.php:191 +msgid "Pending payment." msgstr "" -#: src/Admin/ListTables/KeysTable.php:183 -#: src/Admin/ListTables/KeysTable.php:224 src/functions.php:47 +#: src/Admin/ListTables/KeysTable.php:191 src/functions.php:47 msgid "Pending" msgstr "" -#: src/Admin/ListTables/KeysTable.php:185 -msgid "This means the key has been sold, but the order has not been completed yet." +#: src/Admin/ListTables/KeysTable.php:192 +msgid "Sold keys." msgstr "" -#: src/Admin/ListTables/KeysTable.php:188 -#: src/Admin/ListTables/KeysTable.php:225 +#: src/Admin/ListTables/KeysTable.php:192 #: src/Admin/ListTables/StockTable.php:107 src/functions.php:48 msgid "Sold" msgstr "" -#: src/Admin/ListTables/KeysTable.php:190 -msgid "This means the key has been sold, and the order has been completed." +#: src/Admin/ListTables/KeysTable.php:193 +msgid "Expired keys." msgstr "" -#: src/Admin/ListTables/KeysTable.php:193 -#: src/Admin/ListTables/KeysTable.php:226 src/Functions/Template.php:72 +#: src/Admin/ListTables/KeysTable.php:193 src/Functions/Template.php:72 #: src/functions.php:49 msgid "Expired" msgstr "" -#: src/Admin/ListTables/KeysTable.php:195 -msgid "This means the key has expired and is no longer valid." +#: src/Admin/ListTables/KeysTable.php:194 +msgid "Cancelled keys." msgstr "" -#: src/Admin/ListTables/KeysTable.php:198 -#: src/Admin/ListTables/KeysTable.php:227 src/functions.php:50 +#: src/Admin/ListTables/KeysTable.php:194 src/functions.php:50 msgid "Cancelled" msgstr "" -#: src/Admin/ListTables/KeysTable.php:200 -msgid "" -"This means the key has been cancelled and is no longer available for " -"purchase or use." -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:222 -msgid "All keys." -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:222 -msgid "All" -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:223 -msgid "Available for sell." -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:224 -msgid "Pending payment." -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:225 -msgid "Sold keys." -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:226 -msgid "Expired keys." -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:227 -msgid "Cancelled keys." -msgstr "" - -#: src/Admin/ListTables/KeysTable.php:302 +#: src/Admin/ListTables/KeysTable.php:269 msgid "Reset Activations" msgstr "" -#: src/Admin/ListTables/KeysTable.php:316 +#: src/Admin/ListTables/KeysTable.php:283 msgid "Order" msgstr "" -#: src/Admin/ListTables/KeysTable.php:317 +#: src/Admin/ListTables/KeysTable.php:284 msgid "Validity" msgstr "" -#: src/Admin/ListTables/KeysTable.php:324 +#: src/Admin/ListTables/KeysTable.php:291 msgid "Order Date" msgstr "" -#: src/Admin/ListTables/KeysTable.php:325 src/Admin/Menus.php:322 -#: src/Admin/Views/html-edit-key.php:113 src/Functions/Template.php:78 +#: src/Admin/ListTables/KeysTable.php:292 src/Admin/Menus.php:322 +#: src/Admin/Views/html-edit-key.php:114 src/Functions/Template.php:78 msgid "Status" msgstr "" -#: src/Admin/ListTables/KeysTable.php:390 +#: src/Admin/ListTables/KeysTable.php:357 msgid "ID: %d" msgstr "" -#: src/Admin/ListTables/KeysTable.php:391 +#: src/Admin/ListTables/KeysTable.php:358 #: src/Admin/ListTables/StockTable.php:153 src/Admin/Metaboxes.php:361 msgid "Edit" msgstr "" -#: src/Admin/ListTables/KeysTable.php:482 +#: src/Admin/ListTables/KeysTable.php:449 msgid "%s Day
After purchase" msgid_plural "%s Days
After purchase" msgstr[0] "" msgstr[1] "" -#: src/Admin/ListTables/KeysTable.php:482 src/Admin/Metaboxes.php:348 +#: src/Admin/ListTables/KeysTable.php:449 src/Admin/Metaboxes.php:348 #: src/Functions/Template.php:63 msgid "Lifetime" msgstr "" @@ -565,6 +535,11 @@ msgstr "" msgid "Reports" msgstr "" +#: src/Admin/Menus.php:200 src/Admin/Metaboxes.php:137 +#: src/Admin/Metaboxes.php:156 +msgid "Upgrade to Pro" +msgstr "" + #: src/Admin/Menus.php:247 src/Admin/Views/html-list-keys.php:25 msgid "Import" msgstr "" @@ -667,16 +642,14 @@ msgstr[1] "" #: src/Admin/Metaboxes.php:137 msgid "" -"Want serial numbers to be generated automatically and auto assign with " -"order and many more?" -msgstr "" - -#: src/Admin/Metaboxes.php:137 src/Admin/Metaboxes.php:156 -msgid "Upgrade to Pro" +"Want serial keys to be generated automatically and auto assign with order " +"and many more?" msgstr "" #: src/Admin/Metaboxes.php:156 -msgid "The free version of Serial Numbers for WooCommerce does not support product variation." +msgid "" +"The free version of Serial Numbers for WooCommerce does not support product " +"variation." msgstr "" #: src/Admin/Metaboxes.php:226 @@ -709,8 +682,9 @@ msgstr "" #: src/Admin/Notices.php:65 #. translators: %1$s: link to the plugin page, %2$s: link to the plugin page msgid "" -"Upgrade to %6$s to unlock the full potential of %5$s and avail a %1$s " -"discount by using the promo code %2$s %3$s Upgrade Now %4$s." +"New! Send Serial Keys via SMS with Twilio. Upgrade to %6$s to unlock the " +"full potential of %5$s and avail a %1$s discount by using the promo code " +"%2$s %3$s Upgrade Now %4$s." msgstr "" #: src/Admin/Orders.php:43 src/Admin/Orders.php:122 @@ -751,11 +725,11 @@ msgid "General Settings" msgstr "" #: src/Admin/Settings.php:48 -msgid "The following options affect how the serial keys will work." +msgid "These options determine the behavior and operation of the serial keys." msgstr "" #: src/Admin/Settings.php:52 -msgid "Auto-complete order" +msgid "Auto-complete orders" msgstr "" #: src/Admin/Settings.php:54 @@ -806,101 +780,111 @@ msgstr "" msgid "Disable Software Licensing support & API functionalities." msgstr "" -#: src/Admin/Settings.php:94 +#: src/Admin/Settings.php:86 +msgid "" +"If you enable this option, the activation menu and it’s functionality will " +"be turned off." +msgstr "" + +#: src/Admin/Settings.php:95 msgid "Stock Notification" msgstr "" -#: src/Admin/Settings.php:96 -msgid "The following options affect how the stock notification will work." +#: src/Admin/Settings.php:97 +msgid "These options determine the operation of the serial key stock notification." msgstr "" -#: src/Admin/Settings.php:100 +#: src/Admin/Settings.php:101 msgid "Stock notification email" msgstr "" -#: src/Admin/Settings.php:102 +#: src/Admin/Settings.php:103 msgid "Sends notification emails when product stock is low." msgstr "" -#: src/Admin/Settings.php:108 +#: src/Admin/Settings.php:109 msgid "Stock threshold" msgstr "" -#: src/Admin/Settings.php:110 +#: src/Admin/Settings.php:111 msgid "" -"When the stock goes below the above number, it will send a notification " -"email." +"An email notification will be sent when the stock falls below the specified " +"number." msgstr "" -#: src/Admin/Settings.php:115 +#: src/Admin/Settings.php:116 msgid "Notification recipient email" msgstr "" -#: src/Admin/Settings.php:117 -msgid "The email address to be used for sending the email notifications." +#: src/Admin/Settings.php:118 +msgid "The email address which will be used to send email notifications." msgstr "" -#: src/Admin/Settings.php:151 +#: src/Admin/Settings.php:152 msgid "Create and assign license keys for WooCommerce variable products." msgstr "" -#: src/Admin/Settings.php:152 +#: src/Admin/Settings.php:153 msgid "Generate bulk license keys with your custom key generator rule." msgstr "" -#: src/Admin/Settings.php:153 -msgid "Random & sequential order for the generator rules." +#: src/Admin/Settings.php:154 +msgid "Random & sequential key order for the generator rules." msgstr "" -#: src/Admin/Settings.php:154 +#: src/Admin/Settings.php:155 msgid "Automatic license key generator to auto-create & assign keys with orders." msgstr "" -#: src/Admin/Settings.php:155 +#: src/Admin/Settings.php:156 msgid "License key management option from the order page with required actions." msgstr "" -#: src/Admin/Settings.php:156 +#: src/Admin/Settings.php:157 msgid "Support for bulk import/export of license keys from/to CSV." msgstr "" -#: src/Admin/Settings.php:157 +#: src/Admin/Settings.php:158 +msgid "Send Serial Keys via SMS with Twilio." +msgstr "" + +#: src/Admin/Settings.php:159 msgid "" "Option to sell license keys even if there are no available keys in the " "stock." msgstr "" -#: src/Admin/Settings.php:158 +#: src/Admin/Settings.php:160 msgid "Custom deliverable quantity to deliver multiple keys with a single product." msgstr "" -#: src/Admin/Settings.php:159 +#: src/Admin/Settings.php:161 msgid "" "Manual delivery option to manually deliver license keys instead of " "automatic." msgstr "" -#: src/Admin/Settings.php:160 +#: src/Admin/Settings.php:162 msgid "" "Email Template to easily and quickly customize the order confirmation & low " "stock alert email." msgstr "" -#: src/Admin/Settings.php:161 +#: src/Admin/Settings.php:163 msgid "Many more ..." msgstr "" -#: src/Admin/Settings.php:165 +#: src/Admin/Settings.php:167 msgid "Want More?" msgstr "" -#: src/Admin/Settings.php:166 +#: src/Admin/Settings.php:168 msgid "" "This plugin offers a premium version which comes with the following " "features:" msgstr "" -#: src/Admin/Settings.php:172 +#: src/Admin/Settings.php:174 msgid "Upgrade to PRO" msgstr "" @@ -910,8 +894,8 @@ msgstr "" #: src/Admin/Views/html-api-actions.php:26 msgid "" -"You can use the API to perform actions on serial key. You can use the API " -"to perform actions on your website or on another website." +"You can use the API to perform actions on your website or on another " +"website." msgstr "" #: src/Admin/Views/html-api-actions.php:29 @@ -955,8 +939,8 @@ msgstr "" #: src/Admin/Views/html-api-actions.php:52 #: src/Admin/Views/html-api-validation.php:59 msgid "" -"Optional. If email is provided, the API will check if the serial key is " -"assigned to the provided email address." +"Using email is completely voluntary. The API will verify that the serial " +"number is associated with the given email address." msgstr "" #: src/Admin/Views/html-api-actions.php:57 @@ -1094,7 +1078,7 @@ msgstr "" #: src/Admin/Views/html-api-actions.php:185 #: src/Admin/Views/html-api-validation.php:153 -msgid "API Response" +msgid "API response" msgstr "" #: src/Admin/Views/html-api-actions.php:195 src/Shortcodes.php:146 @@ -1107,6 +1091,7 @@ msgid "API Validation" msgstr "" #: src/Admin/Views/html-api-validation.php:30 +#: src/Admin/Views/html-edit-key.php:33 #. translators: %s: link to the pro version msgid "" "You are using the free version of Serial Numbers for WooCommerce. Upgrade to Pro to get more features." -msgstr "" - #: src/Admin/Views/html-edit-key.php:50 msgid "Select Product" msgstr "" #: src/Admin/Views/html-edit-key.php:60 -msgid "Select the product for which this key is valid." +msgid "Select the product for which this key is applicable." msgstr "" -#: src/Admin/Views/html-edit-key.php:67 src/Shortcodes.php:41 -#: src/Shortcodes.php:137 -msgid "Serial Key" +#: src/Admin/Views/html-edit-key.php:67 +msgid "Serial key" msgstr "" #: src/Admin/Views/html-edit-key.php:74 msgid "" -"Enter secret number, supports multiline. E.g., " +"Enter your serial key, also supports multiline. For example: " "4CE0460D0G-4CE0460D1G-4CE0460D2G" msgstr "" @@ -1213,37 +1190,37 @@ msgid "" "the product is not software, keep it blank." msgstr "" -#: src/Admin/Views/html-edit-key.php:97 +#: src/Admin/Views/html-edit-key.php:98 msgid "Valid for (days)" msgstr "" -#: src/Admin/Views/html-edit-key.php:103 +#: src/Admin/Views/html-edit-key.php:104 msgid "" -"Number of days the key will be valid from the purchase date. Leave blank " +"Number of days the key will be valid from the purchase date. Leave it blank " "for lifetime validity." msgstr "" -#: src/Admin/Views/html-edit-key.php:122 +#: src/Admin/Views/html-edit-key.php:123 msgid "Status of the serial key." msgstr "" -#: src/Admin/Views/html-edit-key.php:129 +#: src/Admin/Views/html-edit-key.php:130 msgid "Order ID" msgstr "" -#: src/Admin/Views/html-edit-key.php:133 +#: src/Admin/Views/html-edit-key.php:134 msgid "Select Order" msgstr "" -#: src/Admin/Views/html-edit-key.php:141 +#: src/Admin/Views/html-edit-key.php:142 msgid "The order to which the serial number will be assigned." msgstr "" -#: src/Admin/Views/html-edit-key.php:152 +#: src/Admin/Views/html-edit-key.php:153 msgid "Update" msgstr "" -#: src/Admin/Views/html-edit-key.php:152 +#: src/Admin/Views/html-edit-key.php:153 msgid "Create" msgstr "" @@ -1318,27 +1295,27 @@ msgstr "" msgid "%1$s updated to version %2$s successfully." msgstr "" -#: src/Models/Activation.php:228 +#: src/Models/Activation.php:244 msgid "Serial id is required." msgstr "" -#: src/Models/Activation.php:233 +#: src/Models/Activation.php:249 msgid "Instance is required." msgstr "" -#: src/Models/Key.php:469 +#: src/Models/Key.php:486 msgid "Product id is required." msgstr "" -#: src/Models/Key.php:474 +#: src/Models/Key.php:491 msgid "Product id is invalid." msgstr "" -#: src/Models/Key.php:491 +#: src/Models/Key.php:508 msgid "Serial key already exists. Duplicate serial keys are not allowed." msgstr "" -#: src/Models/Key.php:497 +#: src/Models/Key.php:514 msgid "Order id is invalid." msgstr "" @@ -1393,6 +1370,10 @@ msgstr "" msgid "Serial Key Validation" msgstr "" +#: src/Shortcodes.php:41 src/Shortcodes.php:137 +msgid "Serial Key" +msgstr "" + #: src/Shortcodes.php:42 src/Shortcodes.php:138 msgid "Enter your serial key" msgstr "" @@ -1427,7 +1408,7 @@ msgid "Could not find any products with serial numbers enabled." msgstr "" #: src/functions.php:91 -msgid "Manually Added" +msgid "Manually added" msgstr "" #: src/functions.php:511 @@ -1685,8 +1666,8 @@ msgstr "" #. Description of the plugin/theme msgid "" -"The best WooCommerce extension to sell license & serial keys, gift cards " -"and other secret numbers!" +"Sell and manage license keys/ serial numbers/ secrect keys easily within " +"your WooCommerce store." msgstr "" #. Author of the plugin/theme diff --git a/package-lock.json b/package-lock.json index 591900f9..bd033de7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wc-serial-numbers", - "version": "1.5.3", + "version": "1.5.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "wc-serial-numbers", - "version": "1.5.3", + "version": "1.5.4", "license": "GPL-3.0+", "devDependencies": { "@lodder/time-grunt": "^4.0.0", diff --git a/src/Admin/ListTables/GeneratorsTable.php b/src/Admin/ListTables/GeneratorsTable.php new file mode 100644 index 00000000..98a02ef7 --- /dev/null +++ b/src/Admin/ListTables/GeneratorsTable.php @@ -0,0 +1,265 @@ + __( 'generator', 'wc-serial-numbers-pro' ), + 'plural' => __( 'generators', 'wc-serial-numbers-pro' ), + 'ajax' => false, + ) + ); + } + + /** + * Prepare table data. + * + * @since 1.4.6 + */ + public function prepare_items() { + $per_page = $this->get_items_per_page( 'wcsn_stocks_per_page' ); + $columns = $this->get_columns(); + $hidden = []; + $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( $_GET['s'] ) : null; + $product_id = isset( $_GET['product_id'] ) ? absint( $_GET['product_id'] ) : ''; + + $args = array( + 'per_page' => $per_page, + 'paged' => $current_page, + 'orderby' => $orderby, + 'order' => $order, + 'product_id' => $product_id, + 'search' => $search, + ); + + $query = new \WP_Query( $args ); + $this->items = wcsn_get_generators( $args ); + $this->total_count = wcsn_get_generators( array_merge( $args, array( 'count' => true ) ) ); + + $this->set_pagination_args( + array( + 'total_items' => $query->found_posts, + 'per_page' => $per_page, + 'total_pages' => $query->found_posts > 0 ? ceil( $query->found_posts / $per_page ) : 0, + ) + ); + } + + /** + * No items found text. + */ + public function no_items() { + esc_html_e( 'No generators found.', 'wc-serial-numbers-pro' ); + } + + /** + * Process bulk action. + * + * @param string $doaction Action name. + * + * @since 1.4.6 + */ + public function process_bulk_actions( $doaction ) { + if ( $doaction ) { + if ( isset( $_REQUEST['id'] ) ) { + $ids = wp_parse_id_list( $_REQUEST['id'] ); + $doaction = ( - 1 !== $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2']; // phpcs:ignore + } elseif ( isset( $_REQUEST['ids'] ) ) { + $ids = array_map( 'absint', $_REQUEST['ids'] ); + } elseif ( wp_get_referer() ) { + wp_safe_redirect( wp_get_referer() ); + exit; + } + + foreach ( $ids as $id ) { // Check the permissions on each. + $key = Generator::get( $id ); + if ( ! $key ) { + continue; + } + switch ( $doaction ) { + case 'delete': + $key->delete(); + break; + } + } + + wp_safe_redirect( wp_get_referer() ); + exit; + } + + parent::process_bulk_actions( $doaction ); + } + + /** + * Get bulk actions + * + * since 1.0.0 + * + * @return array + */ + public function get_bulk_actions() { + return array( + 'delete' => __( 'Delete', 'wc-serial-numbers-pro' ), + ); + } + + /** + * since 1.0.0 + * + * @return array + */ + public function get_columns() { + $columns = array( + 'cb' => '', + 'pattern' => __( 'Pattern', 'wc-serial-numbers-pro' ), + 'product' => __( 'Product', 'wc-serial-numbers-pro' ), + 'type' => __( 'Type', 'wc-serial-numbers-pro' ), + 'activation_limit' => __( 'Activation Limit', 'wc-serial-numbers-pro' ), + 'validity' => __( 'Validity', 'wc-serial-numbers-pro' ), + 'generate' => __( 'Generate', 'wc-serial-numbers-pro' ), + ); + + return apply_filters( 'wc_serial_numbers_stock_table_columns', $columns ); + } + + /** + * since 1.0.0 + * + * @return array + */ + function get_sortable_columns() { + return array( + 'product' => array( 'product_id', false ), + ); + } + + /** + * Gets the name of the primary column. + * + * @since 1.0.0 + * @access protected + * @return string Name of the primary column. + */ + protected function get_primary_column_name() { + return 'column_pattern'; + } + + /** + * Render the bulk edit checkbox + * + * @param Generator $item The item being acted upon. + * + * @return string + */ + protected function column_cb( $item ) { + return ""; + } + + /** + * column pattern + * + * @param $item + * + * @return string + * @since 1.0.0 + */ + function column_pattern( $item ) { + $row_actions = array(); + $base_url = admin_url( 'admin.php?page=wc-serial-numbers-tools&tab=generators' ); + $edit_url = add_query_arg( [ 'edit' => $item->get_id() ], $base_url ); + $delete_url = add_query_arg( + [ + 'action' => 'delete', + 'id' => $item->get_id(), + ], + $base_url + ); + $row_actions['edit'] = sprintf( '%2$s', $edit_url, __( 'Edit', 'wc-serial-numbers-pro' ) ); + $row_actions['delete'] = sprintf( '%2$s', $delete_url, __( 'Delete', 'wc-serial-numbers-pro' ) ); + $pattern = get_post_meta( $item->ID, 'pattern', true ); + + return sprintf( '%1$s %2$s', $pattern, $this->row_actions( $row_actions ) ); + } + + /** + * column generate + * + * @param $item + * + * @since 1.0.0 + */ + public function column_generate( $item ) { + ?> + + 'generate-serials', + 'data-id' => $item->get_id(), + 'data-nonce' => wp_create_nonce( 'generate_serials' ), + ) + ); + ?> + +
+ ID, 'product_id', true ); + $line = ! empty( $product_id ) ? get_the_title( $product_id ) : '-'; + echo ! empty( $product_id ) ? '' . $line . '' : $line; + break; + case 'type': + $type = get_post_meta( $item->ID, 'type', true ); + echo empty( $item->get_ ) ? '-' : ucfirst( $type ); + break; + case 'activation_limit': + $activation_limit = get_post_meta( $item->ID, 'activation_limit', true ); + echo empty( $activation_limit ) ? __( 'Unlimited', 'wc-serial-numbers-pro' ) : $activation_limit; + break; + case 'validity': + $validity = get_post_meta( $item->ID, 'validity', true ); + echo empty( $validity ) ? __( 'Lifetime', 'wc-serial-numbers-pro' ) : $validity; + break; + default: + return ''; + } + + return ''; + } +} diff --git a/src/Admin/ListTables/KeysTable.php b/src/Admin/ListTables/KeysTable.php index bd770a75..afd37385 100644 --- a/src/Admin/ListTables/KeysTable.php +++ b/src/Admin/ListTables/KeysTable.php @@ -168,39 +168,6 @@ public function prepare_items() { */ public function no_items() { echo sprintf( '%s %s', esc_html__( 'No keys found.', 'wc-serial-numbers' ), '' . esc_html__( 'Add new key', 'wc-serial-numbers' ) . '' ); - // Show a documentation about key's statuses. - ?> -

- -

- - id}' value='{$item->id}' />"; + return ""; } /** @@ -397,7 +364,7 @@ protected function column_key( $item ) { /** * Display column product. * - * @param Key $key Key object. + * @param Key $item Key object. * * @since 1.4.6 */ @@ -410,7 +377,7 @@ protected function column_product( $item ) { /** * Display column order. * - * @param Key $key Key object. + * @param Key $item Key object. * * @since 1.4.6 */ diff --git a/src/Admin/Menus.php b/src/Admin/Menus.php index 81d1bb0e..881316fe 100644 --- a/src/Admin/Menus.php +++ b/src/Admin/Menus.php @@ -2,6 +2,7 @@ namespace WooCommerceSerialNumbers\Admin; +use WooCommerceSerialNumbers\Models\Generator; use WooCommerceSerialNumbers\Models\Key; use WooCommerceSerialNumbers\Lib\Singleton; @@ -374,15 +375,17 @@ public static function export_tab() { * @return void */ public static function generators_tab() { - ?> -
-
-

- -
- <?php esc_attr_e( 'Generators', 'wc-serial-numbers' ); ?> -
- exists() ) { + wp_safe_redirect( remove_query_arg( 'edit' ) ); + exit(); + } + Admin::view( 'html-edit-generator.php', array( 'generator' => $generator ) ); + } else { + Admin::view( 'html-list-generators.php' ); + } } /** diff --git a/src/Admin/Metaboxes.php b/src/Admin/Metaboxes.php index 2d83c9b8..53072b74 100644 --- a/src/Admin/Metaboxes.php +++ b/src/Admin/Metaboxes.php @@ -19,10 +19,6 @@ class Metaboxes extends \WooCommerceSerialNumbers\Lib\Singleton { */ protected function __construct() { add_action( 'add_meta_boxes', array( __CLASS__, 'register_metaboxes' ) ); - add_filter( 'woocommerce_product_data_tabs', array( __CLASS__, 'product_data_tab' ) ); - add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'product_write_panel' ) ); - add_filter( 'woocommerce_process_product_meta', array( __CLASS__, 'product_save_data' ) ); - add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'variable_product_content' ), 10, 3 ); // add_action( 'woocommerce_after_order_itemmeta', array( $this, 'order_itemmeta' ), 10, 3 ); } @@ -36,144 +32,6 @@ public static function register_metaboxes() { add_meta_box( 'order-serial-numbers', __( 'Serial Numbers', 'wc-serial-numbers' ), array( __CLASS__, 'order_metabox' ), 'shop_order', 'advanced', 'high' ); } - /** - * product - * since 1.0.0 - */ - public static function product_data_tab( $tabs ) { - $tabs['wc_serial_numbers'] = array( - 'label' => __( 'Serial Numbers', 'wc-serial-numbers' ), - 'target' => 'wc_serial_numbers_data', - 'class' => array( 'show_if_simple' ), - 'priority' => 11, - ); - - return $tabs; - } - - /** - * since 1.0.0 - */ - public static function product_write_panel() { - global $post, $woocommerce; - ?> - - is_pro_active() ) { - echo sprintf( '

%s %s

', __( 'The free version of Serial Numbers for WooCommerce does not support product variation.', 'wc-serial-numbers' ), 'https://www.pluginever.com/plugins/woocommerce-serial-numbers-pro/?utm_source=product_page_license_area&utm_medium=link&utm_campaign=wc-serial-numbers&utm_content=Upgrade%20to%20Pro', __( 'Upgrade to Pro', 'wc-serial-numbers' ) ); - } - - } - - /** - * since 1.0.0 - */ - public static function product_save_data() { - global $post; - $status = isset( $_POST['_is_serial_number'] ) ? 'yes' : 'no'; - $source = isset( $_POST['_serial_key_source'] ) ? sanitize_text_field( $_POST['_serial_key_source'] ) : 'custom_source'; - update_post_meta( $post->ID, '_is_serial_number', $status ); - update_post_meta( $post->ID, '_serial_key_source', $source ); - // save only if software licensing enabled - if ( ! wc_serial_numbers_software_support_disabled() ) { - update_post_meta( $post->ID, '_software_version', ! empty( $_POST['_software_version'] ) ? sanitize_text_field( $_POST['_software_version'] ) : '' ); - } - - do_action( 'wcsn_save_simple_product_meta', $post ); - } /** diff --git a/src/Admin/Products.php b/src/Admin/Products.php index ab1740c2..6986e55a 100644 --- a/src/Admin/Products.php +++ b/src/Admin/Products.php @@ -18,9 +18,162 @@ class Products extends \WooCommerceSerialNumbers\Lib\Singleton { * @since 1.0.0 */ protected function __construct() { + add_filter( 'woocommerce_product_data_tabs', array( __CLASS__, 'product_data_tab' ) ); + add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'product_write_panel' ) ); + add_filter( 'woocommerce_process_product_meta', array( __CLASS__, 'product_save_data' ) ); + add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'variable_product_content' ), 10, 3 ); add_action( 'admin_head', array( __CLASS__, 'print_style' ) ); } + /** + * Add product data tab. + * + * @param array $tabs product tabs. + * + * since 1.0.0 + */ + public static function product_data_tab( $tabs ) { + $tabs['wc_serial_numbers'] = array( + 'label' => __( 'Serial Numbers', 'wc-serial-numbers' ), + 'target' => 'wc_serial_numbers_data', + 'class' => array( 'show_if_simple' ), + 'priority' => 11, + ); + + return $tabs; + } + + /** + * since 1.0.0 + */ + public static function product_write_panel() { + global $post, $woocommerce; + include 'Views/html-product-options.php'; + } + + /** + * since 1.0.0 + */ + public static function product_write_panel_bk() { + global $post, $woocommerce; + ?> + + is_premium_active() ) { + echo sprintf( '

%s %s

', __( 'The free version of Serial Numbers for WooCommerce does not support product variation.', 'wc-serial-numbers' ), 'https://www.pluginever.com/plugins/woocommerce-serial-numbers-pro/?utm_source=product_page_license_area&utm_medium=link&utm_campaign=wc-serial-numbers&utm_content=Upgrade%20to%20Pro', __( 'Upgrade to Pro', 'wc-serial-numbers' ) ); + } + + } + + /** + * since 1.0.0 + */ + public static function product_save_data() { + global $post; + $status = isset( $_POST['_is_serial_number'] ) ? 'yes' : 'no'; + $source = isset( $_POST['_serial_key_source'] ) ? sanitize_text_field( $_POST['_serial_key_source'] ) : 'custom_source'; + update_post_meta( $post->ID, '_is_serial_number', $status ); + update_post_meta( $post->ID, '_serial_key_source', $source ); + // save only if software licensing enabled + if ( ! wc_serial_numbers_software_support_disabled() ) { + update_post_meta( $post->ID, '_software_version', ! empty( $_POST['_software_version'] ) ? sanitize_text_field( $_POST['_software_version'] ) : '' ); + } + + do_action( 'wcsn_save_simple_product_meta', $post ); + } + /** * Print style * diff --git a/src/Admin/Views/edit-generator.php b/src/Admin/Views/edit-generator.php new file mode 100644 index 00000000..5f42032a --- /dev/null +++ b/src/Admin/Views/edit-generator.php @@ -0,0 +1,13 @@ + diff --git a/src/Admin/Views/html-list-generators.php b/src/Admin/Views/html-list-generators.php new file mode 100644 index 00000000..b03a1dc1 --- /dev/null +++ b/src/Admin/Views/html-list-generators.php @@ -0,0 +1,30 @@ +current_action(); +$list_table->process_bulk_actions( $action ); +?> + +

+ + + + +

+
+ prepare_items(); + $list_table->display(); + ?> + + +
+ diff --git a/src/Admin/Views/html-product-options.php b/src/Admin/Views/html-product-options.php new file mode 100644 index 00000000..aaadc84a --- /dev/null +++ b/src/Admin/Views/html-product-options.php @@ -0,0 +1,144 @@ +ID; + +?> + diff --git a/src/Installer.php b/src/Installer.php index 4ab0e155..9199cb23 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -168,6 +168,26 @@ public static function create_tables() { PRIMARY KEY (id), key serial_id (serial_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", + + "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wcsn_generators( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(191) NOT NULL, + `pattern` varchar(191) NOT NULL, + `charset` varchar(191) NOT NULL DEFAULT '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + `length` int(11) NOT NULL DEFAULT '32', + `text_case` varchar(20) NOT NULL DEFAULT 'lowercase', + `is_sequential` tinyint(1) NOT NULL DEFAULT '0', + `activation_limit` int(11) NOT NULL, + `validity` int(11) NOT NULL, + `date_created` DATETIME NULL DEFAULT NULL, + PRIMARY KEY (id), + KEY `name` (`name`), + KEY `pattern` (`pattern`), + KEY `activation_limit` (`activation_limit`), + KEY `validity` (`validity`), + KEY `is_sequential` (`is_sequential`), + KEY `text_case` (`text_case`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8", ]; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; diff --git a/src/Models/Activation.php b/src/Models/Activation.php index 7ef5ab1f..8b3fbcd6 100644 --- a/src/Models/Activation.php +++ b/src/Models/Activation.php @@ -19,7 +19,7 @@ class Activation extends Model { * @since 1.0.0 * @var string */ - const TABLE_NAME = 'serial_numbers_activations'; + protected $table_name = 'serial_numbers_activations'; /** * Object type. @@ -27,15 +27,7 @@ class Activation extends Model { * @since 1.0.0 * @var string */ - const OBJECT_TYPE = 'activation'; - - /** - * Cache group. - * - * @since 1.0.0 - * @var string - */ - const CACHE_GROUP = 'serial_numbers_activations'; + protected $object_type = 'activation'; /** * Core data for this object. Name value pairs (name + default value). @@ -44,6 +36,7 @@ class Activation extends Model { * @var array */ protected $core_data = array( + 'id' => 0, 'serial_id' => '', 'instance' => '', 'platform' => '', @@ -59,6 +52,29 @@ class Activation extends Model { | Methods for getting and setting data. | */ + /** + * Get the key. + * + * @since 1.4.6 + * + * @return string + */ + public function get_id() { + return $this->get_prop( 'id' ); + } + + /** + * Set the key. + * + * @param string $id Key. + * + * @since 1.4.6 + * + * @return void + */ + public function set_id( $id ) { + $this->set_prop( 'id', absint( $id ) ); + } /** * Get the serial id * diff --git a/src/Models/Generator.php b/src/Models/Generator.php new file mode 100644 index 00000000..ec21b514 --- /dev/null +++ b/src/Models/Generator.php @@ -0,0 +1,381 @@ + null, + 'name' => '', + 'pattern' => '', + 'charset' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', + 'length' => 32, + 'text_case' => 'lowercase', + 'is_sequential' => 0, + 'activation_limit' => 0, + 'validity' => 0, + 'date_created' => null, + ); + + /* + |-------------------------------------------------------------------------- + | CRUD methods + |-------------------------------------------------------------------------- + | + | Methods which create, read, update and delete documents from the database. + | Written in abstract fashion so that the way documents are stored can be + | changed more easily in the future. + | + | A save method is included for convenience (chooses update or create based + | on if the order exists yet). + | + */ + /** + * Saves an object in the database. + * + * @return true|\WP_Error True on success, WP_Error on failure. + * @since 1.0.0 + */ + public function save() { + if ( empty( $this->get_name() ) ) { + return new \WP_Error( 'missing_required', __( 'Name is required.', 'wc-serial-numbers-pro' ) ); + } + if ( empty( $this->get_pattern() ) ) { + return new \WP_Error( 'missing_required', __( 'Pattern is required.', 'wc-serial-numbers-pro' ) ); + } + + if ( empty( $this->get_date_created() ) ) { + $this->set_date_created( current_time( 'mysql' ) ); + } + + return parent::save(); + } + + /* + |-------------------------------------------------------------------------- + | Getters and Setters + |-------------------------------------------------------------------------- + | + | Methods for getting and setting data. + | + */ + /** + * Get id. + * + * @return int + * @since 1.0.0 + */ + public function get_id() { + return (int) $this->get_prop( 'id' ); + } + + /** + * Set id. + * + * @param int $id Id. + * + * @since 1.0.0 + */ + public function set_id( $id ) { + $this->set_prop( 'id', absint( $id ) ); + } + /** + * Get the name. + * + * @return string + * @since 1.0.0 + */ + public function get_name() { + return $this->get_prop( 'name' ); + } + + /** + * Set the name. + * + * @param string $name Name. + * + * @since 1.0.0 + */ + public function set_name( $name ) { + $this->set_prop( 'name', $name ); + } + + /** + * Get the pattern. + * + * @return string + * @since 1.0.0 + */ + public function get_pattern() { + return $this->get_prop( 'pattern' ); + } + + /** + * Set the pattern. + * + * @param string $pattern Pattern. + * + * @since 1.0.0 + */ + public function set_pattern( $pattern ) { + $this->set_prop( 'pattern', $pattern ); + } + + /** + * Get the product id. + * + * @param string $context What the value is for. Valid values are 'view' and 'edit'. + * + * @return int + * @since 1.0.0 + */ + public function get_product_id( $context = 'edit' ) { + return $this->get_prop( 'product_id', $context ); + } + + /** + * Set the product id. + * + * @param int $product_id Product id. + * + * @return void + * @since 1.0.0 + */ + public function set_product_id( $product_id ) { + $this->set_prop( 'product_id', absint( $product_id ) ); + } + + /** + * Get the charset. + * + * @return string + * @since 1.0.0 + */ + public function get_charset() { + return $this->get_prop( 'charset' ); + } + + /** + * Set the charset. + * + * @param string $charset Charset. + * + * @since 1.0.0 + */ + public function set_charset( $charset ) { + $this->set_prop( 'charset', sanitize_text_field( $charset ) ); + } + + /** + * Get the length. + * + * @return int + * @since 1.0.0 + */ + public function get_length() { + return $this->get_prop( 'length' ); + } + + /** + * Set the length. + * + * @param int $length Length. + * + * @since 1.0.0 + */ + public function set_length( $length ) { + $this->set_prop( 'length', absint( $length ) ); + } + + /** + * Get the text case. + * + * @return string + * @since 1.0.0 + */ + public function get_text_case() { + return $this->get_prop( 'text_case' ); + } + + /** + * Set the text case. + * + * @param string $text_case Text case. + * + * @since 1.0.0 + */ + public function set_text_case( $text_case ) { + $cases = array( 'lowercase', 'uppercase', 'mixed' ); + if ( ! in_array( $text_case, $cases, true ) ) { + $text_case = 'lowercase'; + } + $this->set_prop( 'text_case', $text_case ); + } + + /** + * Get the is sequential. + * + * @return int + * @since 1.0.0 + */ + public function get_is_sequential() { + return $this->get_prop( 'is_sequential' ); + } + + /** + * Set the is sequential. + * + * @param int $is_sequential Is sequential. + * + * @since 1.0.0 + */ + public function set_is_sequential( $is_sequential ) { + $this->set_prop( 'is_sequential', $this->string_to_int( $is_sequential ) ); + } + + /** + * Get the activation limit. + * + * @return int + * @since 1.0.0 + */ + public function get_activation_limit() { + return $this->get_prop( 'activation_limit' ); + } + + /** + * Set the activation limit. + * + * @param int $activation_limit Activation limit. + * + * @since 1.0.0 + */ + public function set_activation_limit( $activation_limit ) { + $this->set_prop( 'activation_limit', absint( $activation_limit ) ); + } + + /** + * Get the validity. + * + * @return int + * @since 1.0.0 + */ + public function get_validity() { + return $this->get_prop( 'validity' ); + } + + /** + * Set the validity. + * + * @param int $validity Validity. + * + * @since 1.0.0 + */ + public function set_validity( $validity ) { + $this->set_prop( 'validity', absint( $validity ) ); + } + + /** + * Get the created at. + * + * @return string + * @since 1.0.0 + */ + public function get_date_created() { + return $this->get_prop( 'date_created' ); + } + + /** + * Set the created at. + * + * @param string $date_created Created at. + * + * @since 1.0.0 + */ + public function set_date_created( $date_created ) { + $this->set_prop( 'date_created', $date_created ); + } + + /* + |-------------------------------------------------------------------------- + | Helpers Methods + |-------------------------------------------------------------------------- + | + | Common methods used by the class. + | + */ + + /** + * Get product. + * + * @return \WC_Product|null Product object or null if not found. + * @since 1.4.6 + */ + public function get_product() { + $product_id = $this->get_product_id(); + + if ( $product_id ) { + return wc_get_product( $product_id ); + } + + return null; + } + + /** + * Get product name. + * + * @return string Product name. + * @since 1.4.6 + */ + public function get_product_title() { + return wcsn_get_product_title( $this->get_product_id() ); + } + + /** + * Generate a new code based on the configuration. + * + * @param int $amount Amount of codes to generate. + * @param int $product_id Product id. + * + * @return string + * @since 1.0.0 + */ + public function generate_codes( $amount = 1, $product_id = null ) { + $product_id = $product_id ? $product_id : $this->get_product_id(); + $product = wc_get_product( $product_id ); + $length = empty( $this->get_length() ) ? $this->get_length() : 32; + $pattern = empty( $this->get_pattern() ) ? $this->get_pattern() : str_repeat( '#', $length ); + $text_case = empty( $this->get_text_case() ) ? $this->get_text_case() : 'lowercase'; + $charset = empty( $this->get_charset() ) ? $this->get_charset() : 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + $codes = array(); + } +} diff --git a/src/Models/Key.php b/src/Models/Key.php index 6b6cd989..db7dc37b 100644 --- a/src/Models/Key.php +++ b/src/Models/Key.php @@ -19,7 +19,7 @@ class Key extends Model { * @since 1.0.0 * @var string */ - const TABLE_NAME = 'serial_numbers'; + protected $table_name = 'serial_numbers'; /** * Object type. @@ -27,15 +27,7 @@ class Key extends Model { * @since 1.0.0 * @var string */ - const OBJECT_TYPE = 'key'; - - /** - * Cache group. - * - * @since 1.0.0 - * @var string - */ - const CACHE_GROUP = 'serial_numbers'; + protected $object_type = 'key'; /** * Core data for this object. Name value pairs (name + default value). @@ -44,6 +36,7 @@ class Key extends Model { * @var array */ protected $core_data = array( + 'id' => 0, 'serial_key' => '', 'product_id' => 0, 'activation_limit' => 0, @@ -65,6 +58,30 @@ class Key extends Model { | Methods for getting and setting data. | */ + /** + * Get the key. + * + * @since 1.4.6 + * + * @return string + */ + public function get_id() { + return $this->get_prop( 'id' ); + } + + /** + * Set the key. + * + * @param string $id Key. + * + * @since 1.4.6 + * + * @return void + */ + public function set_id( $id ) { + $this->set_prop( 'id', absint( $id ) ); + } + /** * Get the serial key. * diff --git a/src/functions.php b/src/functions.php index 7bd2be31..86122fba 100644 --- a/src/functions.php +++ b/src/functions.php @@ -9,6 +9,7 @@ use WooCommerceSerialNumbers\Encryption; use WooCommerceSerialNumbers\Models\Activation; use WooCommerceSerialNumbers\Models\Key; +use WooCommerceSerialNumbers\Models\Generator; defined( 'ABSPATH' ) || exit; @@ -171,7 +172,7 @@ function wcsn_insert_key( $args, $wp_error = true ) { * @param array $args Query arguments. * * @since 1.4.6 - * @return array + * @return array|int Array of Key objects, otherwise the number of keys found. */ function wcsn_get_keys( $args = array() ) { return Key::query( $args ); @@ -953,3 +954,61 @@ function wcsn_get_product_link( $product_id ) { return get_permalink( $product_id ); } + + +/** + * Get the generator. + * + * @since 1.2.1 + * @return Generator|null + */ +function wcsn_get_generator( $id ) { + $generator = new Generator( $id ); + if ( $generator->exists() ) { + return $generator; + } + + return null; +} + +/** + * Get generators. + * + * @since 1.2.1 + * @return Generator[]|int + */ +function wcsn_get_generators( $args = array() ) { + return Generator::query( $args ); +} + +/** + * Insert a generator. + * + * @since 1.2.1 + * + * @param array $data Generator data. + * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. + * + * @return Generator|\WP_Error|bool + */ +function wcsn_insert_generator( $data, $wp_error = false ) { + return Generator::insert( $data, $wp_error ); +} + +/** + * Delete a generator. + * + * @since 1.2.1 + * + * @param int $id Generator ID. + * + * @return bool + */ +function wcsn_delete_generator( $id ) { + $generator = wcsn_get_generator( $id ); + if ( $generator ) { + return $generator->delete(); + } + + return false; +}