• Hi Greg,

    We’re trying to get the author profile URL so that we can tie it to their WPDiscuz username (when we click on their username, we would end up on their profile page).

    Is there a way to return an author’s permalink?

    For reference, here’s a snippet from WPDiscuz using User Pro to link to their profile:

    add_filter("wpdiscuz_profile_url", function ($profile_url, $user) {
        if ($user && class_exists('userpro_api')) {
            global $userpro;
            $profile_url = $userpro->permalink($user->ID);
        }
        return $profile_url;
    }, 10, 2);

    Thank you,
    Matt

    • This topic was modified 4 years, 5 months ago by Matt Biscay. Reason: add snippet
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    by the Author profile i understand you mean an URL to the page created by WPAdverts Authors extension?

    If so then right now we do not have a function to generate a link to this page, but you can get it with the code below

    
    $args = array(
        'author'         =>  wp_get_current_user()->ID,
        'post_type'      => 'advert-author',
        'posts_per_page' => 1,
        'post_status'    => array( 'publish', 'advert-hidden' ),
    );
    
    $authors = get_posts( $args );
    
    if( isset( $authors[0] ) ) {
      $url = get_the_permalink( $authors[0]->ID );
    } else {
      $url = null;
    }       
    

    If you would like to merge it with the code above then you can replace wp_get_current_user()->ID with $user->ID.

    Thread Starter Matt Biscay

    (@skyminds)

    Hi Greg,

    Thanks for the code snippet. It looks like people submitting ads are not added as Authors on that page:
    /wp-admin/edit.php?post_type=advert-author

    Is there a way to ensure they are added as Authors when the “create account” checkbox is checked and when they post their ad?

    Thank you,
    Matt

    Thread Starter Matt Biscay

    (@skyminds)

    When using the snippet, it gives the same profile URL to anyone who comments. There seems to be only one author and all users commenting inherit his profile URL. Is there something I need to change?

    Thank you,
    Matt

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    when checking the “create account” checkbox the user will only be registered as a user in wp-admin / Users panel.

    If you would like him to have an entry in wp-admin / Authors as well then you can use a wpadverts_user_saved filter to do that

    
    add_filter( "wpadverts_user_saved", function( $user_id ) {
      wp_insert_post( array(
        'post_title'    => $user_id,
        'post_content'  => '',
        'post_status'   => 'publish',
        'post_type'     => 'advert-author',
        'post_author'   =>  $user_id
      ) );
      return $user_id;
    }, 1000 );
    

    but i would not recommend doing so because you will get a bunch of empty author profiles since there is no where to pull the author data from (except for the Ad itself), it would be much better to ask the user to login and manually fill his profile.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get author profile URL’ is closed to new replies.