Prevents WP subscribers' first/last name from being erased when updating
subscription
This commit is contained in:
@ -488,7 +488,10 @@ class Subscriber extends Model {
|
|||||||
unset($data['segments']);
|
unset($data['segments']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if new subscriber, make sure that required fields are set
|
||||||
|
if(!$subscriber) {
|
||||||
$data = self::setRequiredFieldsDefaultValues($data);
|
$data = self::setRequiredFieldsDefaultValues($data);
|
||||||
|
}
|
||||||
|
|
||||||
// get custom fields
|
// get custom fields
|
||||||
list($data, $custom_fields) = self::extractCustomFieldsFromFromObject($data);
|
list($data, $custom_fields) = self::extractCustomFieldsFromFromObject($data);
|
||||||
|
@ -1025,6 +1025,29 @@ class SubscriberTest extends \MailPoetTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItSetsDefaultValuesForNewSubscribers() {
|
||||||
|
$result = Subscriber::createOrUpdate(
|
||||||
|
array(
|
||||||
|
'email' => 'new.subscriber@example.com'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect($result->getErrors())->false();
|
||||||
|
expect($result->first_name)->isEmpty();
|
||||||
|
expect($result->last_name)->isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItDoesNotSetDefaultValuesForExistingSubscribers() {
|
||||||
|
$existing_subscriber_data = $this->data;
|
||||||
|
$result = Subscriber::createOrUpdate(
|
||||||
|
array(
|
||||||
|
'email' => $existing_subscriber_data['email']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect($result->getErrors())->false();
|
||||||
|
expect($result->first_name)->equals($this->data['first_name']);
|
||||||
|
expect($result->last_name)->equals($this->data['last_name']);
|
||||||
|
}
|
||||||
|
|
||||||
function testItExtractsCustomFieldsFromObject() {
|
function testItExtractsCustomFieldsFromObject() {
|
||||||
$data = array(
|
$data = array(
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
|
Reference in New Issue
Block a user