I have the following code in a network install WordPress template. My intent is to allow a non-technical user (content manager who helps blog managers keep their content fresh, etc) to view all users of role "custom-role" by blog, then click the button to copy all email addresses to the textarea so she can copy and paste them into the bcc field and communicate with all current users.
However, the script is only cloning the first instance of class "emails". What am I missing? Shouldn't this grab all instances of li.emails?
<button id="copy">Copy all emails</button>
<textarea id="for-copy"></textarea>
<?php
$bcount = get_blog_count();
global $wpdb;
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE
spam = '0' AND deleted = '0' and archived = '0' and public='1'"));
if(!empty($blogs)){
foreach($blogs as $blog){
$details = get_blog_details($blog->blog_id);
if($details != false){
$addr = $details->siteurl;
$name = $details->blogname;
$id = $details->blog_id;
$blogusers = get_users( 'blog_id='.$id.'&role=custom-role' );
if (!empty($blogusers)) {
echo '<a href="'.$addr.'">'.$name.'</a>'.'<ul>';
foreach ( $blogusers as $user ) {
echo '<li class="emails">'.$user->user_email .'</li>';
}
echo '</ul>';
}
}
}
}
?>
<script>
(function($) {
$('#copy').click(function(e){
var new_list = $(".emails").clone();
$('#for-copy').append(new_list.html()); // also tried val()
});
})( jQuery );
</script>