WordPress.org

Plugin Directory

Changeset 648474


Ignore:
Timestamp:
01/05/13 23:47:31 (16 months ago)
Author:
MrWiblog
Message:

0.5 Added support for sending emails to users with just one role

Location:
sitewide-newsletter/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sitewide-newsletter/trunk/newsletter.php

    r444976 r648474  
    2525{ 
    2626    global $current_user, $wpdb; 
    27     $users = $wpdb->get_var( "select count(user_email) from ".$wpdb->users." where user_activation_key = '' and spam = 0 and deleted = 0" ); 
     27    $query_fields = array( 'fields' => array( 'user_login', 'user_email' ) ); 
     28    if ( array_key_exists( "role", $_POST ) && trim( $_POST["role"] ) != "" ) { 
     29        $query_fields = array( 'fields' => array( 'user_login', 'user_email' ), 'role' => trim( $_POST["role"] ) ); 
     30    } 
     31    $user_query = new WP_User_Query( $query_fields ); 
     32    $users = $user_query->get_total(); 
    2833     
    2934    $message = ""; 
     
    4752            { 
    4853             
    49                 $emails = $wpdb->get_results( "select user_email from ".$wpdb->users." where user_activation_key = '' and spam = 0 and deleted = 0" ); 
    50              
    51                 foreach ($emails as $email) 
     54                $user_query = new WP_User_Query( $query_fields ); 
     55                $emails = $user_query->get_results(); 
     56             
     57                foreach ( $emails as $email ) 
    5258                { 
    5359                    try { 
     
    5864                            $sent++; 
    5965                        } else { 
    60                             $failed .= $e . "\r\n"; 
     66                            if ( trim( $e ) == "" ) { 
     67                                $failed .= "No email address for user " . $email->user_login . "\r\n"; 
     68                            } else { 
     69                                $failed .= $e . "\r\n"; 
     70                            } 
    6171                        } 
    6272                     
     
    91101            if ($failed != "") 
    92102            { 
    93                 $message .= '<p>Failed addresses:</p><p><textarea cols="30" rows="12">' . $failed . '</textarea></p>'; 
     103                $message .= '<p>Failed addresses:</p><p><textarea cols="30" rows="12" style="width: 100%">' . $failed . '</textarea></p>'; 
    94104            } 
    95105             
     
    125135             
    126136        <p><label for="newsletter" style="float: left;width: 15%;">Newsletter</label><textarea name="newsletter" id="newsletter" cols="30" rows="6" style="width: 80%"></textarea></p> 
     137         
     138        <p><label for="role" style="float: left;width: 15%">Role</label><select name="role" id="role"> 
     139            <option value="">All</option> 
     140        '; 
     141        $roles = get_editable_roles(); 
     142        foreach( $roles as $role ) { 
     143            print ' 
     144            <option value="' . $role["name"] . '">' . $role["name"] . '</option> 
     145            '; 
     146        } 
     147        print ' 
     148        </select> Send this newsletter to users with just one role, or to all users</p> 
    127149         
    128150        <p><label for="subject" style="float: left;width: 15%;">Test newsletter</label><input type="checkbox" name="test" id="test" /> This will just send the newsletter to ' . get_site_option("admin_email") . '</p> 
  • sitewide-newsletter/trunk/readme.txt

    r444976 r648474  
    55Requires at least: 2.7 
    66Tested up to: 3.2 
    7 Stable tag: 0.4 
     7Stable tag: 0.5 
    88 
    99Sitewide Newsletters is a Wordpress MU plugin that allows site administrators to send an email message to all users. 
     
    3535== Changelog == 
    3636 
     370.5 Added support for sending emails to users with just one role 
    37380.4 Updated menu position, and added Network capability 
    38390.3.2 Compatibility with WP 3.0, several small bugfixes 
Note: See TracChangeset for help on using the changeset viewer.