• Hi, I tried searching everywhere for weeks now and couldn’t get ideal answer via pre-purchase support.

    I am running a security company and want my employees to post to a blog page via email. They will be using contact form plugin combined with Postie plugin. No backend is allowed for them. I need to add ccaps to every post as if it was entered manually in restriction meta box.

    I used this code in /mu-plugins/ that I found on your old forums:

    add_action ("wp", "my_custom_capabilities");
    
    function my_custom_capabilities ()
    	{
    	if(has_tag("client_a") && !current_user_can ("access_s2member_ccap_client_a"))
    		{
    		header ("Location: ".S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
    		exit();
    		}
    	}

    It indeed redirected me when I clicked on protected post when logged in with the account that does not have the required ccaps. The problem here is that it does not protect the title of the post and its excerpt from the blog page.

    When I enter ccaps manually via restrictions metabox from backend, it just hides the post entirely for all users without ccap “client_a”

    This is critical for my business model because I do not want client B to see security guard submitted activity logs(posts) for client A, client C, client D, etc. I want them to feel like that feed is exclusively theirs and see titles of posts with client_a tags /ccaps.

    Thank you in advance and let me know if anything from what I asked is not clear.

    https://wordpress.org/plugins/s2member/

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must modify the main WP query to not include these posts, if the member/visitor can not have access to them. Not so easy, but possible.

    Plugin Author JasWSInc

    (@jaswsinc)

    See also: Dashboard → s2Member → API / Scripting → Advanced/PHP Query Conditionals

    Plugin Author JasWSInc

    (@jaswsinc)

    See also: Dashboard → s2Member → Restriction Options → Alternative View Protection

    @eshamis I got your note privately. I’ll respond shortly.

    Thread Starter eshamis

    (@eshamis)

    Thank you,

    The Alternative View Protection is enabled for ALL wordpress queries by default. This was one of the first things I checked.

    Do I need to use this code?

    <?php
    if ($tags = get_the_tags ())
        {
            foreach ($tags as $tag)
                {
                    if (!is_permitted_by_s2member ($tag->name, "tag"))
                        continue;
                    /* Skip it. The current User/Member
                        CANNOT access this Tag Archive,
                    or any Posts/Pages with this Tag. */
                }
        }
    ?>

    Or this one?

    <?php
    if ($posts = get_posts ())
        {
            foreach ($posts as $post)
                {
                    if (!is_permitted_by_s2member ($post->ID, "post"))
                        continue;
                    /* Skip it. The current User/Member
                    CANNOT access this particular Post. */
    
                    $post_or_page_id = $post->ID;
                    if (!is_permitted_by_s2member ($post_or_page_id, "singular"))
                        continue;
                    /* The "singular" attribute can check both Pages and Posts the same time.
                    So if this was actually a "Page", that would be valid, w/ "singular". */
                }
        }
    ?>

    And do I insert it in the same s2hacks file or elsewhere? Sorry, I have very limited code knowledge.

    Thank you.

    Thread Starter eshamis

    (@eshamis)

    I also already tried replacing this code `header (“Location: “.S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
    exit();`
    with continue;

    Didn’t work.

    Plugin Author JasWSInc

    (@jaswsinc)

    @eshamis In your first post, you are applying a custom routine that bypasses anything that s2Member stores in the DB and would be aware of; i.e., it is a custom routine that you’re adding. Thus, if you apply what you posted originally, neither of those Query Conditionals will be able to interpret what you’re actually doing with the has_tag() check. s2Member is simply unaware of this check that you’re making, because it’s not in your s2Member configuration, it’s a part of something custom that you wrote.

    What I suggest is that you use the meta box provided by s2Member in the Post/Page editing station and use it to require specific Membership Levels and/or Custom Capabilities. Then, keep s2Member’s Alt. View Restrictions on and that should do it 🙂 You won’t need any custom code at all then.

    On the other hand, if you go with what you posted first (i.e., the has_tag() check that is entirely custom), you will need to move that check into “The Loop” and alter your WordPress theme to use that custom Loop. Referencing: https://codex.wordpress.org/The_Loop

    <?php
    if ( have_posts() ) {
    	while ( have_posts() ) {
    		the_post(); 
    
    		if (has_tag('client_a') && !current_user_can ('access_s2member_ccap_client_a'))
                        continue;
                    /* Skip it. The current User/Member
                    CANNOT access this particular Post. */
    
    	} // end while
    } // end if
    ?>

    Similar… this uses get_posts() instead.

    <?php
    if ($posts = get_posts ())
        {
            foreach ($posts as $post)
                {
                    if (has_tag('client_a', $post) && !current_user_can ('access_s2member_ccap_client_a'))
                        continue;
                    /* Skip it. The current User/Member
                    CANNOT access this particular Post. */
                }
        }
    ?>
    Thread Starter eshamis

    (@eshamis)

    @jaswsinc I read about the loop and tried to insert the code in idex.php with no success, because the location is probably wrong.

    Meta Box is not an option because my security staff wont have access to backend of the site.

    I believe I found a work around. I can assign a new membership level for each new user and then manually remove access to all lower levels with any user role plugin or similar. Then in s2member in tag restrictions.

    The problem with this work around is that I can’t raise the limit of 100 membership levels. I tried this code:
    <?php add_filter("ws_plugin__s2member_max_levels", function(){ return PHP_INT_MAX; }); ?>
    And tried to insert desired value:
    <?php add_filter("ws_plugin__s2member_max_levels", function(){ return 120; }); ?>
    This code brakes my site, did I do something wrong here? Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Cannot add ccap with tag.’ is closed to new replies.