Beispiel #1
0
 /**
  * Get activated activations by license
  *
  * @param \Never5\LicenseWP\License\License $license
  * @param \Never5\LicenseWP\ApiProduct\ApiProduct $api_product
  * @param bool $only_active
  *
  * @return array
  */
 public function get_activations($license, $api_product = null, $only_active = true)
 {
     global $wpdb;
     // dat SQL
     $sql = "SELECT `activation_id` FROM {$wpdb->lwp_activations} WHERE `license_key`=%s";
     // add API product ID if !== null
     if (null !== $api_product) {
         $sql .= $wpdb->prepare(" AND `api_product_id`=%s ", $api_product->get_slug());
     }
     // add if only_active is true
     if ($only_active) {
         $sql .= " AND activation_active = 1";
     }
     $sql .= ";";
     // get activation rows
     $rows = $wpdb->get_results($wpdb->prepare($sql, $license->get_key()));
     // array that stores the api products
     $activations = array();
     // check and loop
     if (is_array($rows) && count($rows) > 0) {
         foreach ($rows as $row) {
             // create ApiProduct objects and store them in array
             $activations[] = license_wp()->service('activation_factory')->make($row->activation_id);
         }
     }
     // return array
     return $activations;
 }
Beispiel #2
0
 /**
  * @param string $content
  * @param License $license
  *
  * @return string
  */
 private function replace_expiration_vars($content, $license)
 {
     // get user
     $user = get_user_by('id', $license->get_user_id());
     // get first name
     $fname = 'there';
     if (!empty($user) && !empty($user->first_name)) {
         $fname = $user->first_name;
     }
     // get WooCommerce product object
     $wc_product = new \WC_Product($license->get_product_id());
     // get parent product if the product has one
     if (0 != $wc_product->get_parent()) {
         $wc_product = new \WC_Product($wc_product->get_parent());
     }
     $content = str_ireplace(':fname:', $fname, $content);
     $content = str_ireplace(':product:', $wc_product->get_title(), $content);
     $content = str_ireplace(':license-key:', $license->get_key(), $content);
     $content = str_ireplace(':license-expiration-date:', $license->get_date_expires() ? $license->get_date_expires()->format('M d Y') : '', $content);
     $content = str_ireplace(':renewal-link:', $license->get_renewal_url(), $content);
     return $content;
 }
Beispiel #3
0
 /**
  * Returns URL to deactivate activation
  *
  * @param \Never5\LicenseWP\License\License $license
  *
  * @return string
  */
 public function get_deactivate_url($license)
 {
     return esc_url(add_query_arg(array('deactivate_license' => $this->get_id(), 'license_key' => $license->get_key(), 'activation_email' => $license->get_activation_email())));
 }
Beispiel #4
0
 /**
  * Get API product download URL
  *
  * @param \Never5\LicenseWP\License\License $license
  *
  * @return string
  */
 public function get_download_url($license)
 {
     return add_query_arg(array('download_api_product' => $this->get_id(), 'license_key' => $license->get_key(), 'activation_email' => $license->get_activation_email()), home_url('/'));
 }