Page 1 of 1

S2Member - Restricted Post Title Displays

PostPosted: April 5th, 2011, 10:27 am
by prema
Hi,

The S2Member restricted posts are displaying in my local machine, not in server.
Anybody can tell what could be the prob?

My code is,

Code: Select all
<?php
$debut 
= 0; // The first article to be displayed
$myposts = get_posts('numberposts=-1&offset=$debut');
foreach(
$myposts as $post) :
    $postAccessLevel = ws_plugin__s2member_check_specific_post_level_access($post->ID);
    $postLevel = $postAccessLevel['s2member_level_req'];
    if($postLevel == 2 || $postLevel == 3 || $postLevel == 4 ){
        ?> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>" class="postlist"><?php the_title(); ?></a><br/> <?php
    
}
endforeach;
?>

Re: S2Member - Restricted Post Title Displays

PostPosted: April 5th, 2011, 2:03 pm
by Cristián Lávaque
Hmm...

Did you read this post and do what it recommends for local installations? viewtopic.php?f=4&t=644&p=8255#p8255

If so, did you remove that when you did it in your server?

Also, wouldn't this approach work for what you want? viewtopic.php?f=4&t=2789&p=8381#p8381

Re: S2Member - Restricted Post Title Displays

PostPosted: April 6th, 2011, 1:01 am
by prema
Thank you Lávaque.

The above code is working only before login.
The code stated here viewtopic.php?f=4&t=2789&p=8381#p8381 is working only after login.

So, I used both snippets for before and after login :(

And appending,
define("LOCALHOST", true);
in wp-config.php doesn't shows any difference.

Any other way??

Re: S2Member - Restricted Post Title Displays

PostPosted: April 7th, 2011, 4:53 pm
by Jason Caldwell
Thanks for the great question.
~ and thanks for bringing this to my attention Cristián.

First, please upgrade the latest release of s2Member.

Now, please use this API function:
( documented in: /s2member/includes/functions/api-functions.inc.php )
Code: Select all
/*
API function for Conditionals.
Allows developers to integrate s2Member ( via Themes ).
Is a specific [Category, Tag, Post, Page, or URI] protected by s2Member?

$__id - optional argument. Defaults to current $post->ID in The Loop.
$__type - optional argument. One of: `category`, `tag`, `post`, `page`, `singular`, `uri`. Defaults to: `singular`.
$check_user - optional ( consider the current User? ) defaults to: false.
*/
if (!function_exists ("is_protected_by_s2member"))
    {
        function is_protected_by_s2member ($__id = FALSE, $__type = FALSE, $check_user = FALSE)
            {
                global $post; /* Global reference to $post in The Loop. */
                /**/
                $__id = ($__id) ? $__id : ( (is_object ($post) && $post->ID) ? $post->ID : false);
                $__type = ($__type) ? strtolower ($__type) : "singular";
                /**/
                if ($__type === "category" && ($array = c_ws_plugin__s2member_catgs_sp::check_specific_catg_level_access ($__id, $check_user)))
                    return $array; /* A non-empty array with ["s2member_level_req"]. */
                /**/
                else if ($__type === "tag" && ($array = c_ws_plugin__s2member_ptags_sp::check_specific_ptag_level_access ($__id, $check_user)))
                    return $array; /* A non-empty array with ["s2member_level_req"]. */
                /**/
                else if (($__type === "post" || $__type === "singular") && ($array = c_ws_plugin__s2member_posts_sp::check_specific_post_level_access ($__id, $check_user)))
                    return $array; /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */
                /**/
                else if (($__type === "page" || $__type === "singular") && ($array = c_ws_plugin__s2member_pages_sp::check_specific_page_level_access ($__id, $check_user)))
                    return $array; /* A non-empty array with ["s2member_(level|sp|ccap)_req"]. */
                /**/
                else if ($__type === "uri" && ($array = c_ws_plugin__s2member_ruris_sp::check_specific_ruri_level_access ($__id, $check_user)))
                    return $array; /* A non-empty array with ["s2member_level_req"]. */
                /**/
                return false;
            }
    } 


Based on your example, you might have something like this:
Code: Select all
<?php
$debut 
= 0; // The first article to be displayed
foreach (get_posts ("numberposts=-1&offset=" . $debut) as $post)
    {
        if (!is_protected_by_s2member ($post->ID, "singular", true))
            {
?>
                <a href = "<?php the_permalink(); ?>" rel = "bookmark" title = "<?php the_title(); ?>" class = "postlist"><?php the_title (); ?></a>
                <br />
<?php
            
}
    }
?>

You may also want to have a look at s2Member's built-in documentation that covers Query Conditionals. Please check your Dashboard under: s2Member -> API Scripting -> Query Conditionals.