memberful / memberful-wp

Better membership software for WordPress.
https://memberful.com
42 stars 15 forks source link

Check whether member is deleted before calling `Memberful_User_Map#map` #352

Closed julianfssen closed 1 year ago

julianfssen commented 1 year ago

To-do: https://3.basecamp.com/3293071/buckets/5610905/card_tables/cards/6411081563


When calling Memberful_User_Map#map, it is possible for the compiler to raise a Undefined property warning when operating on deleted members. A few samples of the error are linked in the to-do.

This happens because the payload for deleted members from the Memberful API only returns the member id and a deleted property.

The errors happen in the following lines:

https://github.com/memberful/memberful-wp/blob/fde48841f661045be0e423ede192d7ff0a12d2a4/wordpress/wp-content/plugins/memberful-wp/src/user/map.php#L22

https://github.com/memberful/memberful-wp/blob/fde48841f661045be0e423ede192d7ff0a12d2a4/wordpress/wp-content/plugins/memberful-wp/src/user/map.php#L188-L194

This PR fixes the warning by checking whether the member is deleted in Memberful_User_Map#map.

If a WP_User with the given member id exists, we return it immediately.

If it doesn't exist, we return a WP_Error which is caught in memberful_wp_sync_user:

https://github.com/memberful/memberful-wp/blob/fde48841f661045be0e423ede192d7ff0a12d2a4/wordpress/wp-content/plugins/memberful-wp/src/syncing.php#L45

I'm open to feedback or suggestions on fixing this differently. Thank you!

julianfssen commented 1 year ago

Good morning, @mrhead ! Patrik, do you see any gotchas or potential bugs for this approach of mapping deleted members?