Prevents WP subscribers' first/last name from being erased when updating

subscription
This commit is contained in:
Vlad
2017-08-24 13:19:42 -04:00
parent d92b1f57bd
commit 8a8108b41d
2 changed files with 27 additions and 1 deletions

View File

@ -488,7 +488,10 @@ class Subscriber extends Model {
unset($data['segments']);
}
$data = self::setRequiredFieldsDefaultValues($data);
// if new subscriber, make sure that required fields are set
if(!$subscriber) {
$data = self::setRequiredFieldsDefaultValues($data);
}
// get custom fields
list($data, $custom_fields) = self::extractCustomFieldsFromFromObject($data);

View File

@ -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() {
$data = array(
'email' => 'test@example.com',