Call custom WP header using ccaps?

Hi All,

I banged away for over an hour on this and couldn’t find an answer.

What I’d like to do is use some conditional PHP code within one of my WP templates to call either one of two header PHP files that are a part of my WP theme. I’d like to use ccaps to control the if/then

So for instance, if the user has access to the ccap “optin”, they’d get the equivalent of this: <?php get_header(); ?>

If the user does not have access to the ccap “optin” they’d get this: <? include ("header-generic.php'); ?>

I tried fiddling with the second item in Example 9 here (https://s2member.com/kb-article/s2if-simple-shortcode-conditionals/) but couldn’t get it to work. Google searches turned up empty too.

Any ideas? Thanks!

Try this hack, it’s easy to turn it from “shortcode” to PHP".

Thanks for the link. That’s my challenge…I don’t know PHP very well or how to convert from shortcode to PHP. Any help would be greatly appreciated.

Instead

[s2If current_user_can(access_s2member_ccap_wmay2016)]
Gift for everyone, who have ccap "wmay2016".
[/s2If]

use

if(current_user_can('access_s2member_ccap_wmay2016')) {
    echo 'Gift for everyone, who have ccap "wmay2016".';
}

as shown at “s2Member -> API / Scripting -> Advanced/PHP Conditionals”.

Got it! Here’s what I wound up with:

<?php if(current_user_can('access_s2member_ccap_wmay2016')) { include('header.php'); } else { include ('header-generic.php'); } ?>

Works beautifully. Thanks for your help

My pleasure :slight_smile: Great that job is done!