Here’s the function w/comments explaining what I’m trying to do:
// Add filter to send custom email after updates volunteer profile form
add_filter ( 'edit_profile_success', 'email_after_edit', 10, 3 );
// this function only applies to this form
function email_after_edit($request, $form_name, $user_id){
// if are submitting information for the form on this page: https://tnmentalhealth.dev.opcdev3.nehmedia.com/edit-volunteer-profile/; I know this works
if ( $form_name == 'support-line-volunteer-profile-update' ){
// Get user ID, user email address, and user's role
$user = get_user_by('id', $user_id);
$user_id = get_current_user_id();
$user_email = $user->user_email;
$user_meta = get_userdata($user_id);
// Everything up to here works
$user_roles = $user_meta->roles;
$user_roles = implode(', ', $user_meta->roles);
return $user_roles;
// This is what I want to do: If the user role is User type 1 or User type 2, queue up one version of the email. It the user is type 3, send version 2 of the email
if ( $user_roles == ('user_type_1' || 'user_type_2')) {
$to = $user_email;
$subject = "User types 1 or 2";
$message = '<p>Dear User type 1</p>';
// If the user role is User type 3, send a different version of the email
} else if ($user_roles == ('user_type_3')){
$to = $user_email;
$subject = "User_type_3";
$message = '<p>Dear User type 3,</p>';
}
// User email and email headers
$headers = "Content-type: text/html";
// compile email and send ?"
wp_mail($to, $subject, $message, $headers);
}
}
The site is on WP 5.4.1, PHP 7.2. I’m using WP Mail SMTP to send the emails.
I really appreciate any help or advice. Thank you in advance!
Lisa
]]>get_userdata does not exist for me.
when I do:
if(function_exists(‘get_userdata’)) {
echo “get_userdata exists!<br />\n”;
} else {
echo “get_userdata does NOT Exist!!!<br />\n”;
}
it says the latter… it does NOT exist.
WP is current.
Why does it not exist?
in the codex, it does not say it has been replaced.
So why cannot I use it now?
How do I get the role of a user I found their ID with by their email address?
]]>We’re getting the following error when get_posts()
is used anywhere in the dashboard.
It seems that LearnPress tries to hook into the parse_query
hook and wants to use get_userdata()
function. However this function is not existent at time of execution.
Uncaught Error: Call to undefined function get_userdata() in /app/public/wp-content/plugins/learnpress/inc/user/class-lp-user-factory.php:144
Maybe you can have a look at this. Thank you.
]]>I have no caching plugin and I get the same result from local development server, remote development server and live server.
The directory page does not reflect any changes made to the user profile it is as though it is being cached somewhere. It make no difference whether I update the profile using the native WordPress admin page or using Gravity Forms User Registration update form.
I have tried
$bio = get_user_meta( $user_id, 'description', true );
and also
$all_user_data = get_userdata($user_id);
$bio = $all_user_data->description;
Both return old data not the updated data from the profile.
]]>Just before the end, I have this message
Notice: Trying to get property of non-object in /www/wp-content/plugins/postie/postie-functions.php on line 2080
ln 2079 : $user = get_userdata('1');
ln 2080 : $myname = $user->user_nicename;
I have no user with the ID 1 so $user is false.
And in the function, $myname is not use.
Maybe it’s a old code.
https://www.ads-software.com/plugins/postie/
]]>These three functions can all take a user ID and be used to retrieve things like Display Name and Email Address. It all seems a little redundant.
Does anyone have any general advice for where/how each would be best used?
I’m writing a plugin that sends an email to all editors when a post is published (a lite custom plugin). I need to retrieve names and email addresses for editors. I decided to use get_userdata(), since get_the_author_meta() doesn’t make sense semantically (I’m not dealing with a post, just the fact that a user has the ‘Editor’ role), and dealing with the nested arrays of get_user_meta() is giving me a headache.
]]>I am a inexperienced programmer and I am stuck trying to create a json to retrieve user and usermeta data. I read all the documentation even the controllers, models and example files.
I think models/author.php is close to what I want but I don’t know how to continue.
?How can I test this author.php model?, ?how could I personalize it for my purpose? (retrieve user data and metadata given it one ID or email).
Any help is welcome. Thank you.
Regards.
David.
https://www.ads-software.com/extend/plugins/json-api/
]]>I’m in need of some help!
I’m trying to create a simple shortcode that will show a user’s display name based on the user ID you insert (or default to the currently logged in user if no ID is provided). Below is a similar shortcode I’ve created to do this for a user’s avatar:
<?php
function avatar_shortcode( $atts ) {
global $current_user;
$user_id = ( is_user_logged_in() ? $current_user->ID : NULL );
extract( shortcode_atts( array(
‘id’ => $user_id,
), $atts ) );
return get_avatar( $id );
}
add_shortcode(‘avatar’, ‘avatar_shortcode’);
?>
[avatar] displays the currently logged in user’s avatar and [avatar id=”1″] display’s the avatar for the user with an ID of 1 and so on. This is exactly what I am looking for to show a user’s display name. Something where [display-name] will show the currently logged in user’s display name and [display-name id=”1″] will show the display name for the user with an ID of 1 and so on.
Please any help will be greatly appreciated!
Thanks,
Jon
wp_dropdown_users(array(‘name’ => ‘users1’)); ?> used to create a drop down called users1 of all users with their display_name and used that as the value in the drop down. With the current update the value has changed the the user_ID. I did not see any way to update the value option of the drop down function.
My solution was to pass the ID and use it through get_userdata( $userid ); but i thought there should be an update/patch-note made to wp_dropdown_users( $args );
OLD CODE PRE UPDATE
<select class=”” id=”user1″ name=”user1″>
<option value=”Amy”>Amy</option>
<option value=”Andie”>Andie</option>
<option value=”Danielle”>Danielle</option>
</select>
New Code
<select class=”” id=”user1″ name=”user1″>
<option value=”24″>Amy</option>
<option value=”32″>Andie</option>
<option value=”68″>Danielle</option>
</select>
$authors = array();
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->ID);
if(!empty($hide_empty)) {
$numposts = count_user_posts($user->ID);
if($numposts < 1) continue;
}
$authors[] = (array) $user;
}
$adminauthors = array();
foreach ($blogadmins as $blogadmins) {
$user = get_userdata($blogadmins->ID);
if(!empty($hide_empty)) {
$numposts = count_user_posts($user->ID);
if($numposts < 1) continue;
}
$adminauthors[] = (array) $user;
}
With get_userdata now being deprecated, what’s the best way to get the metadata for each author in the array?
]]>