function save_post_meta($post_id) { // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // verify nonce if (array_key_exists(FOOLIC_CPT_LICENSE_KEY . '_nonce', $_POST) && wp_verify_nonce($_POST[FOOLIC_CPT_LICENSE_KEY . '_nonce'], plugin_basename($this->_plugin_file))) { //if we get here, we are dealing with the licensekey custom post type //get all the license data $data = apply_filters('foolic_save_licensekey', $_POST[FOOLIC_CPT_LICENSE_KEY]); //and save it update_post_meta($post_id, FOOLIC_CPT_LICENSE_KEY, $data); //save some meta so that I know it is not new update_post_meta($post_id, foolic_licensekey::META_ISNEW, 'NOT'); //load the licensekey object $license_key = foolic_licensekey::get_by_id($post_id); //update the licensekey vendor from the license vendor [this is precautionary to make sure the data is valid] $license_vendor = $license_key->get_license()->author; update_post_meta($post_id, foolic_licensekey::META_VENDOR, $license_vendor); //update the author to be the connected user [this is precautionary to make sure the data is valid] $this->save_correct_vendor($license_key); //process attached domains $license_key->process_domains(); do_action('foolic_save_post_meta_for_license_key', $post_id, $_POST); } }
/** * Attach a domain to a license key * * @param int $licensekey_id The ID of the license key * @param int $domain_id The ID of the domain * * @return bool If the attachment was successful */ function foolic_attach_domain_to_licensekey($licensekey_id, $domain_id) { $licensekey = foolic_licensekey::get_by_id($licensekey_id); if ($licensekey->ID > 0) { return $licensekey->attach_domain($domain_id); } return false; }
/** * @param int $licensekey_id * @param int $upgrade_license_id */ function foolic_perform_upgrade($licensekey_id, $upgrade_license_id) { $license_key = foolic_licensekey::get_by_id($licensekey_id); if ($license_key->ID == 0) { return false; } if (!$license_key->is_deactivated()) { $date_format = get_option('date_format'); $expiry_date = $license_key->expires; $domain_limit = $license_key->domain_limit; //get the expiry date $expiry = strtotime($license_key->expires); //if already expired, then use today's date if ($expiry < time()) { $expiry = time(); } //ensure we have our connections registered foolic_post_relationships::register_connections(); //load new license $license = foolic_license::get_by_id($upgrade_license_id); if ($license->ID > 0) { $domain_limit = $license->domain_limit; if ($license->expires_in_days > 0) { $expiry_date = date($date_format, strtotime('+' . $license->expires_in_days . ' days', $expiry)); } else { $expiry_date = 'never'; } } //save new expiry date and domain limit $license_key->domain_limit = $domain_limit; $license_key->expires = $expiry_date; $license_key->process_domains(); //process domains immediately and update //delete connection $license_key->disconnect_from_existing_license(); //connect to new license $license->link_to_licensekey($license_key->ID); //save upgrade post meta $existing_upgrades = foolic_get_upgrades($license_key->ID); $existing_upgrades[] = array('upgrade_date' => date($date_format), 'upgrade_details' => __('Upgrade to', 'foolicensing') . ' ' . $license->name); foolic_update_upgrades($license_key->ID, $existing_upgrades); return true; } return false; }
/** * @param int $licensekey_id */ function foolic_perform_renewal($licensekey_id) { $license_key = foolic_licensekey::get_by_id($licensekey_id); if ($license_key->ID == 0) { return false; } if ($license_key->does_expire() && !$license_key->is_deactivated()) { $date_format = get_option('date_format'); $expiry_date = $license_key->expires; //get the expiry date $expiry = strtotime($license_key->expires); //if already expired, then use today's date if ($expiry < time()) { $expiry = time(); } //ensure we have our connections registered foolic_post_relationships::register_connections(); //load license $license = $license_key->get_license(); if ($license->ID > 0) { if ($license->expires_in_days > 0) { $expiry_date = date($date_format, strtotime('+' . $license->expires_in_days . ' days', $expiry)); } else { $expiry_date = 'never'; } } //save new expiry date $license_key->expires = $expiry_date; $license_key->update(); //save renewal post $renewal_post_args = apply_filters('foolic_renewal_post_args_override', array('post_type' => FOOLIC_CPT_RENEWAL, 'post_status' => 'publish', 'post_author' => $license->author, 'post_title' => $license->name . ' - ' . $license_key->license_key)); //insert the renewal post $renewal_id = wp_insert_post($renewal_post_args, true); //save renewal post meta $existing_renewals = foolic_get_renewals($license_key->ID); $existing_renewals[] = array('renewal_date' => date($date_format), 'renewal_id' => $renewal_id); foolic_update_renewals($license_key->ID, $existing_renewals); do_action('foolic_perform_renewal', $license_key->ID); return $renewal_id; } return false; }
<br /> </div> <h2><?php _e('License Key Overages', 'foolic'); ?> </h2> <?php if (!get_option('foolic_licensekey_setpostmeta')) { $args = array('post_type' => FOOLIC_CPT_LICENSE_KEY, 'nopaging' => true, 'fields' => 'ids'); $query = new WP_Query(); $keys = $query->query($args); if ($keys) { foreach ($keys as $licensekey_id) { $key = foolic_licensekey::get_by_id($licensekey_id); $key->store_meta_data(); } } _e('Post meta updated!', 'foolic'); add_option('foolic_licensekey_setpostmeta', true); } else { echo '<h3>' . __('Summary') . '</h3>'; echo 'Expiring license keys: ' . count(foolic_get_expiring_licensekeys()) . '<br />'; echo 'Expired license keys: ' . count(foolic_get_expired_licensekeys()) . '<br />'; echo 'Exceeded license keys: ' . count(foolic_get_exceeded_licensekeys()) . '<br />'; return; $filter = isset($_GET['licensekey_filter_status']) ? $_GET['licensekey_filter_status'] : ''; echo __('Overage Type', 'foolic') . '<select name="licensekey_filter_status"><option>' . __('--select--', 'foolic') . '</option>'; echo '<option value="expiring"' . ($filter == 'expiring' ? ' selected="selected"' : '') . '>' . __('Expiring', 'foolic') . '</option>'; echo '<option value="expired"' . ($filter == 'expired' ? ' selected="selected"' : '') . '>' . __('Expired', 'foolic') . '</option>';