public static function register_connections() { if (self::$already_registered) { return; } self::$already_registered = true; p2p_register_connection_type(array('name' => self::LICENSE_TO_LICENSEKEY, 'from' => FOOLIC_CPT_LICENSE, 'to' => FOOLIC_CPT_LICENSE_KEY, 'to_query_vars' => array('orderby' => 'none'), 'from_query_vars' => array('orderby' => 'none'), 'can_create_post' => false, 'cardinality' => 'one-to-many', 'admin_column' => 'to', 'admin_dropdown' => 'to', 'title' => array('from' => __('License Keys', 'foolic'), 'to' => __('License', 'foolic')), 'to_labels' => array('column_title' => __('License', 'foolic')), 'from_labels' => array('create' => __('Select License', 'foolic')), 'admin_box' => array('show' => 'to', 'context' => 'side'))); p2p_register_connection_type(array('name' => self::LICENSEKEY_TO_DOMAINS, 'from' => FOOLIC_CPT_LICENSE_KEY, 'to' => FOOLIC_CPT_DOMAIN, 'title' => array('from' => __('Connected Domains', 'foolic'), 'to' => __('License Keys', 'foolic')), 'to_query_vars' => array('orderby' => 'none'), 'from_query_vars' => array('orderby' => 'none'), 'to_labels' => array('create' => __('Attach Domain', 'foolic')), 'admin_box' => array('show' => 'any', 'context' => 'advanced'), 'fields' => array('attached' => array('title' => 'Attached', 'type' => 'checkbox', 'default' => '1'), 'date_connected' => array('title' => 'Date Connected', 'type' => 'text', 'default_cb' => array('foolic_post_relationships', 'default_domain_connection_date'))))); p2p_register_connection_type(array('name' => self::USER_TO_LICENSEKEYS, 'from' => 'user', 'to' => FOOLIC_CPT_LICENSE_KEY, 'can_create_post' => false, 'cardinality' => 'one-to-many')); p2p_register_connection_type(array('name' => self::LICENSE_TO_LICENSE, 'from' => FOOLIC_CPT_LICENSE, 'to' => FOOLIC_CPT_LICENSE, 'can_create_post' => false, 'admin_column' => 'to', 'cardinality' => 'many-to-many', 'sortable' => 'any', 'title' => array('from' => __('Can Upgrade From The Following Licenses', 'foolic'), 'to' => __('Available License Upgrade Paths', 'foolic')), 'to_labels' => array('create' => __('Add Upgrade Path (Reverse)', 'foolic')), 'from_labels' => array('create' => __('Add Upgrade Path', 'foolic')), 'admin_box' => array('show' => 'any', 'context' => 'advanced'), 'fields' => array('upgrade' => array('title' => 'Upgrade Short Description', 'type' => 'text')))); do_action('foolic_p2p_register_connections'); }
/** * @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; }