strangerstudios / paid-memberships-pro

WordPress membership plugin to restrict access to content and charge recurring subscriptions using Stripe, PayPal, and more. Fully open source. 100% GPL.
https://www.paidmembershipspro.com
Other
452 stars 352 forks source link

PMPro disrupting Wordpress REST API #448

Open produktive opened 7 years ago

produktive commented 7 years ago

A feature of the current core WordPress (no PMPro involved at all) is the REST API. This includes a method to retrieve a post by its ID. The syntax for performing this is as such: example.com/wp-json/wp/v2/posts/<id> where <id> is an integer assigned to the post. This should return information about the post with the ID specified.

If you do not know the ID of the post, you can also retrieve a post by its “slug name.” The syntax for this method is: http://example.com/wp-json/wp/v2/posts?slug=<slug-name> where <slug-name> is a unique string that refers to a specific post. Again, these are standard features that come with the current installation of WordPress.

You can not retrieve posts with the slug method on pages that are protected by PMPro. I have a post category called “Learning Center” and if I create a post and include the “Learning Center” category, the page is now protected by PMPro (as expected). I can even retrieve this protected page with the WordPress API by retrieving with the method. When accessing example.com/wp-json/wp/v2/posts/<id> where <id> is the ID of a protected page, I get a JSON response that includes a message of “This content is for Learning Center members only” (which is the expected result). However, when I attempt to retrieve the page by “slug”: example.com/wp-json/wp/v2/posts?slug=<slug-name> I get no information returned. It is a blank page. This is not an expected result and I expected to get the same page as when I used the <id> method.

Additionally, when attempting to get a list of all posts of a specific category, you can use this method: example.com/wp-json/wp/v2/posts?category=<category-id>

However, when attempting this method with my “Learning Center” category, which is protected by PMpro, I get a null response, same as when I attempt to get a slug page that is protected by PMPro.

eighty20results commented 7 years ago

IIRC (been a couple of months since I wrote it), you'll need to install the PMPro/Rest API add-on (available from: https://eighty20results.com/wordpress-plugins/ )

produktive commented 7 years ago

You had me excited there for a second, but I registered on your site and downloaded the plugin, but it just extends the functions of PMPro, it doesn't fix the disruptions that PMPro caused to the core Wordpress REST API, specifically the 'posts' endpoint in my case.

eighty20results commented 7 years ago

Based on my investigation for a thread in our support forum, this seems more like a REST API issue than a PMPro issue (see the write-up/summary I included in the support forum): https://www.paidmembershipspro.com/forums/topic/pmpro-is-disrupting-api-calls-to-posts/

eighty20results commented 7 years ago

I've updated the REST API plugin to fix the issue with slug based post/page access via the REST v2 API.

produktive commented 7 years ago

Thank you. I know that this is your private plugin/side-project, but shouldn't this bug fix be pulled into the main PMPro plugin? Everyone who uses the PMPro plugin will potentially be experiencing this problem and it seems unusual to have to download your third party plugin to fix the issue. I appreciate you creating a solution, truly.

eighty20results commented 7 years ago

It's been submitted as a pull request before it was included in the REST API plugin.

The availability in the plugin is because a) REST API support was something Jason wanted to keep outside of the core PMPro plugin for now (as he figures out what he wants to do) and b) availability of the workaround/fix without having to wait for a new release of PMPro (which there recently was a couple of so we're likely to try and hold off for a while to let things stabilize).