• Resolved johndoe01

    (@johndoe01)


    Greetings.

    I have an issue. I got the Adverts Authors addon but my clien wants that the Full Name of the Author doesn’t show on the ad.

    I see that in the ad the Author Meta that passes is the adverts_person (name) adverts_email (email) and adverts_phone (phone). Is there a way that i can pass the Username or any other data of the Author Profile which is not the name or the email?

    Thanks in advance.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i am not sure what do you mean? Where exactly (on which page) you would like to hide the user full name?

    Thread Starter johndoe01

    (@johndoe01)

    Well let me explain, here and there:

    
    https://www.racertrader.com/tests/ad-category/race-cars/
    https://www.racertrader.com/tests/ads/ford-mustang-formula-drift/
    

    I placed the User Name (name and last name) provided by the Meta available in the meta adverts_person.

    In list-item.php and single-advert.php that data is avaliable through that meta.

    What does my client want?
    My client wants that The Full name (name and last name) gets replaced by the Username provided by the Registration form.
    Here i need to do a clarification. Once the User is registered WordPress takes the email as user name but in the form there is a Custon Meta or field Named “user_username” (because the one called User_name is the one that names the profile page and i can’t retrieve that metadata elsewhere). The idea is that the user_username metadata of the Profile gets delivered to the adverts and i can change the meta adverts_person for the meta i need to push there.

    hold on while i was writing might be something with wp_get_current_user()

    Thread Starter johndoe01

    (@johndoe01)

    I see somehow what might i need.

    In functions.php on the folder wp-content/plugins/wp-adverts/includes/functions.php around the line 2340 is this function.

    function _adverts_create_user_from_post_id( $user_id, $post_id ) {
        
        if( $user_id !== null ) {
            // some other filter already registered user, skip registration then
            return $user_id;
        }
        
        $email_address = get_post_meta( $post_id, "adverts_email", true );
        $full_name = get_post_meta( $post_id, "adverts_person", true );
        // Generate the password and create the user
        $password = wp_generate_password( 12, false );
        $user_id = wp_create_user( $email_address, $password, $email_address );
    
        // Set the nickname
        wp_update_user(
            array(
                'ID'          =>    $user_id,
                'nickname'    =>    $full_name,
                'display_name'=>    $full_name
            )
        );
    
        // Set the role
        $user = new WP_User( $user_id );
        $user->set_role( 'subscriber' );
    
        // Email the user
        do_action( "adverts_new_user_notification", $user_id, null, "both", $password );
        
        return $user_id;
    }

    i need to set in functions.php of my theme a variation that allows me to override this in order to do something similar without modifying the original file since if i do so, at the next update gets undone.

    My alternate function is something like

    function _adverts_create_user_from_post_id( $user_id, $post_id ) {
        
        if( $user_id !== null ) {
            // some other filter already registered user, skip registration then
            return $user_id;
        }
        
        $email_address = get_post_meta( $post_id, "adverts_email", true );
        $full_name = get_post_meta( $post_id, "adverts_person", true );
        $mod_username = get_post_meta( $post_id, "user_publicname", true );
        // Generate the password and create the user
        $password = wp_generate_password( 12, false );
        $user_id = wp_create_user( $mod_username, $password, $email_address );
    
        // Set the nickname
        wp_update_user(
            array(
                'ID'          =>    $user_id,
                'nickname'    =>    $full_name,
                'display_name'=>    $full_name
            )
        );
    
        // Set the role
        $user = new WP_User( $user_id );
        $user->set_role( 'subscriber' );
    
        // Email the user
        do_action( "adverts_new_user_notification", $user_id, null, "both", $password );
        
        return $user_id;
    }

    I’m not sure if that is the function but from what i see is Close from what i need, and i feel i went into a Dead End

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    if the users are registering with Authors extension register form then the function you pasted is not executed at all (it is only run when you check “create account” checkbox in the [adverts_add] shortcode).

    What you will most likely need to do is hook into wpadverts_authors_registered action and change the user name.

    
    add_action( "wpadverts_authors_registered", function( $form, $user_id ) {
      wp_update_user(array(
        "ID" => $user_id,
        "display_name" => "set name here ...",
        "nickname" => "set nick name here ....",
      ));
    }, 10, 2 );
    

    That being said when the user will update his profile from the Authors manage shortcode his display name will be changed again to the full name.

    I see that only registered users can post ads on your site and that the user name is being displayed by a custom code you have in the templates or in some WPAdverts customizations.

    In this case the easiest way to resolve it would be to just modify the custom codes you have to show the public name?

    Thread Starter johndoe01

    (@johndoe01)

    In this case the easiest way to resolve it would be to just modify the custom codes you have to show the public name?

    That’s exactly what i’m trying to do, but i don’t know how or where to retrieve the public name, since in the adverts and list items i can retrieve email, full name and phone. But the public name (or whatever meta data i want to add to authors’ profiles) I can’t retrieve it since in the post metadata they are not available.

    • This reply was modified 4 years, 3 months ago by johndoe01.
    Thread Starter johndoe01

    (@johndoe01)

    Hello!.

    I paste in the functions.php like this to see if there is any change
    https://i.imgur.com/9REMnN2.png
    Effectively works, but once i update the profile… It gets back to the User Name

    • This reply was modified 4 years, 3 months ago by johndoe01.
    Thread Starter johndoe01

    (@johndoe01)

    Then i do this change:
    https://i.imgur.com/AklRVdA.png
    Change the profile
    https://i.imgur.com/ctC67cf.png
    And gets overriden
    https://i.imgur.com/dWtIaeT.png

    Plugin Author Greg Winiarski

    (@gwin)

    Like i wrote in the last message …

    
    [...] when the user will update his profile from the Authors manage shortcode his display name will be changed again to the full name.
    

    If you know the advert ID then you can get the Author profile ID with a code below

    
    $user_id = get_post( $advert_id )->post_author;
    $args = array(
        'author'         =>  $user_id,
        'post_type'      => 'advert-author',
        'post_status'    => array( 'publish', 'advert-hidden' ),
        'posts_per_page' => 1
    );
    $authors = get_posts( $args );
    $authord_id = $authors[0]->ID;
    
    $meta = get_post_meta( $author_id, "some_meta_name", true );
    
    Thread Starter johndoe01

    (@johndoe01)

    THANK YOU! YOU ARE AWESOME!

    The last code was part of what i was looking for. If my interpretation is correct it running an internal query for the author page and then, retrieving the meta of such page i did this tweak for the Ad and the list item

    
    $user_id = get_post( $post->ID; )->post_author;
    $args = array(
        'author'         =>  $user_id,
        'post_type'      => 'advert-author',
        'post_status'    => array( 'publish', 'advert-hidden' ),
        'posts_per_page' => 1
    );
    $authors = get_posts( $args );
    $author_id = $authors[0]->ID;
    
    $username_author = $author_id = $authors[0]->post_title;
    
    echo $username_author
    

    Since that post title was result from user_publicname and i could not find that else where with that finally it is retrieved it and the name Is hidden for the public.

    I’ll have to do a tweak or two on the authors profiles but this exactly what i was looking for.

    Since my background is for design some things of programming comes hidden to me but i understand strangely some things of that.

    Thanks a lot. I really appreciate it.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    the code takes an $advert_id, and checks the Ad author id (more precisely the user ID in wp_posts table), with the user id an internal query is run to find in wp_posts table the posts assigned to the user_id and with type “advert-author” there should be on post like that only.

    In the code, you pasted you are correct in replacing the $advert_id with your variable as most likely the $advert_id is not available there and you need to use the variable which actually stores the Ad id.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Authors – Is there a way to send an Author Meta (eg Username) to the Ad?’ is closed to new replies.