最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

User roles are changing automatically

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论