wpDiscuz - WordPress Comment Plugin
Change user profile...
 
Share:
Notifications
Clear all

Question [Solved] Change user profile address

4 Posts
2 Users
2 Likes
91 Views
Posts: 11
Topic starter
(@mandegar266)
Eminent Member
Joined: 5 months ago

Hello and don't be tired to all friends
I need to change the default Discase profile link to the template I want, but my code gets an error
I want the following template to be placed for user profiles instead of the default template of Diskaz, so that when a user clicks on the avatar and name of other users in the comments section, the link and address of the user's page will open with the following template:
mysite.
com/users/10/divar where 10 is the user id

Thank you for your help in writing this code

Some of my code that doesn't work:

function change_wpdiscuz_profile_url( $profile_url, $user_id, $url_type ) {
    if ( $url_type === 'author' ) {
        $new_url = home_url( '/users/' . $user_id . '/divar/' );
        return $new_url;
    }
    return $profile_url;
}
add_filter( 'wpdiscuz_profile_url', 'change_wpdiscuz_profile_url', 10, 3 );

function change_wpdiscuz_author_link( $author_link, $comment ) {
    $user_id = $comment->user_id;
    $new_url = home_url( '/users/' . $user_id . '/divar/' );
    $author_link = preg_replace( '/href="([^"]+)"/', 'href="' . $new_url . '"', $author_link );
    return $author_link;
}
add_filter( 'wpdiscuz_author_link', 'change_wpdiscuz_author_link', 10, 2 );

Ā 

function change_wpdiscuz_profile_url( $url, $user_id ) {
    $new_url = home_url( '/users/' . $user_id . '/divar/' );
    return $new_url;
}
add_filter( 'wpdiscuz_profile_url', 'change_wpdiscuz_profile_url', 10, 2 );

function change_wpdiscuz_avatar_link_attributes( $attributes, $comment ) {
    $user_id = $comment->user_id;
    $new_url = home_url( '/users/' . $user_id . '/divar/' );
    $attributes['href'] = $new_url;
    return $attributes;
}
add_filter( 'wpdiscuz_avatar_link_attributes', 'change_wpdiscuz_avatar_link_attributes', 10, 2 );
3 Replies
Asti
Posts: 6223
 Asti
Support
(@asti)
Illustrious Member
Joined: 6 years ago

The function below should work fine:Ā 

function change_wpdiscuz_profile_url( $url, $user ) {
	if ( ! empty( $user->ID ) ) {
		$url = home_url( '/users/' . $user->ID . '/divar/' );
	}
	return $url;
}

add_filter( 'wpdiscuz_profile_url', 'change_wpdiscuz_profile_url', 10, 2 );

Note: the "Enable Profiles URL" option should be enabled. More info here: https://wpdiscuz.com/docs/wpdiscuz-7/plugin-settings/user-authorization-and-profile-data/#enable-profiles-url

Posts: 11
Topic starter
(@mandegar266)
Eminent Member
Joined: 5 months ago

Thank you
I tested the same function as this, but it doesn't work
Do I have to make a special and additional setting in Discuz so that this function works properly?
I used the Jet Engine plugin profiler and by default only the user can click on his avatar and username to open his user page with the default mysite template.
com/author/username, while I need all users to be able to enter the public user profile page with the template mysite.com/users/user by clicking on the avatar and username of each desired user in the comments section of Discuz. be id/divar

Posts: 11
Topic starter
(@mandegar266)
Eminent Member
Joined: 5 months ago

Thanks...it finally worked
Apparently, the cache was causing the functions to not work
Thank you dear and honorable Asti
Be successful and happy

Share: