bbpressの作成者などを変更したい
-
テーマ用のテンプレートの定義ファイル、例えば
bbpress/templates/default/bbpress/loop-single-forum.phpを読むと、次のようなコードがありました。<?php bbp_author_link( array( 'post_id' => bbp_get_forum_last_active_id(), 'size' => 14 ) ); ?>この関数
bbp_author_linkの中で、作成者の画像やユーザー名のプロフィールリンクを出力しているようなので、それを削除すれば良さそうでした。関数
bbp_author_linkの定義を探すと、プラグインのファイルbbpress/includes/users/template.phpにありました。function bbp_author_link( $args = '' ) {
echo bbp_get_author_link( $args );
}同じファイルに関数
bbp_get_author_linkの定義もあり、それを読むと、この関数自体で出力する他に、関数bbp_get_topic_author_linkまたはbbp_get_reply_author_linkの何れかに任せて出力してもらう場合がありました。そこで、3つの関数それぞれを変更して、画像とリンクの出力を無くす検証を行ってみました。以下、その内容です。
bbp_get_author_linkの場合は、まずアバターを出力する下記の行をコメントアウト。// $author_links[] = get_avatar( $user_id, $r['size'] );それから、
<a>タグを埋め込む下記の行をコメントアウトして// $author_link[] = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text );次のように変えて埋め込ませないようにしました。
$author_link[] = $link_text;次に
bbp_get_topic_author_linkはファイルbbpress/includes/topics/template.phpにありました。変更は先ほどと同様に// $author_links['avatar'] = bbp_get_topic_author_avatar( $topic_id, $r['size'] );それから
// $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text );
$author_link[] = $link_text;最後に
bbp_get_reply_author_linkはファイルbbpress/includes/replies/template.phpにあり、変更は同様に// $author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $r['size'] );それから
// $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text );
$author_link[] = $link_text;なお、私はプラグインのphpファイルを直接書き換えて試しましたが、bbpressプラグインのバージョンアップにより元に戻ってしまわないようにフィルターを使って同様の変更を行った方がよいと思います。3つの関数それぞれに、関数名と同じ名前のフィルター(
bbp_get_author_link,bbp_get_topic_author_link,bbp_get_reply_author_link)が用意されていました。Examples:
<?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => false, 'type' => 'name' ) ); ?>
“Displays only the current reply author user’s display name without their avatar or user role” via http://codex.bbpress.org/bbp_reply_author_link/<?php bbp_topic_author_link( array( 'sep' => '<br />', 'show_role' => false, 'type' => 'name' ) ); ?>
“Displays only the current topic author user’s display name without their avatar or user role” via http://codex.bbpress.org/bbp_topic_author_link/More examples are at each of the following links:
http://codex.bbpress.org/bbp_author_link/
http://codex.bbpress.org/bbp_reply_author_link/
http://codex.bbpress.org/bbp_topic_author_link/Hope it helps 🙂
トピック「bbpressの作成者などを変更したい」には新たに返信することはできません。