diff --git a/CHANGELOG.md b/CHANGELOG.md index 202a1de..43d4c2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # CHANGELOG All notable changes to this project will be documented in this file. +#### 4.1 +- Added: New action hookFadded a new action hook #### 4.0 - Fixed a typo with the slm_api_response_args filter diff --git a/software-license-manager/includes/slm-third-party-integration.php b/software-license-manager/includes/slm-third-party-integration.php index c4e1825..0cdf087 100644 --- a/software-license-manager/includes/slm-third-party-integration.php +++ b/software-license-manager/includes/slm-third-party-integration.php @@ -1,19 +1,17 @@ log_debug("WP eStore integration - checking if a license key needs to be created for this transaction."); $products_table_name = $wpdb->prefix . "wp_eStore_tbl"; $slm_data = ""; - foreach ($cart_items as $current_cart_item) { $prod_id = $current_cart_item['item_number']; + $item_name = $current_cart_item['item_name']; $retrieved_product = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$prod_id'", OBJECT); $package_product = eStore_is_package_product($retrieved_product); if ($package_product) { @@ -22,33 +20,29 @@ function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) foreach ($product_ids as $id) { $id = trim($id); $retrieved_product_for_specific_id = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$id'", OBJECT); - $slm_data .= slm_estore_check_and_generate_key($retrieved_product_for_specific_id, $payment_data, $cart_items); + $slm_data .= slm_estore_check_and_generate_key($retrieved_product_for_specific_id, $payment_data, $cart_items, $item_name); } } else { $slm_debug_logger->log_debug('Checking license key generation for single item product.'); - $slm_data .= slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items); + $slm_data .= slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items, $item_name); } } - $body = str_replace("{slm_data}", $slm_data, $body); return $body; } - -function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items) { +function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items, $item_name) { global $slm_debug_logger; $license_data = ''; - if ($retrieved_product->create_license == 1) { $slm_debug_logger->log_debug('Need to create a license key for this product (' . $retrieved_product->id . ')'); - $slm_key = slm_estore_create_license($retrieved_product, $payment_data, $cart_items); + $slm_key = slm_estore_create_license($retrieved_product, $payment_data, $cart_items, $item_name); $license_data = "\n" . __('Item Name: ', 'slm') . $retrieved_product->name . " - " . __('License Key: ', 'slm') . $slm_key; $slm_debug_logger->log_debug('Liense data: ' . $license_data); $license_data = apply_filters('slm_estore_item_license_data', $license_data); } return $license_data; } - -function slm_estore_create_license($retrieved_product, $payment_data, $cart_items) { +function slm_estore_create_license($retrieved_product, $payment_data, $cart_items, $item_name) { global $slm_debug_logger; global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -57,7 +51,6 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item $options = get_option('slm_plugin_options'); $lic_key_prefix = $options['lic_prefix']; $max_domains = $options['default_max_domains']; - //Lets check any product specific configuration. $prod_id = $retrieved_product->id; $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_domains'", OBJECT); @@ -92,11 +85,8 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item $fields['date_created'] = date("Y-m-d"); //Today's date $fields['date_expiry'] = $slm_date_of_expiry; $fields['product_ref'] = $prod_id;//WP eStore product ID - $slm_debug_logger->log_debug('Inserting license data into the license manager DB table.'); $fields = array_filter($fields); //Remove any null values. - - $tbl_name = SLM_TBL_LICENSE_KEYS; $result = $wpdb->insert($tbl_name, $fields); if (!$result) { @@ -108,23 +98,22 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item $fields['last_name'] = esc_sql($last_name); $company_name = mb_convert_encoding($fields['company_name'], "UTF-8", "windows-1252"); $fields['company_name'] = esc_sql($company_name); - $result = $wpdb->insert($tbl_name, $fields); if (!$result) { $slm_debug_logger->log_debug('Error! Failed to update license key table. DB insert query failed.', false); } } //SLM_API_Utility::insert_license_data_internal($fields); + $prod_args = array('estore_prod_id' => $prod_id, 'estore_item_name' => $item_name); + do_action('slm_estore_license_created', $prod_args, $payment_data, $cart_items, $fields); return $fields['license_key']; } - /* Code to handle the eStore's product add/edit interface for SLM specific product configuration */ add_filter('eStore_addon_product_settings_filter', 'slm_estore_product_configuration_html', 10, 2); //Render the product add/edit HTML add_action('eStore_new_product_added', 'slm_estore_new_product_added', 10, 2); //Handle the DB insert after a product add. add_action('eStore_product_updated', 'slm_estore_product_updated', 10, 2); //Handle the DB update after a product edit. add_action('eStore_product_deleted', 'slm_estore_product_deleted'); //Handle the DB delete after a product delete. - function slm_estore_product_configuration_html($product_config_html, $prod_id) { global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -151,30 +140,22 @@ function slm_estore_product_configuration_html($product_config_html, $prod_id) { } else { $slm_date_of_expiry = ""; } - } - $product_config_html .= '
Software License Manager Plugin (Click to Expand)
'; - $product_config_html .= ''; - $product_config_html .= ''; - $product_config_html .= '
Maximum Allowed Domains'; $product_config_html .= ''; $product_config_html .= '

Number of domains/installs in which this license can be used. Leave blank if you wish to use the default value set in the license manager plugin settings.

'; $product_config_html .= '
Number of Days before Expiry'; $product_config_html .= ' Days'; $product_config_html .= '

Number of days before expiry. The expiry date of the license will be set based on this value. For example, if you want the key to expire in 6 months then enter a value of 180.

'; $product_config_html .= '
'; - return $product_config_html; } - function slm_estore_new_product_added($prod_dat_array, $prod_id) { global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; - //Save max domain value $fields = array(); $fields['prod_id'] = $prod_id; @@ -196,11 +177,9 @@ function slm_estore_new_product_added($prod_dat_array, $prod_id) { } } - function slm_estore_product_updated($prod_dat_array, $prod_id) { global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; - //Find the existing value for the max domains field (for the given product) $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_domains'", OBJECT); if ($product_meta) { @@ -238,7 +217,6 @@ function slm_estore_product_updated($prod_dat_array, $prod_id) { } } - function slm_estore_product_deleted($prod_id) { global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -246,7 +224,6 @@ function slm_estore_product_deleted($prod_id) { $result = $wpdb->delete($product_meta_table_name, array('prod_id' => $prod_id, 'meta_key' => 'slm_max_allowed_domains')); $result = $wpdb->delete($product_meta_table_name, array('prod_id' => $prod_id, 'meta_key' => 'slm_date_of_expiry')); } - /************************************/ /*** End of WP eStore integration ***/ /************************************/ \ No newline at end of file diff --git a/software-license-manager/software-license-manager.php b/software-license-manager/software-license-manager.php index 1f293e4..d07583a 100644 --- a/software-license-manager/software-license-manager.php +++ b/software-license-manager/software-license-manager.php @@ -1,7 +1,7 @@