Created
March 27, 2017 23:11
-
-
Save bappi-d-great/b21d8837854f32dd1d8567e59c38ed58 to your computer and use it in GitHub Desktop.
Create additional communication in WPMU Membership2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'ms_model_communication_get_communication_types', function( $types ) { | |
$types[] = 'my_custom_com_types'; | |
return $types; | |
}, 10 ); | |
add_filter( 'ms_model_communication_get_communication_type_titles', function( $type_titles ) { | |
$type_titles['my_custom_com_types'] = 'My Custom COM Types'; | |
return $type_titles; | |
}, 10 ); | |
add_filter( 'ms_model_communication_get_communication_type_classes', function( $type_classes ) { | |
$type_classes['my_custom_com_types'] = 'MS_Model_My_Custom_COM_Type'; | |
return $type_classes; | |
}, 10 ); | |
class MS_Model_My_Custom_COM_Type extends MS_Model_Communication{ | |
/** | |
* Add action to credit card expire event. | |
* | |
* Related Action Hooks: | |
* - ms_model_event_paid | |
* | |
* @since 1.0.0 | |
* @var string The communication type. | |
*/ | |
protected $type = 'my_custom_com_types'; | |
/** | |
* Get communication description. | |
* | |
* @since 1.0.0 | |
* @return string The description. | |
*/ | |
public function get_description() { | |
return __( | |
'My Custom type description.', 'membership2' | |
); | |
} | |
/** | |
* Communication default communication. | |
* | |
* @since 1.0.0 | |
*/ | |
public function reset_to_default() { | |
parent::reset_to_default(); | |
$this->subject = sprintf( | |
__( 'My Custom Type Subject %s', 'membership2' ), | |
self::COMM_VAR_BLOG_NAME | |
); | |
$this->message = self::get_default_message(); | |
$this->enabled = false; | |
do_action( | |
'ms_model_communication_reset_to_default_after', | |
$this->type, | |
$this | |
); | |
} | |
/** | |
* Get default email message. | |
* | |
* @since 1.0.0 | |
* @return string The email message. | |
*/ | |
public static function get_default_message() { | |
$subject = sprintf( | |
__( 'Hi %1$s,', 'membership2' ), | |
self::COMM_VAR_USERNAME | |
); | |
$body_notice = sprintf( | |
__( 'Thank you! Your <strong>%1$s</strong> Membership at %2$s is now activated!', 'membership2' ), | |
self::COMM_VAR_MS_NAME, | |
self::COMM_VAR_BLOG_NAME | |
); | |
$body_account = sprintf( | |
__( 'You can review and edit your membership details now here: %1$s', 'membership2' ), | |
self::COMM_VAR_MS_ACCOUNT_PAGE_URL | |
); | |
$body_invoice = __( 'Here is the most recent payment information for your subscription:', 'membership2' ); | |
$html = sprintf( | |
'<h2>%1$s</h2><br /><br />%2$s<br /><br />%3$s<br /><br />%4$s<br /><br />%5$s', | |
$subject, | |
$body_notice, | |
$body_account, | |
$body_invoice, | |
self::COMM_VAR_MS_INVOICE | |
); | |
return apply_filters( | |
'ms_model_communication_my_type_get_default_message', | |
$html | |
); | |
} | |
/** | |
* Process communication registration. | |
* | |
* @since 1.0.0 | |
*/ | |
public function process_communication( $event, $subscription ) { | |
$membership = $subscription->get_membership(); | |
// Only process Paid memberships here! | |
// Email for free memberships is in MS_Model_Communiction_Registration_Free | |
if ( $membership->is_free() ) { return; } | |
do_action( | |
'ms_model_communication_my_type_process_before', | |
$subscription, | |
$event, | |
$this | |
); | |
$this->send_message( $subscription ); | |
do_action( | |
'ms_model_communication_my_type_process_after', | |
$subscription, | |
$event, | |
$this | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment