Support » Plugin: MailPoet - emails and newsletters in WordPress » Subscribers in multisite

  • Hi,

    This morning, I update MailPoet to version 3. Now, when a site admin go to the subscribers page, all multisite wordpress users are synchronize as subscribers of MP3. Even the multisite WordPress users that are not members of the blog!
    If we try to delete subscribers, Mailpoet said that 0 user have ben move to the trash.

    Thanks,

    Jean-David Rivard

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter jdrivard

    (@jdrivard)

    Is there anybody using MP3 on a multisite environment? IS the subscribers correct on your side?

    Thanks,

    Jean-David

    Thread Starter jdrivard

    (@jdrivard)

    Hi,

    I suggest this modification to the file WP.php, line 118, function insertSubscribers :

    
      private static function insertSubscribers()
      {
        global $wpdb;
        $subscribers_table = Subscriber::$_table;
    
        $request = sprintf('
          INSERT IGNORE INTO %s(wp_user_id, email, status, created_at)
            SELECT wu.id, wu.user_email, "subscribed", CURRENT_TIMESTAMP() FROM %s wu
              LEFT JOIN %s mps ON wu.id = mps.wp_user_id
              WHERE mps.wp_user_id IS NULL', $subscribers_table, $wpdb->users, $subscribers_table);
    
        if (is_multisite() == true)
        {
            $blogMembersID = get_users(array('blog_id' => get_current_blog_id(), 'fields' => array('ID')));
            $inID = "";
            foreach ($blogMembersID as $id)
            {
                if ($inID != "")
                {
                    $inID .= ",";
                }
                $inID .= $id->ID;
            }
            $request .= ' AND wu.id in ('.$inID.')';
        }
        
        Subscriber::raw_execute($request);
      }
    

    With the in value that contains all members, subscribers reflect realty of the multisite environment.

    Hope you will include as possible the multisite purpose in MailPoet. Without this consideration, we can’t process to buy the premium version for our organisation.

    Thanks,

    Jean-David Rivard

    • This reply was modified 4 years, 8 months ago by jdrivard.

    Hi Jean-David,

    Thanks for the suggestion. This is already in the works by our team.

    @jdrivard We’re also using a MS and having the same issues. Just wanted to try out your suggestion. A support member of MailPoet suggested your thread. It is still not solved yet.

    Anyhow. Unfortunately we couldn’t find a file called WP.php – where about is it located? I would be really happy if you could provide the directory path.

    Thanks in advance,
    Best Anke

    Thread Starter jdrivard

    (@jdrivard)

    Hi,

    You can find the wp.php in the mailpoet directory / lib/Segments/wp.php

    Also, I suggest you to introduce this piece of code to repair the auto alimentation of users :

    In the same file, replace the removeOrphanedSubscribers by this function :

    private static function removeOrphanedSubscribers() {
          //removeorphanedwpsegmentsubscribers(nothavingamatchingwpuserid),
          //e.g.ifwpusersweredeleteddirectlyfromthedatabase
          global $wpdb;
    
          $wp_segment=Segment::getWPSegment();
    
          $wp_segment->subscribers()
              ->leftOuterJoin($wpdb->users,array(MP_SUBSCRIBERS_TABLE.'.wp_user_id','=','wu.id'),'wu')
              ->whereNull('wu.id')
              ->findResultSet()
              ->set('wp_user_id',null)
              ->delete();
    
          //Pour faire le menage du bug
          $blogMembersID=get_users(array('blog_id'=>get_current_blog_id(),'fields'=>array('ID')));
          $inID="";
          foreach($blogMembersID as $id)
          {
              if($inID!="")
              {
                  $inID.=",";
              }
              $inID.=$id->ID;
          }
    
          $subscribers_table=Subscriber::$_table;
    
          $request=sprintf('DELETE FROM %s WHERE wp_user_id is not null AND wp_user_id not in('.$inID.')',$subscribers_table);
    
          Subscriber::raw_execute($request);
    
      }

    Finally, to redo a correct synchronisation, call this :
    \MailPoet\Segments\WP::synchronizeUsers();
    Personnaly, I call this function within the contructor of the lib/Config/Menu.php.

    Hope will help,

    Jean-David

    Thread Starter jdrivard

    (@jdrivard)

    Hi,

    I don’t know why, but it is not resolved at this time. We bought the premium version, in hope that this feature will be corrected in this version, but it is always the same problem!
    In addition to that, the function insertSubscribers has been modified. So, now, we must return an array of inserted subscribers, and I must change my code to repair your fault! It is really unacceptable!

    Hope you will rapidly correct the situation.

    Jean-David

    Thread Starter jdrivard

    (@jdrivard)

    This is the new code for the function insertSubscribers in / lib/Segments/wp.php

    private static function insertSubscribers() {
          global$wpdb;
          $subscribers_table=Subscriber::$_table;
    
          $request=sprintf('
    	INSERT IGNORE INTO %s (wp_user_id,email,status,created_at)
    	SELECT wu.id,wu.user_email,"subscribed",CURRENT_TIMESTAMP()FROM %s wu
    	LEFT JOIN %s mps ON wu.id=mps.wp_user_id
    	WHERE mps.wp_user_id IS NULL ',$subscribers_table,$wpdb->users,$subscribers_table);
    
          if(is_multisite()==true)
          {
              $blogMembersID=get_users(array('blog_id'=>get_current_blog_id(),'fields'=>array('ID')));
              $inID="";
              foreach($blogMembersID as $id)
              {
                  if($inID!="")
                  {
                      $inID.=",";
                  }
                  $inID.=$id->ID;
              }
              $request.=' AND wu.id in('.$inID.')';
          }
    
          $inserterd_user_ids = \ORM::for_table($wpdb->users)->raw_query(sprintf(
              'SELECT %2$s.id, %2$s.user_email as email FROM %2$s
            LEFT JOIN %1$s AS mps ON mps.wp_user_id = %2$s.id
            WHERE mps.wp_user_id IS NULL AND %2$s.user_email != ""
          AND mps.id in('.$inID.')', $subscribers_table, $wpdb->users))->findArray();
    
          Subscriber::raw_execute($request);
    
          return $inserterd_user_ids;
    
      }

    Thanks jdrivard, solved my problem….

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Subscribers in multisite’ is closed to new replies.