Home › Forums › Front End PM PRO › Trying to get id from $authordata
- This topic has 3 replies, 1 voice, and was last updated 4 years, 4 months ago by lia.spoerl.
- AuthorPosts
- August 15, 2021 at 2:31 pm #43512lia.spoerlParticipant
Hi,
So with the below code I can get the other users nicename depending on their role and then show their name and a link:
add_action( ‘fep_display_after_reply_message’, function(){
$authordata = get_userdata( fep_get_message_field( ‘mgs_author’ ) );if( in_array( ’employer’, $authordata->roles )){
echo ‘‘ . $name . ‘‘;
}
});I’m wondering it it could be possible to get the ID of that user as I need to add it to a shortcode.
I have tried a few different ways but none seem to be working. This is the shortcode I’m trying to get to work:
echo do_shortcode(‘[uwp_add_friend user_id =”%”]’);
the “%” should be the user ID but I don’t know how to get the ID from $authordata = get_userdata( fep_get_message_field( ‘mgs_author’ ) );
Could you help me?
Thanks
August 16, 2021 at 12:35 pm #43526lia.spoerlParticipantI have gotten this code to work:
add_action( ‘‘fep_display_after_reply_message’, function(){
$authordata = get_userdata( fep_get_message_field( ‘mgs_author’ ) );
if( in_array( ’employer’, $authordata->roles ) ){
echo do_shortcode(‘[uwp_add_friend user_id=”‘. $authordata->ID . ‘”]’);
}
});But, now I’m also getting a php error log:
Notice: Undefined variable: parent_id in /www/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()’d code on line 3
Notice: Trying to get property ‘user_id’ of non-object in /www/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()’d code on line 3Is there a way to prevent this error?
Thanks
August 16, 2021 at 2:59 pm #43528lia.spoerlParticipantHi,
I just noticed that when the last user to reply is not in the employer role, the friend request button disappears.
I guess I need to check both participants instead and filter the one with the employer role and then get that users id.
Which hook would I need to use?
Thanks
August 17, 2021 at 7:00 pm #43531lia.spoerlParticipantI figured it out myself. Thanks
- AuthorPosts
You need to purchase ‘Front End PM PRO’ to create topic in this support forum.
If you already purchased ‘Front End PM PRO’ please LOGIN.