BuddyPressでプロフィール欄のリンクを削除する
そもそも
BuddyPressでマイページのプロフィール欄を見ると、いちいちリンクが貼られています。
ここをクリックすると同じプロフィールのユーザの検索結果が出てくるのですが、あまり使わないし、「一言プロフィール」までリンクが貼られることもあって、削除してやりたいですね。
どこで定義されているか?
buddypress/bp-xprofile/bp-xprofile-filters.php のココ。
add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
この1行を消してやるとリンクが消えるのがわかります。
念のため xprofile_filter_link_profile_data 関数の中身も見てやりましょう。
function xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) { if ( 'datebox' == $field_type ) return $field_value; if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) ) return $field_value; $values = explode( ',', $field_value ); if ( !empty( $values ) ) { foreach ( (array) $values as $value ) { $value = trim( $value ); // If the value is a URL, skip it and just make it clickable. if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) { $new_values[] = make_clickable( $value ); // Is not clickable } else { // More than 5 spaces if ( count( explode( ' ', $value ) ) > 5 ) { $new_values[] = $value; // Less than 5 spaces } else { $search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() ); $new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>'; } } } $values = implode( ', ', $new_values ); } return $values; }
$valueがURLならそのままclickableにしてやり、そうでなければ検索のリンク(s=hogeってアレですね)にして返すって関数です。
で、リンクを消す方法
もちろんBuddyPressのソースをそのままいじくるのはまずいので、子テーマを作ってfunction.phpの中に以下の1行を追加してやりましょう。
remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2);
これでリンクがなくなりました。