Skip to main content
added 34 characters in body; edited title
Source Link
markcbain
  • 333
  • 2
  • 10

Is it possible to access plugin data from a custom feed template?

I'm trying to use current_user_can in a custom feed template (created using add_feed) to check if they have a particular Memberpress membership plan in order to access the feed, but while I can get other user data (e.g. $current_user->user_login outputs the username), I can't use the plugin function.

At the moment, instead of showing the feed, I'm just echoing some test content, as follows:

if( current_user_can( 'mepr-active', 'memberships:1,2' ) ) {         
  echo 'Hi ' . $current_user->user_login . '! You are a member';
} else {
  echo 'Hi ' . $current_user->user_login . '! You <strong>not</strong> a member';
    }

I'm guessing this is something to do with the order WordPress loads things. Could someone confirm? Is there any way around this? (I can get it working if I add the same code to a page template within the theme.)

Thanks

Is it possible to access plugin data from a feed template?

I'm trying to use current_user_can in a feed template to check if they have a particular Memberpress membership plan in order to access the feed, but while I can get other user data (e.g. $current_user->user_login outputs the username), I can't use the plugin function.

if( current_user_can( 'mepr-active', 'memberships:1,2' ) ) {         
  echo 'Hi ' . $current_user->user_login . '! You are a member';
} else {
  echo 'Hi ' . $current_user->user_login . '! You <strong>not</strong> a member';
    }

I'm guessing this is something to do with the order WordPress loads things. Could someone confirm? Is there any way around this? (I can get it working if I add the same code to a page template within the theme.)

Thanks

Is it possible to access plugin data from a custom feed template?

I'm trying to use current_user_can in a custom feed template (created using add_feed) to check if they have a particular Memberpress membership plan in order to access the feed, but while I can get other user data (e.g. $current_user->user_login outputs the username), I can't use the plugin function.

At the moment, instead of showing the feed, I'm just echoing some test content, as follows:

if( current_user_can( 'mepr-active', 'memberships:1,2' ) ) {         
  echo 'Hi ' . $current_user->user_login . '! You are a member';
} else {
  echo 'Hi ' . $current_user->user_login . '! You <strong>not</strong> a member';
    }

I'm guessing this is something to do with the order WordPress loads things. Could someone confirm? Is there any way around this? (I can get it working if I add the same code to a page template within the theme.)

Thanks

Source Link
markcbain
  • 333
  • 2
  • 10

Is it possible to access plugin data from a feed template?

I'm trying to use current_user_can in a feed template to check if they have a particular Memberpress membership plan in order to access the feed, but while I can get other user data (e.g. $current_user->user_login outputs the username), I can't use the plugin function.

if( current_user_can( 'mepr-active', 'memberships:1,2' ) ) {         
  echo 'Hi ' . $current_user->user_login . '! You are a member';
} else {
  echo 'Hi ' . $current_user->user_login . '! You <strong>not</strong> a member';
    }

I'm guessing this is something to do with the order WordPress loads things. Could someone confirm? Is there any way around this? (I can get it working if I add the same code to a page template within the theme.)

Thanks