• mteshy

    (@mteshy)


    現在、BuddyPressを利用し会員制サイトを制作しております。

    ユーザーのプロフィールページ(マイページ)はBuddyPressの基本構造では
    /members/usernameになっておりますが、/members/user_idの構成にしたいと考えております。

    そこで、いろいろネットを調べましたところ、同じ質問をされている方がおりました。

    http://buddypress.org/support/topic/member-profile-url-with-user-id-instead-of-username/#post-165054(英語サイト)
    その中でフックを公開されている方がおりまして、https://gist.github.com/dzmounir/5503865

    ——————————————————————-
    上記サイトより引用

    <?php

    function bp_get_user_domain_with_id( $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);

    //if ( !$domain = wp_cache_get( ‘bp_user_domain_’ . $user_id, ‘bp’ ) ) {
    $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 );

    // Cache the link
    if ( !empty( $domain ) ) {
    wp_cache_set( ‘bp_user_domain_’ . $user_id, $domain, ‘bp’ );
    }
    //}

    return $domain;

    }
    add_filter(‘bp_core_get_user_domain’, ‘bp_get_user_domain_with_id’, 10, 4);

    // Warning部分
    function bp_get_userid_with_id($userid, $username){
    //if the username is an userid ?
    if(ctype_digit($username)){
    // check if a user with userid equal to $username exist
    $aux = get_userdata( $username );
    if( get_userdata( $username ) )
    $userid = $username;
    }
    return $userid;
    }
    add_filter(‘bp_core_get_userid’, ‘bp_get_userid_with_id’, 10, 2);
    ——————————————–ここまで

    //add_filter(‘bp_core_get_userid_from_nicename’, ‘bp_get_userid_with_ideddde’,10, 1);

    // bp_core_get_userid_from_nicename filter havn’t the $username in param 🙁 so i was
    // add filter to bp_is_username_compatibility_mode to force the excution of bp_core_get_userid
    // *** check line 261 of bp-core-catchuri.php ***

    function bp_is_username_compatibility_mode_always_true(){
    return true;
    }
    add_filter(‘bp_is_username_compatibility_mode’, ‘bp_is_username_compatibility_mode_always_true’);

    ?>
    ——————————————————————

    テストサイトにてfunctions.phpに記述してみましたが、確かにプロフィールページが/members/user_idになるのですが、
    プロフィール自体が表示されない現象に陥っております。

    なおこのコードを実行しますとWarning: Missing argument 2 for bp_get_userid_with_id() in /wp-content/themes/my-theme/functions.php on line 117
    のメッセージが出力されます。

    BuddyPressのコアのソースを解析しておりますが、いかせん、hockについての知識が少ないため
    四苦八苦しております。

    お手数をおかけしますが、どなたかご教示頂けないでしょうか?

    宜しくお願いします。

    wordpress ver 3.5.1
    BuddyPress ver 1.6.4

  • トピック「BuddyPressプロフィールページ(マイページ)のURLを/members/user_idへ変更」には新たに返信することはできません。