Most probably the code you are using is trying to access logged in user’s data before init action. Since the current user is set on ‘set_current_user’ hook’ which is just before init, any function trying to access current user data should be called on or after init action.
Hope that helps.
Reference: https://codex.wordpress.org/Plugin_API/Action_Reference
thanks @sbrajesh
i’m working on the translation, not coding actually. 😉
I just wonder on this new message and the comments:
function bp_setup_current_user() {
// If the current user is being setup before the “init” action has fired,
// strange (and difficult to debug) role/capability issues will occur.
Is this message viewed by the user on front-end ? Or only in the admin ?
And if roles/caps will occur, the super-admi is also affected i guess. I presume this was tested by the devs, so advice about what kind of incident this can give would be great to know.
[resolved]
Is harmless. This sends only a php notice when debug mode is on.
Hi @chouf1
sorry I could not follow up.
That message is intended for debugging the site and will be visible if WP_DEBUG is set true as you have already noticed.
It is there to aid the developers/site admin to properly use functions related to current user.
@sbrajesh,
For help or guidance on the french BP support forum, it’s as important for me to undestand such error messages clearly. Thank you again !
I wouldn’t say it’s entirely harmless.
If you need to check something like user roles right after you load your plugin but before continuing, you can do something like this:
`
function something_check_access () {
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$role = array_shift($roles);
if($role == ‘administrator’ ) {
// add your hooks here
}
}
add_action(‘init’, ‘something_check_access’);`