Пример #1
0
/**
 * Register listeners for renewal reminders.
 *
 * @since 1.0
 *
 * @param Manager $manager
 */
function register_listeners(Manager $manager)
{
    $shared = \ITELIC\get_shared_tags();
    foreach ($shared as $listener) {
        $manager->listen($listener);
    }
    $manager->listen(new Listener('key', function (Key $key) {
        return $key->get_key();
    }));
    $manager->listen(new Listener('key_expiry_date', function (Key $key) {
        return $key->get_expires()->format(get_option('date_format') . ' ' . get_option('time_format'));
    }));
    $manager->listen(new Listener('key_days_from_expiry', function (Key $key) {
        $diff = $key->get_expires()->diff(new \DateTime(), true);
        return $diff->days;
    }));
    $manager->listen(new Listener('product_name', function (Key $key) {
        return $key->get_product()->post_title;
    }));
    $manager->listen(new Listener('transaction_order_number', function (Key $key) {
        return it_exchange_get_transaction_order_number($key->get_transaction());
    }));
    $manager->listen(new Listener('renewal_link', function (Key $key) {
        if ($key->is_renewable()) {
            return itelic_generate_auto_renewal_url($key);
        } else {
            return get_permalink($key->get_product()->ID);
        }
    }));
    $manager->listen(new Listener('discount_amount', function (Discount $discount) {
        return $discount->get_amount(true);
    }));
}
Пример #2
0
 /**
  * Setup the template manager for the notification sent to outdated
  * customers.
  *
  * @since 1.0
  *
  * @param Template_Manager $manager
  */
 public function outdated_customers_manager(Template_Manager $manager)
 {
     $shared = \ITELIC\get_shared_tags();
     foreach ($shared as $listener) {
         $manager->listen($listener);
     }
     $manager->listen(new Listener('product_name', function (Release $release) {
         return $release->get_product()->post_title;
     }));
     $manager->listen(new Listener('version', function (Release $release) {
         return $release->get_version();
     }));
     $manager->listen(new Listener('changelog', function (Release $release) {
         return $release->get_changelog();
     }));
     $manager->listen(new Listener('install_list', function (Release $release, \WP_User $to) {
         $query = new Activations(array('status' => Activation::ACTIVE, 'product' => $release->get_product()->ID, 'customer' => $to->ID, 'release__not_in' => array($release->get_pk())));
         $activations = array_filter($query->get_results(), function (Activation $activation) use($release) {
             if (!$activation->get_release()) {
                 return true;
             }
             return version_compare($activation->get_release()->get_version(), $release->get_version(), '<');
         });
         $html = '<ul>';
         /** @var Activation $activation */
         foreach ($activations as $activation) {
             $html .= '<li>' . "{$activation->get_location()} – v{$activation->get_release()->get_version()}" . '</li>';
         }
         $html .= '</ul>';
         return $html;
     }));
 }