Prevent updating WordPress users data
[MAILPOET-6168]
This commit is contained in:
@ -9,6 +9,8 @@ The argument `$subscriber` is similar to [Add Subscriber](AddSubscriber.md) meth
|
|||||||
|
|
||||||
It returns the updated subscriber. See [Get Subscriber](GetSubscriber.md) for a subscriber data structure.
|
It returns the updated subscriber. See [Get Subscriber](GetSubscriber.md) for a subscriber data structure.
|
||||||
|
|
||||||
|
If the subscriber is a WordPress user, the method does not allow updating `email`, `first_name` and `last_name`. It needs to be updated in the `wp_users` and MailPoet will synchronise the new values.
|
||||||
|
|
||||||
## Arguments
|
## Arguments
|
||||||
|
|
||||||
| Argument | Type | Description |
|
| Argument | Type | Description |
|
||||||
|
@ -177,6 +177,12 @@ class Subscribers {
|
|||||||
// filter out all incoming data that we don't want to change, like status ...
|
// filter out all incoming data that we don't want to change, like status ...
|
||||||
$defaultFields = array_intersect_key($defaultFields, array_flip(['email', 'first_name', 'last_name', 'subscribed_ip']));
|
$defaultFields = array_intersect_key($defaultFields, array_flip(['email', 'first_name', 'last_name', 'subscribed_ip']));
|
||||||
|
|
||||||
|
if ($subscriber->getWpUserId() !== null) {
|
||||||
|
unset($defaultFields['email']);
|
||||||
|
unset($defaultFields['first_name']);
|
||||||
|
unset($defaultFields['last_name']);
|
||||||
|
};
|
||||||
|
|
||||||
if (empty($defaultFields['subscribed_ip'])) {
|
if (empty($defaultFields['subscribed_ip'])) {
|
||||||
$defaultFields['subscribed_ip'] = Helpers::getIP();
|
$defaultFields['subscribed_ip'] = Helpers::getIP();
|
||||||
}
|
}
|
||||||
@ -201,7 +207,7 @@ class Subscribers {
|
|||||||
APIException::FAILED_TO_SAVE_SUBSCRIBER
|
APIException::FAILED_TO_SAVE_SUBSCRIBER
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->subscribersResponseBuilder->build($subscriberEntity);
|
return $this->subscribersResponseBuilder->build($subscriberEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,10 +810,24 @@ class SubscribersTest extends \MailPoetTest {
|
|||||||
$this->assertEquals('new value', $result['cf_' . $customField->getId()]);
|
$this->assertEquals('new value', $result['cf_' . $customField->getId()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateSubscriberWordPressUser() {
|
||||||
|
$subscriber = $this->subscriberFactory->create();
|
||||||
|
$subscriber->setWpUserId(4);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$result = $this->getApi()->updateSubscriber($subscriber->getId(), [
|
||||||
|
'email' => 'newemail@example.com',
|
||||||
|
'first_name' => 'New Name',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals($subscriber->getEmail(), $result['email']);
|
||||||
|
$this->assertEquals($subscriber->getFirstName(), $result['first_name']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testUpdateSubscriberFailsForNonExisting() {
|
public function testUpdateSubscriberFailsForNonExisting() {
|
||||||
$this->expectException(APIException::class);
|
$this->expectException(APIException::class);
|
||||||
$this->expectExceptionMessage('This subscriber does not exist.');
|
$this->expectExceptionMessage('This subscriber does not exist.');
|
||||||
|
|
||||||
$this->getApi()->updateSubscriber('non existing', [
|
$this->getApi()->updateSubscriber('non existing', [
|
||||||
'email' => 'newemail@example.com',
|
'email' => 'newemail@example.com',
|
||||||
'first_name' => 'New Name',
|
'first_name' => 'New Name',
|
||||||
|
Reference in New Issue
Block a user