• Resolved cannon303

    (@cannon303)


    Hi is there a way to only show content on pages which have been protected? I need to add a side nav but it should only appear on protected pages and not on public pages. Even if the site visitor is logged in, that side nav should still not appear on pages that haven’t been ticked with the “Yes, Protect this content.” button in the page editor.

    As far as I can see I can only check if someone is logged in with:

    if(SwpmMemberUtils::is_member_logged_in()) {
        $auth = SwpmAuth::get_instance();
        $accstatus = $auth->get('account_state');
        if($accstatus !== 'expired' && $accstatus !== 'inactive'){
    
    		echo 'show content';
    
    	}
    }

    what I really need is something like this:

    if(SwpmMemberUtils::is_member_logged_in()) {
        $auth = SwpmAuth::get_instance();
        $accstatus = $auth->get('account_state');
        if($accstatus !== 'expired' && $accstatus !== 'inactive'){
    
                 if(page_is_protected()){
    		echo 'show content';
                 }
    
    	}
    }

    Thanks
    https://wordpress.org/plugins/simple-membership/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter cannon303

    (@cannon303)

    Sorted:

    global $post;
    $access_ctrl = SwpmAccessControl::get_instance();
    if ($access_ctrl->can_i_read_post($post)){
    
      $acc = SwpmProtection::get_instance()->is_protected($post->ID);
    
      if($acc){
    	echo 'show content';
    	}
    }
    Plugin Support mbrsolution

    (@mbrsolution)

    I am glad you found a solution. Thank you for sharing your custom PHP code.

    Regards

    Plugin Author wp.insider

    (@wpinsider-1)

    I think the examples we have at the following URL should have helped:

    https://simple-membership-plugin.com/simple-membership-miscellaneous-php-tweaks/

    If you think those examples weren’t enough then let me know and I will add your one to that page also.

    Thread Starter cannon303

    (@cannon303)

    Yes I checked that page and couldn’t find a solution. What my code does is firstly check if the site visitor is a logged in member and has access to the page but then checks if the page is a protected page or a publicly accessible page.

    It’s useful because I have a members section on my site and only want the members side navigation to appear on pages in the members section.

    Another way around it would have been to create a different page template for the members pages but then that would have meant my site administrator having to remember to select the right template as well as clicking the “Yes, Protect this content.” button.

    P.S. I imagine my code probably could be better written but hope it helps.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Only showing content if page is protected’ is closed to new replies.