get_currentuserinfo
-
get_currentuserinfo got deprecated
It must to be changed to wp_get_current_user
-
I also received the notice. get_currentuserinfo is deprecated since WordPress 4.5 and there should be a check if wp_get_current_user exists before using it.
I suggest following change of ga_current_user_is function in google-analyticator.php @ line 1288:
/** * Determines if a specific user fits a role **/ function ga_current_user_is($roles) { if ( !$roles ) return false; global $current_user; // Fix for deprecated get_currentuserinfo since WordPress 4.5 if(function_exists('wp_get_current_user')) { $user = wp_get_current_user(); // wp_get_current_user returns WP_User object, so there is no need to create new WP_User instance if ( !$user->ID ) { return false; } } else { get_currentuserinfo(); $user_id = intval( $current_user->ID ); if ( !$user_id ) { return false; } $user = new WP_User($user_id); // $user->roles } foreach ( $roles as $role ) if ( in_array($role, $user->roles) ) return true; return false; }I just uploaded the change on my site and the notice goes away.
Thanks! It solves for me 😉
Getting the same error/notice here.
Getting the same error. Is there going to be an update soon?
I would rather not edit core files.M.
It’s now a week since the update to WordPress 4.5 and no reaction… Seems that the plugin is no longer maintained.
@andydegroo Have you added some code?
My code reads like this:
/** * Determines if a specific user fits a role **/ function ga_current_user_is($roles) { if ( !$roles ) return false; global $current_user; get_currentuserinfo(); $user_id = intval( $current_user->ID ); if ( !$user_id ) { return false; } $user = new WP_User($user_id); // $user->roles foreach ( $roles as $role ) if ( in_array($role, $user->roles) ) return true; return false; }All I had to do is change get_currentuserinfo() to wp_get_current_user().
@mvanboordt google-analyticator.php is not a core file. It is part of Google Analyticator plugin.
@edi Goetschel
I guess Noah has better things to do with his time and this plugin doesn’t bring in referrals to his main business – SumoMe. That would be a good reason for not spending time on this plugin.I’ve added the fix in a way that doesn’t break in older WordPress versions. However, that is not necessary, because wp_get_current_user function was added in WordPress 2.0.3.
Some parts of the original plugin code are not needed, because wp_get_current_user creates complete WP_User object with roles. So the function code for WP >= 2.0.3 would be:
/** * Determines if a specific user fits a role **/ function ga_current_user_is($roles) { if ( !$roles ) return false; $user = wp_get_current_user(); if ( !$user->ID ) { return false; } foreach ( $roles as $role ) if ( in_array($role, $user->roles) ) return true; return false; }@andydegroo I see what you mean but I ment the core files of the plugin.
The principle is the same. Change the code and loose the changes after an update.@andydegroo Thank you for the explanation.
And I can understand that there are better things to do than adopt changes in the core of WordPress that can break every few month a plugin or a theme.
The topic ‘get_currentuserinfo’ is closed to new replies.