To correct the issue with Types, open types/embedded/includes/usermeta-post.php
and find this line:
$user_role = isset($user_id->roles) ? array_shift($user_id->roles) : 'subscriber';
Change it to:
$tmp_roles = isset( $user_id->roles ) ? $user_id->roles : array( 'subscriber' );
$user_role = array_shift( $tmp_roles );
The problem is that the plugin is using array_shift()
to manipulate $user_id->roles
(note to dev: should probably change that variable to $user
). This is manipulating the user object that my plugin and others will need to use later. It’s an easy mistake to make because the purpose is to get the first array value. array_shift()
does that wonderfully. However, the function also removes the first array value from $user_id->roles
, so when the user object gets used later, the first value (i.e., first role) is removed.
Side Issue #1: I’m not the Types developer and don’t know all the code, but this looks to me like there might be another related issue. The code seems to also be assuming that a user must have a role, so it’s assigning subscriber
there for users without a role. That could be problematic for people who intentionally want to have users on their site without a role. Like I said, I’m not that familiar with the plugin code, but I figured I’d post it here in the off-chance that someone has an issue with that.
Side Issue #2: The code in that function only recognizes the first role of a user as the “user role”. WordPress allows any number of roles to be assigned to a user. This can be 0 roles or 100 roles. I’m not sure what the ultimate goal for the wpcf_admin_userprofile_init()
function is, but only recognizing the first role means that your code won’t properly work when a user has multiple roles.