User roles are changing automatically

I am facing a strange issue.Some of my user roles are changing automatically.I searched in the whole project and canno

I am facing a strange issue. Some of my user roles are changing automatically. I searched in the whole project and cannot find the location from where user roles are changing. So I added the following code in my functions.php

add_action( 'set_user_role', function( $user_id, $role, $old_roles ){
    mail('[email protected]','User role is changed from admin',
         'This mail is sending from set_user_role hook in functions line 2450. The user id is '.$user_id.
         'The loggedin user is '.get_current_user_id()
         );
}, 10, 3 ); 

I am getting the emails with changed userids. but the currently logged in user is showing as 0. So I assume the function is not calling from admin and the following function is running somewhere in my function.

$user->add_role( 'userrole' );

But I cannot find the function $user->add_role(); in my project. Is this hook is called in any other cases? Please help me to solve this.

I am facing a strange issue. Some of my user roles are changing automatically. I searched in the whole project and cannot find the location from where user roles are changing. So I added the following code in my functions.php

add_action( 'set_user_role', function( $user_id, $role, $old_roles ){
    mail('[email protected]','User role is changed from admin',
         'This mail is sending from set_user_role hook in functions line 2450. The user id is '.$user_id.
         'The loggedin user is '.get_current_user_id()
         );
}, 10, 3 ); 

I am getting the emails with changed userids. but the currently logged in user is showing as 0. So I assume the function is not calling from admin and the following function is running somewhere in my function.

$user->add_role( 'userrole' );

But I cannot find the function $user->add_role(); in my project. Is this hook is called in any other cases? Please help me to solve this.

Share Improve this question asked Aug 27, 2018 at 4:30 Edison LazarEdison Lazar 31 bronze badge 0
Add a comment  | 

1 Answer 1

Reset to default 2

Good catch with the action, catching the instance.

You might be able to add a debug_backtrace() to trace it back to the calling functions, and their calling functions, to see how you actually get there.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745437984a4627697.html

相关推荐

  • User roles are changing automatically

    I am facing a strange issue.Some of my user roles are changing automatically.I searched in the whole project and canno

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信