Extra blank line added after an s2Member shortcode

Hi Cristián,

Within the last couple of weeks, I’ve noticed an issue where an extra blank line is now added after an s2Member shortcode in the following type of situation …

Suppose that a page contains the following text and shortcodes:

Text for everyone.

[s2If !current_user_can(access_s2member_level1)]

* Bullet for non-members.

[/s2If][s2If current_user_can(access_s2member_level1)]

* Bullet for members.

[/s2If]Text for everyone.

Until recently, the above page would display to a member as follows:

Text for everyone.

* Bullet for members.

Text for everyone.

However, now the above page displays to a member as follows:

Text for everyone.


* Bullet for members.

Text for everyone.

I’m not sure exactly when this issue started - I noticed it about a week ago, so it might have been after the recent s2Member update or after the recent Wordpress update. I’ve tried disabling all plugins except s2Member (i.e. so that the only active plugin is either 1) “s2Member Framework”, or 2) “s2Member Framework” and “s2Member Pro”), and this issue is still present.

It might not sound like a big issue, but in practice it’s a pain because there are now hundreds of pages on my website that include extra blank lines (which looks very messy). It would obviously be interesting to hear if any other s2Member users have experienced this same issue (just in case there’s some reason why this issue is unique to my website).

If this issue is caused by something that has recently changed in s2Member (or something that has recently changed in Wordpress), then it would be really good if there’s a fix that would revert back to the previous treatment of paragraph spacing.

Please note that I realise that when using s2Member shortcodes, the author should not normally leave a space (or a paragraph mark) between the shortcode and the subsequent text. For example, within the above example page, I’ve written “[/s2If]Text for everyone.” with no space (or paragraph mark) between “[s2If]” and “Text”. However, this issue occurs when a shortcode is followed by a bullet, where’s it’s not possible to leave no space.

Thanks,
Steve

That’s your theme or editor…

Hi Felix,

Thanks very much for the suggestions.

I’m using a “Twenty Twelve” child theme, but this issue is still present even if I switch to a completely different theme (e.g. “Twenty Twenty-One”, “Twenty Twenty”, “Astra”, etc).

I’m using the “Classic Editor” plugin, but this issue is still present even if I disable all plugins (except s2Member).

Thanks,
Steve

Is it a line break or is it a margin space from one of the items (above or below)?

Hi Steve.

I see. That’s interesting. I could reproduce it in my installation. I know that s2 didn’t change in that area. I don’t know if something changed in the shortcode parsing or maybe the editor itself.

I can’t say that it’s the wrong behavior, either… You have an extra line before the s2If, and there’s an empty line inside the s2If block too.

You can remove one of the empty lines. For example before the s2If:

Text for everyone.
[s2If !current_user_can(access_s2member_level1)]

* Bullet for non-members.

[/s2If][s2If current_user_can(access_s2member_level1)]

* Bullet for members.

[/s2If]Text for everyone.

Or remove the extra lines inside the s2Ifs, and have the empty lines outside, for example:

Text for everyone.

[s2If !current_user_can(access_s2member_level1)]
* Bullet for non-members.
[/s2If][s2If current_user_can(access_s2member_level1)]
* Bullet for members.
[/s2If]

Text for everyone.

Or like this:

Text for everyone.

[s2If !current_user_can(access_s2member_level1)]
* Bullet for non-members.
[else]
* Bullet for members.
[/s2If]

Text for everyone.

An option for not having to edit all your posts, though, would be to filter the shortcode’s content, to remove the empty line at the beginning, but keeping a trailing one because you put the following public text without a line after the closing s2if…

You can try the ‘ws_plugin__s2member_sc_if_conditionals’ filter.

I tested this a bit, and found that it’s not an empty line what’s causing the problem. The post parser seems to be getting confused with the shortcodes, and in the second one (apparently not the first one) it adds a closing P tag </p> at the very beginning. This is outside of s2 and you can avoid it using the empty lines a different way, as I mentioned above. But to help you, I wrote this simple fix for your particular case:

<?php
add_filter('ws_plugin__s2member_sc_if_conditionals', function($condition_content) {
  return preg_replace('~^</p>~', '', $condition_content);
});

You can put that in a php file in this folder /wp-content/mu-plugins, for example.

I hope that helps. :slight_smile:

2 Likes

Hi Cristián,

Thank you so much for the php fix - it works perfectly (i.e. it has removed all of the extra spaces, and my website now appears exactly the same as it did until recently).

Apologies that I’ve probably used the wrong terminology (as I don’t have any programming experience). For info, when I gave the following example …

Text for everyone.

[s2If !current_user_can(access_s2member_level1)]

* Bullet for non-members.

… that corresponded to me typing the following into the Wordpress “Visual” editor (with the “Classic Editor” plugin activated) …

“Text for everyone” then “[Enter key]” then “[s2If !current_user_can(access_s2member_level1)]” then “[Enter key]” then “Bullet for non-members” (note: then applying the “Bulleted list” button to the latter text).

As such, using the “Visual” editor, I can recreate your 1st example by typing “Text for everyone” then “[Shift + Enter key]” then “[s2If !current_user_can(access_s2member_level1)]” then “[Enter key]” then “Bullet for non-members”.

However, I can’t recreate your 2nd example, because when I try to use “[Shift + Enter key]” between the shortcode and the subsequent bulleted text, it applies the bullet to the shortcode (which seems to cause problems).

However, as said above, your php fix works perfectly - so I’ve applied it, and I’ll continue to use “[Enter key]” between the shortcode and the subsequent bulleted text.

I’m very curious as to why no-one else on the forums seems to have had a problem with this extra space - I’ve no idea what I must be doing differently!

Thanks very much again,
Steve

2 Likes

Ah, I never use the visual editor. The paragraphs handling is a pain. Also, I sometimes use PHP in my content for different reasons including testing, and the visual editor breaks it all. So I tend to forget that some things might not be possible there when I try it, sorry about that.

I’m very glad that the hack helped you! :smiley:

Seems quite innocent to implement it in the release, but since I have no idea how it may break what others have, and I don’t see others mentioning it, I’ll leave it as it is. But I now have this post to point someone to if I get this mentioned again.

2 Likes

I use the visual editor most of the time, and it seems to be working well as it is right now. Today I tested the conditionals with [else] and they work fine too, even having everything in the same line without line breaks to display different segments of texts inside of a single paragraph.

2 Likes

Thanks very much - that’s useful for me to know that you’re also using the visual editor, but not experiencing this same issue with the extra space.

That was not the point of my comment. This is a community and you’re not the only user. If the plugin were to be changed to fit your demand but break the way items are displayed for everybody else it would not be a good thing for the rest of us.

Hi Sim,

I know this is a community - that’s why I asked for a fix to be applied to s2Member if something has recently changed in s2Member or Wordpress (and not if this issue is unique to my website). Your earlier reply helps to show that users (other than me) aren’t experiencing this same issue (which is also indicated by the lack of replies from other users) - so of course I wouldn’t expect (or want) a fix to be applied to s2Member in such a situation.

Thanks,
Steve

2 Likes

I thought you were being passive aggressive, sorry. I have Asperger’s and sometimes I don’t understand if people mean what they say or if there’s something between the lines. Please accept my apologies for my misunderstanding.

2 Likes

Thanks for your reply Sim - that’s no worries. I know what you mean - I find it difficult enough to read people I know face-to-face, and it’s far harder (sometimes impossible) with strangers online.

2 Likes

Thanks! I can’t read people anywhere, hence why I make mistakes all the time :laughing:

I try my best but we can only go so far when we can’t see certain nuances in communication.

I wish you get everything working well on your site(s).

2 Likes

Thanks Sim :smiley:

1 Like