Page 1 of 1

Class problem inside loop...

Posted: Wed Mar 02, 2011 7:11 pm
by wpcs_phil
Hello all,

Thanks in advance for reading. I'm building a member importer (rebuild of a busy site) but am having problems getting my members to import into my newsletter plugin. It handles the first one fine, but then just stops on the second. Recreated a stripped down version...

Code: Select all

<?php
$emails = array('test1@bigfishadwords.com', 'test2@bigfishadwords.com', 'test3@bigfishadwords.com');
foreach ($emails as $email) {
	if (process_wnp_optin($email, 1)) { 
		echo 'Added: ' . $email . '<br>';
	} else {
		echo 'Not added: ' . $email . '<br>';
	}
}

function process_wnp_optin($email, $list_id) {
	global $Subscriber; 
	$wpMail = new wpMail();
	$data = array('email' => $email, 'list_id' => array($list_id));
	if ($Subscriber -> optin($data, true)) { return true; } else { return false; }
}
?>
I can post the whole subscriber class too if that helps, but have identified the line where it stops working...

Code: Select all

$this -> data[$this -> model] = $this -> array_to_object($data);
$data has the right info in it, and the array_to_object call works and does just that, still get the same error even if I create my own object to feed to it.

Anyway someone can help me out from this info? Happy to put in more of the code if needed, but I'm not that familiar with classes (though trying to break free from procedural), so maybe it's something simple like not creating a new wpMail object every time or something, though I've tested everything I can think of.

Any help is most appreciated. Day 3...

Thanks,

Philip