strangerstudios / pmpro-addon-packages

Charge for access to specific pages or other post types in WordPress. Requires the Paid Memberships Pro plugin.
https://www.paidmembershipspro.com/add-ons/pmpro-purchase-access-to-a-single-page/
25 stars 29 forks source link

Check if post exist and post status of existing post #46

Closed ipokkel closed 4 years ago

ipokkel commented 4 years ago

When a purchased post is binned (trashed) it still appears as a post in the Member Links section on the Membership Account page. If this post does not exist anymore when permanently deleted it returns an error of "Trying to get property 'post_title' of non-object.

Should we maybe check if a post exist and check the post status before listing it on the account page.

ideadude commented 4 years ago

Thanks!

For now, this commit (https://github.com/strangerstudios/pmpro-addon-packages/commit/b30fcad37130c2b6e46a9188b4955cb0ca0c8bf3) makes the following 2 changes to address this:

  1. If a post is not in publish status (deleted, trashed, or draft), it is skipped when showing links in the member links section of the PMPro account page.

  2. If a post is not found (deleted), we will show a message like "Deleted Post with ID#1" on the edit user page.

This may create orphaned data, but I think it's okay in this case. This shouldn't be too likely, and we want the addon package link (via the post id purchased) to be in the DB in case the post comes back or is being used as an indication of access. (Some custom code will check if a user purchased a certain page ID to lock down features of WP, WP plugins, or other apps.)