Prevent updating WordPress users data

[MAILPOET-6168]
This commit is contained in:
Pavel Dohnal
2024-07-25 14:29:36 +02:00
committed by Jan Lysý
parent 2a10a5817b
commit 7be9ade5f4
3 changed files with 24 additions and 2 deletions

View File

@ -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.
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
| Argument | Type | Description |

View File

@ -177,6 +177,12 @@ class Subscribers {
// 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']));
if ($subscriber->getWpUserId() !== null) {
unset($defaultFields['email']);
unset($defaultFields['first_name']);
unset($defaultFields['last_name']);
};
if (empty($defaultFields['subscribed_ip'])) {
$defaultFields['subscribed_ip'] = Helpers::getIP();
}

View File

@ -810,6 +810,20 @@ class SubscribersTest extends \MailPoetTest {
$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() {
$this->expectException(APIException::class);
$this->expectExceptionMessage('This subscriber does not exist.');