How to custom user url in BuddyPress and WordPress? -
thanks support! need custom user url in page using wordpress , buddypress. example:
from: (current)
http://example.com/user/pum_su411
to
http://example.com/user/548234
with 548234
id of user.
i want after completed custom, users have url above automatically.
thanks solutions!
- add code theme functions.php file.
function _bp_core_get_user_domain($domain, $user_id, $user_nicename = false, $user_login = false) { if ( empty( $user_id ) ){ return; } if( isset($user_nicename) ){ $user_nicename = bp_core_get_username($user_id); } $after_domain = bp_get_members_root_slug() . '/' . $user_id; $domain = trailingslashit( bp_get_root_domain() . '/' . $after_domain ); $domain = apply_filters( 'bp_core_get_user_domain_pre_cache', $domain, $user_id, $user_nicename, $user_login ); if ( !empty( $domain ) ) { wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' ); } return $domain; } add_filter('bp_core_get_user_domain', '_bp_core_get_user_domain', 10, 4); function _bp_core_get_userid($userid, $username){ if(is_numeric($username)){ $aux = get_userdata( $username ); if( get_userdata( $username ) ) $userid = $username; } return $userid; } add_filter('bp_core_get_userid', '_bp_core_get_userid', 10, 2); function _bp_get_activity_parent_content($content){ global $bp; $user = get_user_by('slug', $bp->displayed_user->fullname); // 'slug' - user_nicename return preg_replace('/href=\"(.*?)\"/is', 'href="'.bp_core_get_user_domain($user->id, $bp->displayed_user->fullname).'"', $content); } add_filter( 'bp_get_activity_parent_content','_bp_get_activity_parent_content', 10, 1 ); function _bp_get_activity_action_pre_meta($content){ global $bp; $fullname = $bp->displayed_user->fullname; // 'slug' - user_nicename $user = get_user_by('slug', $fullname); if(!is_numeric($user->id) || empty($fullname)){ $args = explode(' ', trim(strip_tags($content))); $fullname = trim($args[0]); $user = get_user_by('slug', $fullname); } return preg_replace('/href=\"(.*?)\"/is', 'href="'.bp_core_get_user_domain($user->id, $fullname).'"', $content); } add_action('bp_get_activity_action_pre_meta', '_bp_get_activity_action_pre_meta'); add_filter('bp_core_get_userid_from_nicename', '_bp_core_get_userid', 10, 2);
Comments
Post a Comment