Page 1 of 1

Can't restrict <!--more--> or anything before it

PostPosted: November 27th, 2011, 11:12 am
by ggandg
For example,

ABC [s2If current_user_can(access_s2member_level0)] DEF <!--more--> GHI [/s2If]

I've noticed this returns "ABC DEF Read the rest of this post..." for non-logged in users. If I remove <!--more--> non-logged in users get only ABC.

Why is <!--more--> breaking any restrictions before and including the <!--more--> itself? "More" is critically important for controlling long posts and it's also a good point to start restricting content. I want place various restrictions immediately before <!--more--> but they don't have any effect. Is there a work-around or am I missing something??

Re: Can't restrict <!--more--> or anything before it

PostPosted: November 27th, 2011, 7:30 pm
by Cristián Lávaque
Thanks for the observation, I'll mention this to Jason.

In the meantime, have you tried this?

Code: Select all
[s2If current_user_can(access_s2member_level0)] DEF [/s2If]
<!--more-->
[s2If current_user_can(access_s2member_level0)] GHI [/s2If]


Also, what are your settings for alt. views? WP Admin -> s2Member -> Restriction Options -> Alt. Views
http://www.s2member.com/content-restric ... ble-video/

Let me know if it helps.

Re: Can't restrict <!--more--> or anything before it

PostPosted: November 28th, 2011, 5:44 am
by ggandg
My Alt Views are not restricted (I already checked that thinking it might be an issue). Also, I researched how Wordpress/Buddypress deals with <!--more--> and with excerpts but nothing obvious jumped out at me.

The problem with your suggestion above is that non-logged in users will get "ABC Read the rest of this post...".

I don't want non-logged in users (or alternatively, low level members) to ever get as far as the link generated by <!--more-->. I want non-logged in users to get "ABC You must register and log in to read the rest of this post." and I want logged in users to get "ABC DEF Read the rest of this post... GHI"

I use the code below to generate a "login nag message" for non-logged in users and to control my blog posts:

ABC [s2If current_user_can(access_s2member_level0)] DEF <!--more--> GHI [/s2If]
[s2If !current_user_can(access_s2member_level0)] You must register and log in to access the rest of this post. [/s2If]

Here is the big problem as stated previously: Non-logged in users get "ABC DEF Read the rest of this post..." instead of "ABC You must register and log in to access the rest of this post."

When non-logged in users click the <!--more--> link or individual post link and are directed to the corresponding single post (example mysite.com/blogpostnumber220/#-more220 or mysite.com/blogpostnumber220) they actually get "ABC You must register and log in to access the rest of this post." which is what they should have gotten in the first place! So... it's critical for Jason to know this problem occurs on my homepage/main blog page (WP->Options->Reading is set to "Your latest posts"). Archive pages and blog pages also suffer from the <!--more--> problem. Only single posts restrict things properly because Wordpress does not generate <!--more--> links on single posts.

I'm surprised the <!--more--> problem hasn't come up sooner. To me, it's a major problem and seems like a potential a security issue since it definitely breaks any shortcode restrictions placed around it (except on single posts). Please let me know what Jason says about this. FYI I'm running WP 3.2.1 with BP 1.5.1 and the problem appears identical in both Firefox and IE. Thanks in advance!

Re: Can't restrict <!--more--> or anything before it

PostPosted: November 29th, 2011, 3:10 am
by Cristián Lávaque
I see. Yeah, the more tag breaks the conditional, even in PHP. I'll wait for Jason's input.

Re: Can't restrict <!--more--> or anything before it

PostPosted: November 30th, 2011, 5:20 pm
by Jason Caldwell
Sorry, perhaps I've missed something, but I'm not seeing a problem here.
~ Please let me know if this makes sense or not.

First off, this is incorrect with ANY type of Shortcode in WordPress:
Code: Select all
ABC [s2If current_user_can(access_s2member_level0)] DEF <!--more--> GHI [/s2If]

The <!--more--> tag is a separating marker between your Excerpt and the remaining content after your Excerpt. So placing a <!--more--> tag into your content means that you are breaking this content apart into two separate chunks of data for WordPress to use in different ways.

In any Archive View, WordPress will look at these two chunks separately ( which is bad in this case ).
Code: Select all
ABC [s2If current_user_can(access_s2member_level0)] DEF
Code: Select all
GHI [/s2If]
So your Shortcode Conditional is left broken ( i.e. the Shortcode is incomplete ) when these chunks are separated. It will only work as intended, when the full content body is parsed together as one piece, not when it is separated.

So instead, you should do something like this.
Code: Select all
ABC [s2If current_user_can(access_s2member_level0)]DEF[/s2If] <!--more--> GHI

As I see it, this is not a bug. Rather, it has to do with your placement of the <!--more--> tag. Just remember to structure your content so that WordPress can make sense of each section independently, when it needs to ( i.e. in any Archive View ).

Re: Can't restrict <!--more--> or anything before it

PostPosted: December 9th, 2011, 10:33 am
by ggandg
Jason/Cristian,

Here is what I think you may be missing...

The desired output/flow is this:
Non-logged in users get ABC "You must be logged in to access the rest of this post"
Logged in users get ABC DEF "Read the rest of this post" GHI

In my code, a non-logged in user NEVER gets as far as the <!--more--> link and instead gets a nag message "Log in to access the rest of this post".

ABC [s2If current_user_can(access_s2member_level0)] DEF <!--more--> GHI [/s2If]
[s2If !current_user_can(access_s2member_level0)] You must register and log in to access the rest of this post. [/s2If]

In your code, a non-logged in user ALWAYS gets the <!--more--> link, even though it would lead him to the full post, which is restricted to him (don't forget GHI is restricted).

ABC [s2If current_user_can(access_s2member_level0)]DEF[/s2If] <!--more--> GHI

Here is the problem... it's not a matter of the placement of the <!--more--> tag. If <!--more--> can't be restricted, then it will ALWAYS appear where it is placed, and it will essentially function as a dead link for unauthorized users because the full post is restricted to them. Users should get a nag message at the point in a post where their privileges end, not "Read the rest of this post..." which leads them to the full post which they are unauthorized to view.

How can you possibly get the output/flow shown below without being able to restrict "DEF <!--more--> GHI" as a whole?

Non-logged in users get ABC "You must be logged in to access the rest of this post"
Logged in users get ABC DEF "Read the rest of this post" GHI

Re: Can't restrict <!--more--> or anything before it

PostPosted: December 9th, 2011, 11:27 am
by Jason Caldwell
Thanks for the follow-up.
I understand the frustration, and I understand now what you're trying to accomplish.

Just to make a quick point. The <!--more--> tag can NEVER be inside content surrounded by a Shortcode. It's not an s2Member thing, it's related to what I mentioned earlier about WordPress. Breaking content apart inside a Shortcode with the <!--more--> tag will always result in a broken Shortcode.

Now, I think I understand what you're trying to accomplish. You want to make sure the "continue reading..." link is NOT presented in certain cases; and there is a way to accomplish this with WordPress®.


The usual method does not allow this:
Code: Select all
This is the excerpt.
<!--more-->
This is after the more tag.
WordPress will convert <!--more--> into a clickable hyperlink, leading a visitor to the rest of the Post ( i.e. what comes after the <!--more--> tag. )


The more advanced way:
If you look at the documentation here: http://codex.wordpress.org/Customizing_ ... _each_post
You will find that it's also possible to supply your own text for the <!--more--> tag like this:
Code: Select all
This is the excerpt.
<!--more Continue Reading... -->
This is after the more tag.
So now the link will say: "Continue Reading...", or whatever you specify.


Forcing WordPress® NOT to provide a link to the remaining content:
Code: Select all
This is the excerpt.
<!--more -->
This is after the more tag.
Notice the single space here? It tells WordPress® NOT to link to the remaining content ( i.e. there is no more link, nothing for it to say ).


Taking this a step further with s2Member's [s2If /] Conditionals:
Code: Select all
This is the excerpt.
<!--more [s2If current_user_can(access_s2member_level1)]continue reading...[/s2If][s2If current_user_cannot(access_s2member_level1)][/s2If] -->
This is after the more tag.
If they have Level#1 access, we show "continue reading...". If not, we show nothing.


If you're going to do this repeatedly. You might grab this plugin and create a Quicktag to insert this into your Posts automatically. See: http://wordpress.org/extend/plugins/add ... reenshots/

Re: Can't restrict <!--more--> or anything before it

PostPosted: December 10th, 2011, 11:02 am
by ggandg
Wow... S2If's inside the <!--more--> tag itself. That is the solution I was looking for... a way to ensure authorized members get the more desired <more> link while ensuring unauthorized members get a nag message such as "You must upgrade your account to access the rest of this post".

I'm surprised this issue did not surface earlier. Any sensible webmaster would want to avoid annoying low level members with a <more> link that leads them to unviewable/unauthorized material. In almost every circumstance I can think of, a friendly nag message should appear where a members privileges ends.

Re: Can't restrict <!--more--> or anything before it

PostPosted: December 10th, 2011, 8:27 pm
by Cristián Lávaque
I'm glad that solves it for you. It is a great tip, I didn't know it either. :)

By the way, if the link pointed to a page that the user doesn't have access to, that's when he's sent to the Membership Options page to sell him the access, or using conditionals to sell him the access in the very page he can't view. I guess this works fine for most and that's why the "more" link edit had not be asked about earlier.