$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>users - Is it possible to access plugin data from a custom feed template?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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

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

Share Improve this question edited Mar 1, 2019 at 17:37 markcbain asked Mar 1, 2019 at 17:31 markcbainmarkcbain 3332 silver badges10 bronze badges 2
  • What's the plugin function you're trying to use within the conditional you posted? – Taruc Commented Mar 1, 2019 at 23:00
  • It's a Memberpress function to check if the user has a particular membership plan. – markcbain Commented Mar 4, 2019 at 16:07
Add a comment  | 

1 Answer 1

Reset to default 1

The solution, for anyone else interested, was to clear cookies and the cache:

clean_user_cache($current_user->ID);
wp_clear_auth_cookie();
wp_set_current_user($current_user->ID);
wp_set_auth_cookie($current_user->ID, true, false);
update_user_caches($current_user);
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';
}
Post a comment

comment list (0)

  1. No comments so far