Is there any way to get a user role history? Let's say I added a new user with the role Subscriber. Now I manually updated the role to "Editor", and then "Administrator".
Is there any way to get the history of the user with date/time?
For e.g:
User 1 was a "Subscriber" on 25/01/2023
User 1 updated to "Editor" on 27/01/2023.
User 1 updated to "Administrator" on 29/01/2023.
I know we can fetch the current display role
There's nothing in core WordPress that records this history. There are some popular history plugins you might try. https://wordpress.org/plugins/search/history/
The current role settings for each user are stored in wp_usermeta in an entry with meta_key = 'wp_capabilities'. For example, an editor will have this meta value:
array( 'editor' => true )
Recording changes to those metadata values will give you the history if you decide to do this with your own plugin code. You can hook the 'update_user_meta', 'add_user_meta', and 'delete_user_meta' actions to intercept changes.
Related
I have setup WSO2 IS 5.3.0 with an Active Directory as secundary user store.
I am able to find users from the AD, and view their user profile in the management console.
I would now like to modify the list of attributes that are displayed in the user profile screen. I already found documentation saying I should edit the corresponding claims, setting the attribute 'Supported by Default' to true for the desired claims, and also setting the desired number in the 'Display Order' attribute. So I modified some local claims, but these changes have no effect on the User Profile screen: I keep getting the same original list of attributes (First Name, Last Name, Organisation, Country, ...). Can anyone tell me what I could be doing wrong ?
The secondary user store is configured with the following settings:
screenshot AD configuration
This is the user profile screen for my user account in the AD.
An example of a claim modification is for the local Country claim where I set the 'Supported by Default' to false and changing the 'Display Order' from 4 to 0. When opening the user profile screen again, the content remains unchanged (country field is still there).
Another example is when I try to add another claim in the user profile screen, such as the local Date of Birth claim, by setting the 'Supported by Default' to true and changing the 'Display Order' from 0 to 4. Again, nothing changes in the user profile screen either (date of birth field is not present).
For the Organisation claim that is present in the user profile screen, but that is currently empty, I added an attribute mapping to the 'company' attribute that exists in the AD, but when looking at the user profile screen again, this field remains empty.
Let me know if any further details are needed (I would have added some more screenshots, but as a new user on this forum, I'm currently limited to 2 links in my posts...).
In the end, I did a complete reinstallation (including setting up an oracle DB as carbon DB instead of the H2 DB), and this time everything works correctly. Something must have gone wrong during the first installation.
I am new to Drupal. How do I get all user data in a single query or function, including extra fields like middle name, phone # from:
Configuration » People » Account settings
I want all the records of all the users, including the extra fields listed above. How can I achieve this?
If the fields are attached to the user : user_load();
Something like :
$user = user_load(1); // 1 = uid of admin user
drupal_set_message($user->field_middle_name); // print a message with your user custom field named middle_name.
If you got many users to load, use user_load_multiple, the perfs will be better.
I use Drupal 7 and would prefer to do so but if I need to use Drupal 6 I will. I have a Drupal 7 site that I allow "advisors" to create authenticated users. I am an admin on the site so I see and can do everything. All that an "advisor" can do is create and edit authenticated users. Is there a way to make a view that displays the users that the particular advisor has created while the advisor is logged in?
If you don't understand what I'm saying let me put it this way. I am the admin of the site so I can do everything. I created a user role called advisor. There's also an authenticated role for users. Advisors can create authenticated users. So I have Advisor 1. Advisor 1 created 10 users. I also have Advisor 2. Advisor 2 created 3 users. I'd like a page (more than likely built with views - and I've used views before on other sites so I'm familiar with them) - I'd like a page that Advisor 1 could go to once logged in and it would display all of the 10 users that they created. Advisor 1 wouldn't see the users that Advisor 2 create.
Is this possible? Any help on this would be greatly appreciated. Thank you in advance.
I have implemented something similar and I can give you some guidelines.
First of all drupal 7 doesn't store the information of the creator of the users.
So, in order to track this you will need to attach a custom field to the user to keep this information.
In such case you ll have to make sure that every creator can insert only himself in this field and not anyone else or you 'll have to find an automated way to fill it in.
I suggest you use field permission module for setting permissions to this field (users probably should not even have view, creators should not be able to change it etc ) and computed field module for automatically populate the field (eg creator_field) upon creation for example with the uid of the creator.
Finally when creating the view you could add contextual filtering by using the logged in user on the creator_field.
You should also have a look at Organic Groups. I haven't use it but might be helpful
Hope it helps.
Updated
Add
global $user;
$entity_field[0]['value'] = $user -> uid;
to the Computed Code (PHP) in the computed field settings and store the value as integer in "Database store settings". Then in your view you should add a view of user with contextual filter of creator_field. In the contextual filter settings you must set "provide default value" -> "User ID from logged in user" in the "WHEN THE FILTER VALUE IS NOT IN THE URL" section.
This could be done relatively easily in Drupal 7 by adding a field to the user profile that points back to the user creator (using the Entity Reference module). Profile2 could offer a shortcut to making this field available on a profile, though if this is the only customization that you need to add to your profiles, it would be cleaner to do this in a custom module.
A view (Views module) could be configured to output a list of users with the current logged in user as the creator.
You'll also need to add similar logic for user_access to allow/restrict profile editing (if the current user is the user referenced in the profile). A permissions hook also could be useful if you plan to have different admin levels.
The Tokens module should work to insert this value for the new user, by inserting the current user into the field. Or you can do this before the user is saved. It would go a little something like this:
function mymodule_user_presave(&$edit, $account, $category) {
if ($account->is_new) {
global $user;
$created_by = $user->uid;
$edit['created_by'] = $created_by;
}
}
Good luck.
Intro info:
I have a Custom Post Type (CPT) called Service.
I am already connecting users to this CPT using the plug-in 'Posts 2 Posts', this is a many to many relation, and these users connected to the CPT represent the 'team' of said Service.
Alright so here's the headscratcher:
Now I want to create a custom field in the CPT Service, which will be the Director of the Service. Say a field called 'Director' in which the value is a User.
Ideally, the value of the field Director is a User, not a string representing the user name or anything like that.
I have no idea how to start tackling this issue and some brightness on the subject would be strongly appreciated.
Thank you!
save it as post_meta. e.g if you have the user email:
$user = get_user_by( 'email');
update_post_meta($serviceid, '_director', $user->ID);
If you are setting this up in the admin section you can add a meta box and attach a action to save_posts to save a html field where you select a user. Google add_meta_box, there are a load of tutorials on this.
I have 2 roles in my drupal site. One is admin. The uid is 1. If I visit the profile of another user, say a user with uid 2, is it possible to get that value. I did not want to retrieve it from the url(user/2). Is there any other way to get a user information like uid, role etc while visiting profile of another user. I think $user can be used to get the details of current user only.
To get the details from user id when you are in the profile page of that user use the $account variable. More details in the user-profile.tpl.php template inside ROOT/modules/user.
Example, get user id: $account->uid;