Protected Content Solution (something other than FETCH_COOKIES_ENABLED)
-
Please reference this issue for some back story.
The issue began when PDF Templates stopped working in conjunction with a support plugin called Awesome Support. Eventually we were able to narrow it down to the following line which was added to my
wp-config
file in order to grant the PDF plugin access to restricted content:define('FETCH_COOKIES_ENABLED', true);
.I have premium content which is restricted by a Woocommerce extension called Memberships.
Before implementing the suggested
define('FETCH_COOKIES_ENABLED', true);
line in mywp-config
file, the PDF Templates plugin could not access the content, because it does not inherit the current user. The above line successfully allowed PDF Templates to access the content, BUT with the Awesome Support plugin installed, for some reason that same line caused any PDF request to time out and get a 502 response from the server. We tested this in multiple environments, and even though we weren’t able to understand why that line causes that behavior, we were able to isolate the issue to that one line.So we need another solution for granting the PDF Templates plugin access to the restricted content. Perhaps there is another method of passing the current user role to the plugin?
Unfortunately I don’t quite understand how this all works, so I’m really hoping you can offer some advice on how to get around the above issue.
To summarize:
I need the members of my site to be able to export certain restricted pages and post type as PDFs, but I can’t use the FETCH_COOKIES_ENABLED solution, because it breaks the PDF functionality when the Awesome Support plugin is enabled.
Let me know what you think.
Thanks in advance!
– Colin
UPDATE:
So my code to restrict access to content and PDFs is as follows:
// Initial Membership Conditional Check: $user_id = get_current_user_id(); if( wc_memberships_is_user_active_member( $user_id, 'session-plan' ) || current_user_can('manage_options') ) { // ... show the restricted content to WP Admins or registered members as defined the // WooCommerce Memberships plugin } else { // ... display "Restricted" message to non members }
The above conditional checks work for my php/html templates, however they do not work for the PDF templates I’ve created. Doesn’t matter whether the current user in a logged-in Admin or a registered member, they always get the “Restricted” message.
So I thought, well, the PDF Templates plugin must not inherit the current user session data, so it has no idea whether a user is logged in or what role or capabilities they have. So what if I didn’t check for user role/capability but instead checked the referrer and make sure that the only people who can see the PDF page are those that have accessed it from a protected/restricted page.
So I ran the following conditional checks instead:
// Initial REFERER Conditional Check: $ref = $_SERVER['HTTP_REFERER']; if( $ref == 'https://my-domain.com/protected-page-one/' || $ref == 'https://my-domain.com/protected-page-two/' ) { // ... show the restricted content only to users who followed a link from one of // the two URLs listed above... } else { // ... display "Restricted" message anyone who tries to access the page directly or from an unprotected // page... }
Unfortunately this did not work either ?? I cleared all my caches, hard reloaded several times, and tried accessing a pdf page from both of the above URLs. I still got the “Restricted” message!
I guess I don’t understand how the PDF Templates plugin works… Can you explain to me how the
/pdf
url endpoint works? How is the server request made? Is there anyway of getting the URL referrer from within a PDF template? If I can’t access the current$user
object, and I can’t access the global$_SERVER
object from within a PDF template, is there any other way I can conditionally serve PDF content to my site’s visitors/users? Even if I could just check whether they were logged in, and/or what user role they were, that would solve my problem.Let me know what’s possible.
Thanks!
- The topic ‘Protected Content Solution (something other than FETCH_COOKIES_ENABLED)’ is closed to new replies.