ホーム > bbPress > bbPress : 画像を貼り付けられる様にする

bbPress : 画像を貼り付けられる様にする

bbPressには標準で画像を添付する事ができません。
つまり、imgタグなどが使えないって事です。

それを使えるようにする方法が紹介されていました。

方法は、
bb-includes/formatting-functions.php の
58行目あたり、function encode_bad( $text ) 以下に

$text = preg_replace('|<(/?img.*?)>|', '<$1>', $text);

を追加します。

function encode_bad( $text ) {
	$text = wp_specialchars($text);
	$text = preg_replace('|&lt;(/?strong)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;(/?em)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;(/?a.*?)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;(/?ol)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;(/?p)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;br /&gt;|', '<br />', $text);
	$text = preg_replace('|&lt;(/?ul)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;(/?li)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;(/?blockquote.*?)&gt;|', '<$1>', $text);
	$text = preg_replace('|&lt;(/?code)&gt;|', '<$1>', $text);
 
	$text = preg_replace("|`(.*?)`|se", "'<code>' . encodeit('$1') . '</code>'", $text);
	$text = preg_replace('|&amp;amp;lt;(/?img.*?)&amp;amp;gt;|', '&lt;$1&gt;', $text);
	return $text;
}

次に、87行目あたり function bb_allowed_tags() { 以下に

		'img' =&gt; array(
		'src' =&gt; array(),
		'alt' =&gt; array(),
		'title' =&gt; array()),

を追加します。

function bb_allowed_tags() {
	$tags = array(
		'a' => array(
			'href' => array(),
			'title' => array(),
			'rel' => array()),
		'blockquote' => array('cite' => array()),
		'br' => array(),
		'code' => array(),
		'em' => array(),
		'strong' => array(),
		'ul' => array(),
		'ol' => array(),
		'li' => array()
 
		'img' =&gt; array(
		'src' =&gt; array(),
		'alt' =&gt; array(),
		'title' =&gt; array()),
 
	);
	return apply_filters( 'bb_allowed_tags', $tags );
}

これで imgタグ が使えるようになるはずです。
ちなみに、0.73で試しました。

動作デモは、

画像テスト ≪ WordPress Plugin DB Japan

ネタ元
bbPress Img Tag Add On ≪ Talkabout Design – Community

カテゴリー: bbPress タグ: ,
  1. コメントはまだありません。
  1. トラックバックはまだありません。