MS_Model_Communication_Registration_Free

Communication model - registration for free membership.

Defined (1)

The class is defined in the following location(s).

/app/model/communication/class-ms-model-communication-registration-free.php  
  1. class MS_Model_Communication_Registration_Free extends MS_Model_Communication_Registration { 
  2.  
  3. /** 
  4. * Add action to credit card expire event. 
  5. * Related Action Hooks: 
  6. * - ms_model_event_paid 
  7. * @since 1.0.0 
  8. * @var string The communication type. 
  9. */ 
  10. protected $type = self::COMM_TYPE_REGISTRATION_FREE; 
  11.  
  12. /** 
  13. * Add action to signup event. 
  14. * @since 1.0.0 
  15. * @var string The communication type. 
  16. */ 
  17. public function after_load() { 
  18. parent::after_load(); 
  19.  
  20. if ( $this->enabled ) { 
  21. $this->add_action( 
  22. 'ms_model_event_'. MS_Model_Event::TYPE_MS_SIGNED_UP,  
  23. 'process_communication_registration', 10, 2 
  24. ); 
  25.  
  26. /** 
  27. * Get communication description. 
  28. * @since 1.0.0 
  29. * @return string The description. 
  30. */ 
  31. public function get_description() { 
  32. return __( 
  33. 'Sent when a member completes the signup for a free membership.', MS_TEXT_DOMAIN 
  34. ); 
  35.  
  36. /** 
  37. * Communication default communication. 
  38. * @since 1.0.0 
  39. */ 
  40. public function reset_to_default() { 
  41. parent::reset_to_default(); 
  42.  
  43. $this->subject = sprintf( 
  44. __( 'Confirmation of your membership at %s', MS_TEXT_DOMAIN ),  
  45. self::COMM_VAR_BLOG_NAME 
  46. ); 
  47. $this->message = self::get_default_message(); 
  48. $this->enabled = false; 
  49. $this->save(); 
  50.  
  51. do_action( 
  52. 'ms_model_communication_reset_to_default_after',  
  53. $this->type,  
  54. $this 
  55. ); 
  56.  
  57. /** 
  58. * Get default email message. 
  59. * @since 1.0.0 
  60. * @return string The email message. 
  61. */ 
  62. public static function get_default_message() { 
  63. $subject = sprintf( 
  64. __( 'Hi %1$s, ', MS_TEXT_DOMAIN ),  
  65. self::COMM_VAR_USERNAME 
  66. ); 
  67. $body_notice = sprintf( 
  68. __( 'Thanks for subscribing to our free <strong>%1$s</strong> membership at %2$s!', MS_TEXT_DOMAIN ),  
  69. self::COMM_VAR_MS_NAME,  
  70. self::COMM_VAR_BLOG_NAME 
  71. ); 
  72. $body_account = sprintf( 
  73. __( 'You can review and edit your membership details here: %1$s', MS_TEXT_DOMAIN ),  
  74. self::COMM_VAR_MS_ACCOUNT_PAGE_URL 
  75. ); 
  76.  
  77. $html = sprintf( 
  78. '<h2>%1$s</h2><br /><br />%2$s<br /><br />%3$s',  
  79. $subject,  
  80. $body_notice,  
  81. $body_account 
  82. ); 
  83.  
  84. return apply_filters( 
  85. 'ms_model_communication_registration_get_default_message',  
  86. $html 
  87. ); 
  88.  
  89. /** 
  90. * Process communication registration. 
  91. * Related Action Hooks: 
  92. * - ms_model_event_signed_up 
  93. * @since 1.0.0 
  94. * @var string The communication type. 
  95. */ 
  96. public function process_communication_registration( $event, $ms_relationship ) { 
  97. $membership = $ms_relationship->get_membership(); 
  98. $is_free = $membership->is_free || (int) $membership->price * 100 == 0; 
  99.  
  100. // Only process Free memberships here! 
  101. // Email for paid memberships is in MS_Model_Communiction_Registration 
  102. if ( ! $is_free ) { return; } 
  103.  
  104. do_action( 
  105. 'ms_model_communication_registration_process_before',  
  106. $ms_relationship,  
  107. $event,  
  108. $this 
  109. ); 
  110.  
  111. $this->send_message( $ms_relationship ); 
  112.  
  113. do_action( 
  114. 'ms_model_communication_registration_process_after',  
  115. $ms_relationship,  
  116. $event,  
  117. $this 
  118. );