Protected Content - Functions & Hooks Part 2

Following on from my previous post, here's some helpful code I've been working on:

BCC Communications instead of CC:

add_filter('ms_view_settings_prepare_messages_automated_fields', 'pc_comms_rename_cc', 10, 1);
add_filter('ms_model_communication_send_message_recipients', 'pc_comms_recipients', 10, 3);
add_filter('ms_model_communication_send_message_headers', 'pc_comms_headers', 10, 3);

function pc_comms_rename_cc($fields){
	$fields['cc_enabled']['title'] = __( 'Send blind copy to Administrator', MS_TEXT_DOMAIN );
return $fields;
}

function pc_comms_recipients($recipients, $invoice, $subscription){
if ( $invoice->cc_enabled) {
			if(($key = array_search($invoice->cc_email, $recipients)) !== false) {
	 		unset($recipients[$key]);
	 		}
			} 

return $recipients;
}

function pc_comms_headers($headers, $invoice, $subscription){
$headers = 'From: Email <email@address.co.uk>'  . "\r\n";
if ( $invoice->cc_enabled ) {
		$headers .= 'Bcc: ' . $invoice->cc_email  . "\r\n";
		} 

return $headers;
}

Please note that the current (5th March 2015) version requires that you fix the following line of code:
File: protected-content\app\model\class-ms-model-communication.php
Line: 846
Was: 'ms_model_communication_send_message_html_message',
Change: 'ms_model_communication_send_message_recipients',

    Ian Hulme

    Not a problem, always happy to help.

    Next little bit of helpful code is to edit the expiry date of a subscriber:

    add_action('edit_user_profile', 'add_custom_user_profile_fields',3);
    add_action('edit_user_profile_update', 'save_custom_user_profile_fields');
    
    function add_custom_user_profile_fields($user) {
    	if (!current_user_can('manage_options'))
            return FALSE;
    
    	$ms_relationships = MS_Model_Relationship::get_subscriptions(
    		array( 'user_id' => $user->ID )
    		);
    
    	foreach($ms_relationships as $obj){
    		$expire_date_id = $obj->id;
    		$expire_date = $obj->expire_date;
    		$user_id = $obj->user_id;
    		}
    	if ($user_id == $user->ID) {
        printf(
        '
    <h3>%1$s</h3>
    <table class="form-table">
    <tr>
    <th><label for="location">%2$s</label></th>
    <td>
      <input type="text" name="expire_date" id="expire_date" value="%3$s" class="regular-text" />
      <input type="hidden" name="expire_date_id" id="expire_date_id" value="%5$s" class="regular-text" />
      <br /><span class="description">%4$s</span>
    </td>
    </tr>
    </table>
    ',      __('Membership Expires', 'locale'),
            __('Expiry Date', 'locale'),
            $expire_date,
            __('Date Format YYYY-MM-DD', 'locale'),
    		$expire_date_id
        );
    	}
    }
    
    function save_custom_user_profile_fields($user_id) {
        if (!current_user_can('manage_options'))
            return FALSE;
    
    	$ms_relationships = MS_Model_Relationship::get_subscriptions( array( 'user_id' => $user_id ) );
    
    	foreach($ms_relationships as $obj){
    		$current_id = $obj->id;
    		$current = $obj->expire_date;
    		$current_user_id = $obj->user_id;
    		}
    
    	if (!isset($current) OR $current == '' OR !$current OR $current_user_id != $user_id)
    		return FALSE;
    
        $expire_date = ( isset($_POST['expire_date']) ) ? $_POST['expire_date'] : '';
    
    	if (!isset($expire_date) OR $expire_date == '' OR !$expire_date)
    		return FALSE;
    
        update_post_meta($current_id, 'expire_date', $expire_date);
    }