Hide members content after Ajax page update

Hi all,

I need little help with hiding content from non-members. my issue is described here

To be breif I need a help with finding the s2 function then hide non-members content and rerun it in code snippet

Any help greatly appreciated!

jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
/**
* data.view_unique_id (string) The View unique ID hash
* data.effect (string) The View AJAX pagination effect
* data.speed (integer) The View AJAX pagination speed in miliseconds
* data.layout (object) The jQuery object for the View layout wrapper
*/
//HERE fire the s2 Plugins function again.

});

Well, s2M is server side script, a s2M function can not be started with JS script (which is client side). You should re-think the concept…

hm, to be more specific - we’re talking about the js that works inside Wordpress installation and calls Wordpress s2members plugin. So the initial question can be like this “what is the function in s2members wordpress plugin that hides non-members content”…

the js that works inside Wordpress installation and calls Wordpress s2members plugin

That is not how s2Member works. s2Member is powered by PHP (server-side, as Krum said) and not by JavaScript client-side.

what is the function in s2members wordpress plugin that hides non-members content

Again, that’s not how s2Member works. It doesn’t “hide” content. It redirects a non-authorized user so that they are not permitted access to where that content is shown.

You seem to be under the misapprehension that content exists in the HTML that s2Member subsequently hides from view. That’s not what s2Member does. It ensures instead that the HTML is never generated for unauthorized users in the first place.

Sorry for that, but you’re wrong. I’m not going to complain about this - my site works and s2 membership plugin hides everything. If you READ my initial description and link mentioned - you find out how it works. My questions is - how to implement s2 api into this code

<?php
attach_s2member_query_filters();
query_posts("posts_per_page=5");
if (have_posts()):
	while (have_posts()):
		the_post();
	# Protected content will be excluded automatically.
	# (based on the current User's Role/Capabilities)
	endwhile;
endif;
wp_reset_query();
detach_s2member_query_filters();
?>    


jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
/**
* data.view_unique_id (string) The View unique ID hash
* data.effect (string) The View AJAX pagination effect
* data.speed (integer) The View AJAX pagination speed in miliseconds
* data.layout (object) The jQuery object for the View layout wrapper
*/
//HERE fire the s2 Plugins function again.
});

What do you think that means?

Please be more specific.

test case

hide some woocommerce products from guests, for that I use S2Member plugin, and that works perfect exept 1 situation.
Link to a page where the issue can be seen:

  1. scenario when everything ok : go to the https://soapmaker.pro/product-category/face-care/flower-water (products with sku 207830, 207825, 207810 are hidden and thats OK)).
  2. go to the https://soapmaker.pro/product-category/face-care THEn go to the page #2 and you can see them on that page in first column (pagination is done AJAX, but with no checking for S2 capability - hide product from guests). I thing the case is to write some js check under the JS section of Filter chapter for WordPress Archive (please see screen 2)

I expected to see:
hidden sku 207830, 207825, 207810
Instead, I got: I can see them for scenario 2

In the code snippet you quoted, the line “# Protected content will be excluded automatically” appears. I am asking you what you think it means.

This statement didn’t works - in my site configuration and combination of plugins Toolset (which runs AJAX update) & S2 membership plugin. Please read my test case carefully.

You told me that I was wrong, and then quoted a snippet of code that’s actually in PHP that shows that I’m actually right. Reading what you want to do doesn’t change the fundamentals of how s2Member works. Two people have now told you that. But still you persist. Well, it’s up to you.

I’m fully agree with you. But you didn’t help me. Just trying to prove HOW it should work. I’m telling you - there is REAL test case which I need to fix, unfortunally I’m not very strong in php | js.

Please read my test case carefully if you wish. to help. If not - please stop commenting this.

Sorry, but you don’t get it. The point is that what you are trying to do won’t ever work. It doesn’t matter how much you repeat what you want. It won’t work.

Instead of trying to say how you want the code to work, you would be much better off explaining what, in practice, you are trying to achieve. In other words, what is it that you are trying to do for your members? If you explain that, rather than insisting on a specific use of code, then you might get some suggestions. But your code idea has no chance of success.

Hi Dima.

I know you’re trying to make it work and it’s frustrating that it doesn’t yet. It’s like that sometimes with customizations. I’ll do what I can to help you, k? But let me first ask you a few things so we have a clearer picture.

I read the thread in the page you linked to. So you want to hide the link to a certain product if the user doesn’t have the required access, is that right?

Well, if you do it with JavaScript, a savvy user would be able to still get the link, because it’d have already been served to the browser and then JS just hides it. It could be done, you can look at s2’s variables in the JS to check the user’s access and write your JS to hide the link or not. See: WP Admin > s2Member > API / Scrpiting > JS/API Globals and PHP/API Constants

It’s also possible, and generally much better, to just not send the link at all to the browser. You can customize your link with a conditional that checks the user’s access, and adds the link based on that. If your WooCommerce page allows shortcodes, you can use the s2If shortcode. If you can use PHP, then it’s possible with a PHP condition, of course. See: https://s2member.com/kb-article/s2if-simple-shortcode-conditionals/

The queries thing you saw in the s2 code, is related to this restriction: WP Admin > Restriction Options > Alternative Views

Does that help? :slight_smile:

All the s2M’s tasks are done at the server, long before the JS (and AJAX in it) runs at the browser. So, there is no way you to set AJAX update with s2M, without custom code. Seems you try to create that, but you must be aware how WP and s2M works… Note, that s2M works “inside” WP, so your AJAX responding script at the server has to run WP and then s2M, to be possible to use s2M’s API. Please check this KB article: Building An API Notification Handler.

A way to restrict access to a Woo page, would be using s2’s URI restriction. See: WP Admin > s2Member > Restriction Options > URI

I hope that helps. :slight_smile:

Dima,

If all you’re trying to do is to keep a specific piece of content from appearing within a web page based on a user’s membership level or CCAPs, then take a look at simple shortcode conditionals. That said, if you keep insisting that we tell you how to make this work the way you want it to work you might as well give up since as you have been told repeatedly, that is not the way s2Member works.

Unfortunatelly for you guys that work my way. In case I change the output method for shop catalogue page from AJAX to full page reload - products with (s2 levels => 1) are hidden for non-logged or level 0 users. The only case - it is AJAX update.

Hi Dima.

I’m sorry, I didn’t understand your last reply. Could you explain some more?

Did you read my two replies above? I tell you there a couple of ways in which you can do it, if I understood correctly what you want.

I look forward to your update. :slight_smile: