latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Set default "Post Level Restriction" new post

Home Forums Community Forum Set default "Post Level Restriction" new post

This topic contains 7 replies, has 2 voices. Last updated by  Patrix 3 years, 12 months ago.

Topic Author Topic
Posted: Saturday Jan 12th, 2013 at 9:21 pm #37199
Patrix
Username: s.patrix

Hello,
Is there a way to set the Post Level Restriction to a default level for new posts?

I created 3 levels:
1: Users not registered
2: Free registered users
3: Premium paid members

Now, if I restrict a certain post category, to the level 2, I won’t be able to select the level 1.

So, what I need is to leave all the categories open, and having dropdown to the level 2 as default for the new posts.

How can I accomplish this?

Thanks.

List Of Topic Replies

Viewing 7 replies - 1 through 7 (of 7 total)
Author Replies
Author Replies
Posted: Sunday Jan 13th, 2013 at 12:44 pm #37270
Staff Member

Thanks for your inquiry.

~ We appreciate your patience :-)

I’m sorry. I’m not sure I completely understand the question.

I created 3 levels:
1: Users not registered
2: Free registered users
3: Premium paid members

Only Membership Level #0 is free (i.e. Free Subscribers are at Level #0). All other Membership Levels require paid access. So I’m not sure I understand this exactly. Please feel free to elaborate so that I’ll understand better.

Now, if I restrict a certain post category, to the level 2, I won’t be able to select the level 1.

So, what I need is to leave all the categories open, and having dropdown to the level 2 as default for the new posts.

s2Member does not come with a feature that would allow you to define a default value for the meta-box in the Post/Page editing station. However, you can accomplish what you need to with Category or Tag Restrictions. Have you given Tag Restrictions any thought yet? That’s one of my favorite ways to protect content.

If you’re looking for something MUCH more flexible, I recommend using Custom Capabilities instead of Levels.
Video » s2Member (Custom Capabilities)

Posted: Sunday Jan 13th, 2013 at 1:32 pm #37280
Patrix
Username: s.patrix

Hi again, and thanks for following up on this :)

Ok let me explain in more details:

Here’s the structure I have:

1: Free to eveyone, not registered on WP | Value=”” | Blank
2: Registered Users – default new users on WP | Value=”0″ | Level #0
3: Paid Registered Users – paid membership | Value=”1″ | Level #1

So, I can’t use any Tag/Category/Custom Capability restriction upfront, because otherwise he won’t be able to assign a new post the “Free without registration” or “lower” level.
– Some posts from the same category are

What I was thinking then, is to not block any tag/category and to tell the client to manually assign a level for each article.

And you may ask… so what? That’s the out of the box feature! :P

Well, the issue is because the client doesn’t want to switch the dropdown selection from BLANK to LEVEL 0 for every new post, but he would like to have LEVEL 0 as default for new posts, and in case select the BLANK or LEVEL 1.

Does it make sense?

Thanks.

Posted: Sunday Jan 13th, 2013 at 1:50 pm #37283
Staff Member

Thanks for the follow-up :-)

Gotchya. Well unfortunately, this is not possible with a hook/filter, so it will require some changes to the code directly, which might get wiped out during a future upgrade of s2Member. If you can deal with this, no biggy. I’ll outline it below. If you don’t like this solution, you might consider adding a jQuery-driven script to the Post/Page editing station in the Dashboard, that would set that meta-box drop-down value to a default selection. That way you’re not making changes to the s2Member source code directly, but handling this with JavaScript in the Dashboard instead.

If you’d like to make the changes to the source code, here is what you’ll need to do.

Open this source file please:
/s2member/includes/classes/meta-box-security.inc.php

Find these two snippets of code. One for Pages, another for Posts.

<option value="'.$n.'"'.((in_array($page_id, $pages&#91;$n&#93;)) ? ' selected="selected"' : '').'>
<option value="'.$n.'"'.((in_array($post_id, $posts&#91;$n&#93;)) ? ' selected="selected"' : '').'>

Change these to the following:

<option value="'.$n.'"'.((in_array($page_id, $pages&#91;$n&#93;) || (empty($pages&#91;$n&#93;) && $n === 0)) ? ' selected="selected"' : '').'>
<option value="'.$n.'"'.((in_array($post_id, $posts&#91;$n&#93;) || (empty($posts&#91;$n&#93;) && $n === 0)) ? ' selected="selected"' : '').'>

Please let us know if problems persist :-)

Posted: Sunday Jan 13th, 2013 at 2:14 pm #37287
Patrix
Username: s.patrix

Thanks again Jason,

I like the idea of the Javascript, but for now I have to go with the “dirty” solution… :) running out of time.

I tried to apply the code you wrote, but it seems not to work. When I create a post/page nothing changes.

Any idea why?

Thanks

Posted: Sunday Jan 13th, 2013 at 2:34 pm #37290
Staff Member

Ah. Thanks for reporting back.

So sorry. I wrote that up too quickly. You’re right, it does not work as expected. I will post an updated code sample shortly for you and I’ll see if we can get this into a future release as well.

Posted: Sunday Jan 13th, 2013 at 3:01 pm #37291
Staff Member

Thanks for your patience.

Here is the JavaScript solution I mentioned, which will actually serve you better, since it won’t get wiped out during future updates to s2Member. Please follow the instructions below, and let me know if you have any trouble. This was tested against WordPress v3.5, but should work on any version of WordPress, at least back to v3.2.

Please create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
(NOTE: these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins)
(See also: http://www.s2member.com/kb/hacking-s2member/)

Posted: Sunday Jan 13th, 2013 at 3:52 pm #37299
Patrix
Username: s.patrix

Well,
this works like a charm!!!

And it is much a better solution that what I was expected to complete by today.

Thanks again for your quick support, and for providing the solution. ;)

Viewing 7 replies - 1 through 7 (of 7 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.