/**
 * Get the users based on groups from the User Access Manager plugin
 * $meta_filter can be '', MAILUSERS_ACCEPT_NOTIFICATION_USER_META, or MAILUSERS_ACCEPT_MASS_EMAIL_USER_META
 */
function mailusers_get_recipients_from_uam_group($uam_ids, $exclude_id = '', $meta_filter = '')
{
    global $wpdb;
    //  Make sure we have an array
    if (!is_array($uam_ids)) {
        $uam_ids = array($uam_ids);
    }
    //  No groups?  Return an empty array
    if (empty($uam_ids)) {
        return array();
    }
    //  Prepare tends to wrap stuff in quotes so we need to build up the IN construct
    //  based on the number of UAM IDs that are provided by the caller.
    $in = '';
    foreach ($uam_ids as $id) {
        $in .= '%d' . ($id == end($uam_ids) ? '' : ',');
    }
    $ids = array();
    $query = $wpdb->prepare("\n\t\tSELECT DISTINCT a.ID FROM {$wpdb->users} a\n\t\tINNER JOIN {$wpdb->prefix}uam_accessgroup_to_object b ON a.id = b.object_id\n\t\tWHERE b.object_type != 'role' AND b.group_id IN (" . $in . ")", $uam_ids);
    //  Get the IDs and put them in the proper format as
    //  the Query will return an array of Standard Objects
    foreach ($wpdb->get_results($query) as $id) {
        $ids[] = $id->ID;
    }
    //  Make sure the list of IDs accounts for the Email Users settings for email
    $ids = mailusers_get_recipients_from_ids($ids, $exclude_id, $meta_filter);
    return $ids;
}
예제 #2
0
/**
 * Get the users based on groups from the Paid Memberships Pro plugin
 * $meta_filter can be '', MAILUSERS_ACCEPT_NOTIFICATION_USER_META, or MAILUSERS_ACCEPT_MASS_EMAIL_USER_META
 */
function mailusers_get_recipients_from_membership_levels($pmp_ids, $exclude_id = '', $meta_filter = '')
{
    global $wpdb;
    //  Make sure we have an array
    if (!is_array($pmp_ids)) {
        $pmp_ids = array($pmp_ids);
    }
    //  No groups?  Return an empty array
    if (empty($pmp_ids)) {
        return array();
    }
    //  Prepare tends to wrap stuff in quotes so we need to build up the IN construct
    //  based on the number of PMP IDs that are provided by the caller.
    $in = '';
    foreach ($pmp_ids as $id) {
        $in .= '%d' . ($id == end($pmp_ids) ? '' : ',');
    }
    $ids = array();
    $query = $wpdb->prepare("\n\t\tSELECT DISTINCT a.ID FROM {$wpdb->users} a\n\t\tINNER JOIN {$wpdb->prefix}pmpro_memberships_users b ON a.id = b.user_id\n\t\tWHERE b.status = 'active' and b.membership_id IN (" . $in . ")", $pmp_ids);
    //  Get the IDs and put them in the proper format as
    //  the Query will return an array of Standard Objects
    foreach ($wpdb->get_results($query) as $id) {
        $ids[] = $id->ID;
    }
    //  Make sure the list of IDs accounts for the Email Users settings for email
    //  but only do it IF the list of ids is not empty otherwise all IDs will be
    //  returned!
    if (!empty($ids)) {
        $ids = mailusers_get_recipients_from_ids($ids, $exclude_id, $meta_filter);
    }
    return $ids;
}
예제 #3
0
/**
 * Get the users based on groups from the User Access Manager plugin
 * $meta_filter can be '', MAILUSERS_ACCEPT_NOTIFICATION_USER_META, or MAILUSERS_ACCEPT_MASS_EMAIL_USER_META
 */
function mailusers_get_recipients_from_itthinx_groups_group($itthinx_groups_ids, $exclude_id = '', $meta_filter = '')
{
    global $wpdb;
    $ids = array();
    //  Make sure we have an array
    if (!is_array($itthinx_groups_ids)) {
        $itthinx_groups_ids = array($itthinx_groups_ids);
    }
    //  No groups?  Return an empty array
    if (empty($itthinx_groups_ids)) {
        return array();
    }
    foreach ($itthinx_groups_ids as $key => $value) {
        $group = new Groups_Group($value);
        foreach ($group->users as $u) {
            $ids[] = $u->user->ID;
        }
    }
    //  Make sure the list of IDs accounts for the Email Users settings for email
    $ids = mailusers_get_recipients_from_ids($ids, $exclude_id, $meta_filter);
    return $ids;
}
        $post_content = $post_content[0];
    }
    $subject = mailusers_replace_post_templates($subject, $post_title, $post_author, $post_excerpt, $post_content, $post_url);
    if (mailusers_get_wpautop_processing() == 'true') {
        $mail_content = wpautop(mailusers_replace_post_templates($mail_content, $post_title, $post_author, $post_excerpt, $post_content, $post_url));
    } else {
        $mail_content = mailusers_replace_post_templates($mail_content, $post_title, $post_author, $post_excerpt, $post_content, $post_url);
    }
}
?>

<div class="wrap">
<?php 
// Fetch users
// --
$recipients = mailusers_get_recipients_from_ids(array($user_ID));
if (empty($recipients)) {
    ?>
		<p><strong><?php 
    _e('No recipients were found.', MAILUSERS_I18N_DOMAIN);
    ?>
</strong></p>
<?php 
} else {
    $useheader = mailusers_get_header_usage() != 'notification';
    $usefooter = mailusers_get_footer_usage() != 'notification';
    mailusers_send_mail($recipients, $subject, $mail_content, $mail_format, $from_name, $from_address, $useheader, $usefooter);
    ?>
		<div class="updated fade">
			<p><?php 
    echo sprintf(__("Test email sent to %s.", MAILUSERS_I18N_DOMAIN), $from_address);
    if (class_exists(MAILUSERS_USER_ACCESS_MANAGER_CLASS) && !empty($send_uam)) {
        $users_from_roles_and_filters = array_merge($users_from_roles_and_filters, mailusers_get_recipients_from_uam_group($send_uam, $exclude_id, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META));
    }
    if (class_exists(MAILUSERS_ITTHINX_GROUPS_CLASS) && !empty($send_groups)) {
        $users_from_roles_and_filters = array_merge($users_from_roles_and_filters, mailusers_get_recipients_from_itthinx_groups_group($send_groups, $exclude_id, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META));
    }
    if (class_exists(MAILUSERS_PMPRO_CLASS) && !empty($send_groups)) {
        $users_from_roles_and_filters = array_merge($users_from_roles_and_filters, mailusers_get_recipients_from_membership_levels($send_pmpro, $exclude_id, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META));
    }
    if (!empty($send_roles)) {
        $users_from_roles_and_filters = array_merge($users_from_roles_and_filters, mailusers_get_recipients_from_roles($send_roles, $exclude_id, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META));
    }
    // Fetch users
    // --
    if (!empty($send_users)) {
        $users_from_ids = mailusers_get_recipients_from_ids($send_users, $exclude_id, MAILUSERS_ACCEPT_NOTIFICATION_USER_META);
    } else {
        $users_from_ids = array();
    }
    $recipients = array_merge($users_from_roles_and_filters, $users_from_ids);
    if (empty($recipients)) {
        ?>
			<p><strong><?php 
        _e('No recipients were found.', MAILUSERS_I18N_DOMAIN);
        ?>
</strong></p>
	<?php 
    } else {
        $useheader = mailusers_get_header_usage() != 'email';
        $usefooter = mailusers_get_footer_usage() != 'email';
        $num_sent = mailusers_send_mail($recipients, $subject, $mail_content, $mail_format, $from_name, $from_address, $useheader, $usefooter);
예제 #6
0
/**
 * Get the users given a term or an array of terms
 * $meta_filter can be '', MAILUSERS_ACCEPT_NOTIFICATION_USER_META, or MAILUSERS_ACCEPT_MASS_EMAIL_USER_META
 */
function mailusers_get_recipients_from_user_groups($terms, $exclude_id = '', $meta_filter = '')
{
    $ids = get_objects_in_term($terms, MAILUSERS_USER_GROUPS_TAXONOMY);
    return mailusers_get_recipients_from_ids($ids, $exclude_id, $meta_filter);
}
    //--
    if ($mail_format == 'html') {
        $mail_content = wpautop($mail_content);
    }
    ?>
	<div class="wrap">
	<?php 
    // Fetch users
    // --
    //  Don't want to spam people so if more than one user was selected,
    //  drop all of the users who don't want to receive Mass Email!
    if (count($send_users) == 1) {
        $recipients = mailusers_get_recipients_from_ids($send_users, $exclude_id);
        $filtered_recipients_message = '';
    } else {
        $recipients = mailusers_get_recipients_from_ids($send_users, $exclude_id, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META);
        $filtered_recipients_message = sprintf(__('<br/>%d users who should not to receive Mass Email were filtered from the recipient list.', MAILUSERS_I18N_DOMAIN), count($send_users) - count($recipients));
    }
    if (empty($recipients)) {
        ?>
			<div class="error fade"><p><strong><?php 
        _e('No recipients were found.', MAILUSERS_I18N_DOMAIN) . $filtered_recipients_message;
        ?>
</strong></p></div>
	<?php 
        include 'email_users_user_mail_form.php';
    } else {
        $num_sent = mailusers_send_mail($recipients, $subject, $mail_content, $mail_format, $from_name, $from_address);
        if (false === $num_sent) {
            echo '<div class="error fade"><p><strong>' . __('There was a problem trying to send email to users.', MAILUSERS_I18N_DOMAIN) . $filtered_recipients_message . '</strong></p></div>';
        } else {