Redirect to a page based on a restricted pages ccap

if someone tries to visit a restricted page they are redirected to a signup page.

i would like to have a different page depending on the ccap restriction of they page they try and visit.

eg.

  1. members only content page - restricted to level 1 with ccap premiumyear - redirect to membership signup page

2, members only content page - restricted to level 1 with ccap coachingprogram- redirect to coaching programme sales page

Is this possible?

Yes. See: WP Admin > s2Member > API / Scripting > Membership Options Page Variables

Then see: https://github.com/wpsharks/s2member-kb/issues/131#issuecomment-158311574

Or you can leave the page accessible and instead change its content based on the user’s access using conditionals. That way if the person doesn’t have the access you offer it to him, and if he does you show him the content. https://s2member.com/kb-article/s2if-simple-shortcode-conditionals/

I hope that helps. :slight_smile:

Arrh, I think that helps, but it is a bit above my level. I think the “if” then “else” might help, but I am not really sure how to implement. I just want to do the following. Place some type of code/redirection on all my protected course pages that direct anyone who lands there to that courses specific sales page.

Then you could try the redirection hack I linked to, but make the redirection dynamic using the ccap as the page’s slug.

Create this directory and file: /wp-content/mu-plugins/s2-mop-ccap-redir.php
https://wordpress.org/support/article/must-use-plugins/

<?php
add_action('template_redirect', function () {
    if (empty($_REQUEST['_s2member_vars'])) {
        return; // Nothing to do here.
    }
    if (!is_page(S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_ID)) {
        return; // Nothing to do here.
    }
    @list($restriction_type, $requirement_type, $requirement_type_value, $seeking_type, $seeking_type_value, $seeking_uri)
        = explode('..', stripslashes((string) $_REQUEST['_s2member_vars']));

    if (!empty($requirement_type) && $requirement_type === 'ccap') {
        if (!empty($requirement_type_value) && $requirement_type_value === 'pro') {
            wp_redirect(home_url($requirement_type_value));
            exit;
        }
    }
});

Then you need a page for each ccap, or you’ll get 404s. So if the ccap is “videos” you need a page at yoursite.com/videos

I hope that helps. :slight_smile: