fluiditystudio
Forum Replies Created
-
Thanks for adding this feature! I’m also curious as to if you took a look at the code I modified above regarding the license activation expire date. I have purchased many plugins over the years and a number of times, I have not needed to install and activate the plugin right away. I would just purchase it in advance for a project and install and use when needed.
In the case of your current code, when a purchase is made and a license key is created, the expire date is set one year from the creation date. If someone purchases a plugin and has no need to install and activate it just yet, then their clock is already ticking.
My modified code basically updates the renewed date to the current day activated and updates the expire date to one year from that activation date if the status was “pending” when activated. This is going the extra mile I know, but if they haven’t started using the plugin yet, then their time should start until they do.
What is your opinion about adding this feature?
Thanks!
BTW: I’m almost done with a full WooCommerce integration addon for this plugin! I’m excited to release it. It will even check the expiration dates and send out an email at 1 month, 2 weeks & 3 days before the expiration date. In the email they can click a link that will populate the checkout page with their plugin and license key to renew. Upon payment, their expiration date will be updated another year from that date! There are other cool features in the addon as well.
Forum: Plugins
In reply to: [WooCommerce] Custom product meta on order status completedI knew it was something so simple and I was over analyzing it. I totally got it to work. Thanks for the point in the right direction Mike!
If anyone else wants this feature I have modified the slm-api-listener.php file in the plugin under the “activation_api_listener()” function to update the expire field on activation to 1 year from the day the license is activated. The additional code checks for a “Pending” status as each new license will begin with this status until activated by the end user.
The code checks the status upon license activation. If the license was pending upon activation, then it will update the expire date to 1 year from the date the user activated it. The license status then goes into “Active” and if the user were to deactivate and reactivate it again, the expire date would not change.
My code is noted below:
<?php /* * This class listens for API query and executes the API requests * Available API Actions * 1) slm_create_new * 2) slm_activate * 3) slm_deactivate * 4) slm_check */ class SLM_API_Listener { function __construct() { if (isset($_REQUEST['slm_action']) && isset($_REQUEST['secret_key'])) { //This is an API query for the license manager. Handle the query. $this->creation_api_listener(); $this->activation_api_listener(); $this->deactivation_api_listener(); $this->check_api_listener(); } } function creation_api_listener() { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_create_new') { //Handle the licene creation API query global $slm_debug_logger; $options = get_option('slm_plugin_options'); $lic_key_prefix = $options['lic_prefix']; SLM_API_Utility::verify_secret_key_for_creation(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license creation (slm_create_new) request received."); //Action hook do_action('slm_api_listener_slm_create_new'); $fields = array(); if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])){ $fields['license_key'] = strip_tags($_REQUEST['license_key']);//Use the key you pass via the request }else{ $fields['license_key'] = uniqid($lic_key_prefix);//Use random generated key } $fields['lic_status'] = 'pending'; $fields['first_name'] = strip_tags($_REQUEST['first_name']); $fields['last_name'] = strip_tags($_REQUEST['last_name']); $fields['email'] = strip_tags($_REQUEST['email']); $fields['company_name'] = strip_tags($_REQUEST['company_name']); $fields['txn_id'] = strip_tags($_REQUEST['txn_id']); if (empty($_REQUEST['max_allowed_domains'])) { $fields['max_allowed_domains'] = $options['default_max_domains']; } else { $fields['max_allowed_domains'] = strip_tags($_REQUEST['max_allowed_domains']); } $fields['date_created'] = isset($_REQUEST['date_created'])?strip_tags($_REQUEST['date_created']):date("Y-m-d"); $fields['date_expiry'] = isset($_REQUEST['date_expiry'])?strip_tags($_REQUEST['date_expiry']):''; global $wpdb; $tbl_name = SLM_TBL_LICENSE_KEYS; $result = $wpdb->insert($tbl_name, $fields); if ($result === false) { //error inserting $args = (array('result' => 'error', 'message' => 'License creation failed')); SLM_API_Utility::output_api_response($args); } else { $args = (array('result' => 'success', 'message' => 'License successfully created', 'key' => $fields['license_key'])); SLM_API_Utility::output_api_response($args); } } } /* * Query Parameters * 1) slm_action = slm_create_new * 2) secret_key * 3) license_key * 4) registered_domain (optional) */ function activation_api_listener() { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_activate') { //Handle the license activation API query global $slm_debug_logger; SLM_API_Utility::verify_secret_key(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license activation (slm_activate) request received."); //Action hook do_action('slm_api_listener_slm_activate'); $fields = array(); $fields['lic_key'] = trim(strip_tags($_REQUEST['license_key'])); $fields['registered_domain'] = trim(strip_tags($_REQUEST['registered_domain'])); //gethostbyaddr($_SERVER['REMOTE_ADDR']); $fields['item_reference'] = trim(strip_tags($_REQUEST['item_reference'])); $slm_debug_logger->log_debug("License key: " . $fields['lic_key'] . " Domain: " . $fields['registered_domain']); global $wpdb; $tbl_name = SLM_TBL_LICENSE_KEYS; $reg_table = SLM_TBL_LIC_DOMAIN; $key = $fields['lic_key']; $sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key); $retLic = $wpdb->get_row($sql_prep1, OBJECT); $sql_prep2 = $wpdb->prepare("SELECT * FROM $reg_table WHERE lic_key = %s", $key); $reg_domains = $wpdb->get_results($sql_prep2, OBJECT); if ($retLic) { if ($retLic->lic_status == 'blocked') { $args = (array('result' => 'error', 'message' => 'Your License key is blocked')); SLM_API_Utility::output_api_response($args); } elseif ($retLic->lic_status == 'expired') { $args = (array('result' => 'error', 'message' => 'Your License key has expired')); SLM_API_Utility::output_api_response($args); //Added if pending status check for initial activation. If the license status is pending upon activation, then the expire date will be updated to 1 year from the date activated. The Renewed date will be update with the activation date. } elseif ($retLic->lic_status == 'pending') { $expireDate = date('Y-m-d', strtotime('+1 year')); $currentDate = date('Y-m-d'); } else { $expireDate = ''; $currentDate = ''; }//end if pending status check. if (count($reg_domains) < floor($retLic->max_allowed_domains)) { foreach ($reg_domains as $reg_domain) { if (isset($_REQUEST['migrate_from']) && (trim($_REQUEST['migrate_from']) == $reg_domain->registered_domain)) { $wpdb->update($reg_table, array('registered_domain' => $fields['registered_domain']), array('registered_domain' => trim(strip_tags($_REQUEST['migrate_from'])))); $args = (array('result' => 'success', 'message' => 'Registered domain has been updated')); SLM_API_Utility::output_api_response($args); } if ($fields['registered_domain'] == $reg_domain->registered_domain) { $args = (array('result' => 'error', 'message' => 'License key already in use on ' . $reg_domain->registered_domain)); SLM_API_Utility::output_api_response($args); } } $fields['lic_key_id'] = $retLic->id; $wpdb->insert($reg_table, $fields); $slm_debug_logger->log_debug("Updating license key status to active."); //If status pending before activation update expire date to 1 year from current activation date. if($expireDate == true){ $data = array('lic_status' => 'active', 'date_renewed' => $currentDate, 'date_expiry' => $expireDate); }else{ $data = array('lic_status' => 'active'); } $where = array('id' => $retLic->id); $updated = $wpdb->update($tbl_name, $data, $where); $args = (array('result' => 'success', 'message' => 'License key activated')); SLM_API_Utility::output_api_response($args); } else { $args = (array('result' => 'error', 'message' => 'Reached maximum allowable domains')); SLM_API_Utility::output_api_response($args); } } else { $args = (array('result' => 'error', 'message' => 'Invalid license key')); SLM_API_Utility::output_api_response($args); } } } function deactivation_api_listener() { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_deactivate') { //Handle the license deactivation API query global $slm_debug_logger; SLM_API_Utility::verify_secret_key(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license deactivation (slm_deactivate) request received."); //Action hook do_action('slm_api_listener_slm_deactivate'); if (empty($_REQUEST['registered_domain'])) { $args = (array('result' => 'error', 'message' => 'Registered domain information is missing')); SLM_API_Utility::output_api_response($args); } $registered_domain = trim(strip_tags($_REQUEST['registered_domain'])); $license_key = trim(strip_tags($_REQUEST['license_key'])); $slm_debug_logger->log_debug("License key: " . $license_key . " Domain: " . $registered_domain); global $wpdb; $registered_dom_table = SLM_TBL_LIC_DOMAIN; $sql_prep = $wpdb->prepare("DELETE FROM $registered_dom_table WHERE lic_key=%s AND registered_domain=%s", $license_key, $registered_domain); $delete = $wpdb->query($sql_prep); if ($delete === false) { $slm_debug_logger->log_debug("Error - failed to delete the registered domain from the database."); } else if ($delete == 0) { $args = (array('result' => 'error', 'message' => 'The license key on this domain is already inactive')); SLM_API_Utility::output_api_response($args); } else { $args = (array('result' => 'success', 'message' => 'The license key has been deactivated for this domain')); SLM_API_Utility::output_api_response($args); } } } function check_api_listener() { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_check') { //Handle the license check API query global $slm_debug_logger; SLM_API_Utility::verify_secret_key(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license check (slm_check) request received."); $fields = array(); $fields['lic_key'] = trim(strip_tags($_REQUEST['license_key'])); $slm_debug_logger->log_debug("License key: " . $fields['lic_key']); //Action hook do_action('slm_api_listener_slm_check'); global $wpdb; $tbl_name = SLM_TBL_LICENSE_KEYS; $reg_table = SLM_TBL_LIC_DOMAIN; $key = $fields['lic_key']; $sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key); $retLic = $wpdb->get_row($sql_prep1, OBJECT); $sql_prep2 = $wpdb->prepare("SELECT * FROM $reg_table WHERE lic_key = %s", $key); $reg_domains = $wpdb->get_results($sql_prep2, OBJECT); if ($retLic) {//A license key exists $args = (array( 'result' => 'success', 'message' => 'License key details retrieved.', 'status' => $retLic->lic_status, 'max_allowed_domains' => $retLic->max_allowed_domains, 'email' => $retLic->email, 'registered_domains' => $reg_domains, 'date_created' => $retLic->date_created, 'date_renewed' => $retLic->date_renewed, 'date_expiry' => $retLic->date_expiry, )); //Output the license details SLM_API_Utility::output_api_response($args); } else { $args = (array('result' => 'error', 'message' => 'Invalid license key')); SLM_API_Utility::output_api_response($args); } } } }
The only problem with modifying this file, is that you will need to add the updated code back in if the plugin gets updated and the authors have not already added this feature.
Also another thing that I noticed is that when a license is created either through the admin or via the API after a purchase is made, the date_expiry needs to be set. The expire date should be set by the system 1 year or whatever amount from the date activated.
If I set an expiry date as 1 year from the time they placed the order, then the clock is already ticking on their license when they may not activate it for a while.
Could this featured be added?
Forum: Plugins
In reply to: [Software License Manager] License panel not updatingUse the slm_check to verify if the license is active or not. This example code will throw a JavaScript alert if the license comes back activated or deactivated.
/*** Verify license key is active ***/ $api_params = array( 'slm_action' => 'slm_check', 'secret_key' => 'YOUR_SECRET_KEY_GOES_HERE', 'license_key' => get_option('sample_license_key'), //replace with your license key field name. ); // Send query to the license manager server $response = wp_remote_get(add_query_arg($api_params, YOUR_LICENSE_SERVER_URL), array('timeout' => 20, 'sslverify' => false)); $license_data = json_decode(wp_remote_retrieve_body($response)); global $active, $message; if($license_data->result == 'success'){?> <script>alert('Activated');</script> <?php }else{ ?> <script>alert('Deactivated');</script> <?php }
You could even go a step further and check if the license is active and as well as if it is past the expiration date.
/*** Verify license key is active and expire date has not passed ***/ $api_params = array( 'slm_action' => 'slm_check', 'secret_key' => 'YOUR_SECRET_KEY_GOES_HERE', 'license_key' => get_option('sample_license_key'), //replace with your license key field name. ); // Send query to the license manager server $response = wp_remote_get(add_query_arg($api_params, YOUR_LICENSE_SERVER_URL), array('timeout' => 20, 'sslverify' => false)); $license_data = json_decode(wp_remote_retrieve_body($response)); global $active, $message; if($license_data->result == 'success' && $license_data->date_expiry >= date('Y-m-d')){?> <script>alert('Activated');</script> <?php }else{ ?> <script>alert('Deactivated');</script> <?php }
Running this will show you an alert that will verify it works. After you have verified that it works, just replace the JavaScript alerts with whatever functions you want to run for activated and deactivated.
I’m using this same code to activate the shortcode in my plugin if the license is activated and the expiration date hasn’t passed. If the expiration date has passed and the license is still active, then my shortcode still isn’t usable.
Since the update, I have found that if you upload a file it gets uploaded to the main filebase folder in the uploads directory and when you select a category and add file, the file then gets deleted. If you create the file name and category and add file then go back and actually upload the file, then it will work and the file will be there. For some reason there is an issue with the category and moving the file to that folder, it just deletes it. This problem needs to be repaired, as the less technically inclined will not figure out how to get around this problem.
Forum: Plugins
In reply to: Export Custom Table to CSVSo, I have finally answered my own question. In case anyone else comes across this problem here is the answer.
$idList = array(); foreach( $entry_id as $id){ if ((int)$id > 0) { $idList[] = (int)$id; } }//end foreach $sql = $wpdb->get_results( "SELECT * FROM $bp_table_name WHERE id IN(" . implode(",", $idList) . ")");
Forum: Plugins
In reply to: [Coupon Creator] Confict with Events Calendar by Modern TribeResolved!
Forum: Plugins
In reply to: [Coupon Creator] Confict with Events Calendar by Modern TribeThanks Brian, you ROCK!
Forum: Plugins
In reply to: [Coupon Creator] Confict with Events Calendar by Modern TribeBy the way, the version 3.8.1 before 3.9 works just fine against your plugin. But anyone who has uses The Events Calendar and Coupon Creator, will be forced to keep The Events Calendar at version 3.8.1 unless you come up with a fix.
Thanks!
Forum: Plugins
In reply to: [rtMedia for WordPress, BuddyPress and bbPress] Play list for Music albumThere is a great Music Albums Plugin here. It allows you to upload music into an album with album art and other info as well as pause/play buttons with download individual songs option or purchase album option.
Forum: Hacks
In reply to: update custom db table row via a plugin page through http urlI finished my plugin and it works GREAT!!!
https://fluiditystudio.com/wpplugins/catfishad/Forum: Hacks
In reply to: update custom db table row via a plugin page through http urlHere is my “Save” function:
function adcounter_save_advertiser() { global $wpdb; global $wp_ad_counter_table; $wp_ad_counter_table = $wpdb->prefix . "ad_counter"; $save_and_publish = $_POST['save-and-publish']; $advertiser = $_POST['advertiser']; if( isset($save_and_publish) ) { $insert = "INSERT INTO " . $wp_ad_counter_table . " (advertiser) " . "VALUES ('" . $wpdb->escape($advertiser) . "')"; $results = $wpdb->query( $insert ); echo '<div class="updated"><p>Advertiser has been added!</p></div>'; } }
And my form to save it:
global $advertiser; global $save_and_publish; if ( isset($save_and_publish) ) { echo '<div class="updated"><p>Advertiser has been added</p></div>'; } echo'<br/><hr>'; echo' <div class="wrap ad-advertiser"> <h2>Add New Advertiser</h2> <p>Enter the name of your new advertiser here:</p> <form action="" method="post"> <p><input type="text" name="advertiser" id="advertiser" value="' . $advertiser . '" size="20" /></p> <p> <button class="button-primary" name="save-and-publish">Submit Advertiser</button> </p> </form> </div>';
IT WORKS LIKE A CHARM!
Forum: Hacks
In reply to: update custom db table row via a plugin page through http urlThat didn’t work, but this did!!!
<?PHP include_once("../../../wp-config.php"); include_once("../../../wp-load.php"); include_once("../../../wp-includes/wp-db.php"); global $wpdb; $table_name = "wp_ad_counter"; extract($_GET); $sql = "SELECT * FROM $table_name WHERE id = $id"; $result = @mysql_query($sql); while ($row = mysql_fetch_array($result)) { $clickthrough = $row['clickthrough']; } //UPDATE VIEW CONNECTION $clickthrough = $clickthrough +1; $query="UPDATE $table_name SET clickthrough = '$clickthrough' WHERE id= $id"; $result=mysql_query($query); header("location: $adurl"); ?>
Thanks for the help though!
Forum: Plugins
In reply to: Query doubling up on loop_start– post retracted…. I commented on the wrong one.