How do I display all the sites registered users on the Members Page?

Hi,

Currently, when users register as a user on my sub-sites I have them automatically added to my Main Blog ID 1 with the "subscriber role".

All users who personally register on the main blog do appear on the e-Newsletter Members Page (although they are not subscribed to any group). But the automatically added users do not appear on the e-Newsletter Members Page for the Main Blog.

I would like to have all of the registered users on my main blog appearing on the e-Newsletter Members Page. Does anyone know how to do this?

Thanks,
Michael

  • Kimberly

    Michael,

    Hey there and thanks for using WPMUdev forums!

    How are you adding the users from your sub-blog to the main?

    I will have to flag the developer on this as I am not sure how e-newsletter recognizes users nor how to change it. But it would be interesting to know.

    I believe there would be great use for this as a Multisite tool, being able to mail members across a network. I think this would be a great feature request! I'll move once the developer comments here :slight_smile:

    Best,

    Kimberly

  • twicealive

    Hi Cole,

    Thanks for your help! I really appreciate it.

    Right, I'm using "cets_default_user_role" plugin to add users to One or more additional sites.

    Somehow, I need to have the Newsletter Plugin on the Network Site to "see" the Newsletter Subscribers from all the sub-sites; Is there a simple solution for this?

    Or, in the alternative, I need the Newsletter Plugin on the Network Site to recognize the Blog ID 1 users list as part of the Newsletter Subscribers list.

    Or, possibly the "cets_default_user_role" plugin could be modified to add the user in a way that will allow the Newsletter Plugin to "see" the subscriber?

    Best Regards,
    Michael

  • twicealive

    Still There, Cole?..

    Re: adding a user to the main blog in addition to the subsite they came from, should bring them into the subscription list. Are you using the double opt-in setting by any chance

    The Double-optin seems to be a feature of the widget. If I use the widget to subscribe to a list, then the subscriber is not added as a user to either blog 1 or the sub-site. Which I think is the intended outcome of the widget functionality.

    The problem of adding the user to the main blog is that there is a difference between adding a user via wp-signup and wp-register.

    What I don't understand is why the Newsletter plugin doesn't simply recognize the "users" for the blog site irregardless of how they were added to the user database. Apparently, the plugin has its own table of users, rather than getting them from the blog users table.

    WP can see the Users List, and I want to repair the plugin so it can see the WP Users List. Can you tell me where in the plugin that I can see this?

    Thanks,
    Michael

  • Kimberly

    What I don't understand is why the Newsletter plugin doesn't simply recognize the "users" for the blog site irregardless of how they were added to the user database

    Sorry if I'm not making any sense here but I am wondering if this is even the problem.

    Users have to opt-in to the Newsletter correct? That's SOP for newsletters, so...
    Perhaps it doesn't see the users simply because they have not subscribed to that particular instance of that Newsletter.

    This by no means is a solution, but perhaps another way of looking at the problem?

  • Cole

    So after a little more investigation, I realize that user's are only automatically added to the subscription list upon installation. And thinking about it, it is for good reason. It would be a pretty heavy function to cross-reference the user table to the e-newsletter table on every page load for larger installations. I'm including a custom drop-in plugin I whipped up quickly that will re-sync your users with the database.

    A few things to note before installing this. If you leave this plugin activated it will run everytime you load a wp-admin page. It may be a better idea to activate then deactivate this as a temporary fix when you need to. I have made a note to make some changes on the next release so that this method will become obsolete.

    I can't upload php files in threads so I am going to try and just include it below.

    To Install this create a new file in your wp-content/plugins/ folder. You can call it whatever you like just make sure it ends in .php. Paste the code in there activate it and hopefully you will be set. Let me know if you have any trouble. Hopefully everything goes smoothly.

    <?php
    /*
    Plugin Name: E-Newsletter Sync
    Plugin URI: https://premium.wpmudev.org
    Description: Sync a single blog's users to the e-newsletter members table.
    Version: 1.0
    Author: Cole (incsub)
    Author URI: https://premium.wpmudev.org
    License: GPLv3
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    */
    add_action('admin_init', 'enewsletter_init_member_sync');
    
    function enewsletter_init_member_sync() {
    	global $email_newsletter, $wpdb, $blog_id;
    
    	if ( 1 < $blog_id )
    		$tb_prefix = $wpdb->base_prefix . $blog_id . '_';
    	else
    		$tb_prefix = $wpdb->base_prefix;
    
    	//Sync exist wp users
    	$arg = array (
    		'blog_id' => $blog_id
    	);
    	$users = get_users( $arg );
    
    	if ( $users ) {
    		foreach( $users as $user ) {
    			$unsubscribe_code = $email_newsletter->gen_unsubscribe_code();
    			$search = $wpdb->get_row("SELECT * FROM {$tb_prefix}enewsletter_members WHERE wp_user_id = ".$user->ID);
    
    			if(empty($search)) {
    				$result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$tb_prefix}enewsletter_members SET
    					wp_user_id = %d,
    					member_fname = %s,
    					member_email = %s,
    					join_date = %d,
    					unsubscribe_code = '%s'
    				 ", $user->ID, $user->user_nicename, $user->user_email, time(), $unsubscribe_code ) );
    			}
    		}
    	}
    }
    ?>
  • Cole

    You could, I would be careful about doing it with large amounts of users, because it might unnecessarily increase your page load times.

    You can change
    add_action('admin_init', 'enewsletter_init_member_sync');
    to
    add_action('init', 'enewsletter_init_member_sync');

    that would have the function run on every page load. There aren't any other adequate actions inside e-newsletter to hook into at the moment, but like I mentioned before I plan to find a more permanent solution to this in a future release.

    Alternatively, if you commented out or removed the add_action() line you could call the enewsletter_init_member_sync(); function from just about any location you choose. You should note that it will only work if the plugin is activated on the specific subsite your trying to make the call from.

  • Cole

    You could try this.

    <?php
    /*
    Plugin Name: E-Newsletter Sync
    Plugin URI: https://premium.wpmudev.org
    Description: Sync a single blog's users to the e-newsletter members table.
    Version: 1.0
    Author: Cole (incsub)
    Author URI: https://premium.wpmudev.org
    License: GPLv3
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    */
    add_action('admin_init', 'enewsletter_init_member_sync');
    
    function enewsletter_init_member_sync() {
    	global $email_newsletter, $wpdb, $blog_id;
    
    	if ( 1 < $blog_id )
    		$tb_prefix = $wpdb->base_prefix . $blog_id . '_';
    	else
    		$tb_prefix = $wpdb->base_prefix;
    
    	//Sync exist wp users
    	$arg = array (
    		'blog_id' => $blog_id
    	);
    	$users = get_users( $arg );
    
    	if ( $users ) {
    		foreach( $users as $user ) {
    			$unsubscribe_code = $email_newsletter->gen_unsubscribe_code();
    			$search = $wpdb->get_row("SELECT * FROM {$tb_prefix}enewsletter_members WHERE wp_user_id = ".$user->ID);
    
    			if(empty($search)) {
    				$result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$tb_prefix}enewsletter_members SET
    					wp_user_id = %d,
    					member_fname = %s,
    					member_email = %s,
    					join_date = %d,
    					unsubscribe_code = '%s'
    				 ", $user->ID, $user->user_nicename, $user->user_email, time(), $unsubscribe_code ) );
    			} else {
    				$tb_data = array(
    					'member_fname' => $user->user_nicename,
    					'member_email' =>$user->user_email
    				);
    				$result = $wpdb->update( $tb_prefix . 'enewsletter_members', $tb_data, array('wp_user_id' => $user->ID) );
    			}
    		}
    	}
    }
    ?>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.