Trying to get id from $authordata


Home Forums Front End PM PRO Trying to get id from $authordata

This topic is: Resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #43512
    lia.spoerl
    Participant

    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

    #43526
    lia.spoerl
    Participant

    I 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 3

    Is there a way to prevent this error?

    Thanks

    #43528
    lia.spoerl
    Participant

    Hi,

    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

    #43531
    lia.spoerl
    Participant

    I figured it out myself. Thanks

Viewing 4 posts - 1 through 4 (of 4 total)

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.