このページでは、プラグインとテーマ以外のファイルに加えた変更を記しておきます。つまりWordPressの際にこれらのファイルを変更する必要があると言うことです。
wp-includes/feed-rss2.php、wp-includes/js/quicktags.js、wp-includes/formatting.phpは変更点が多いため、diffを見ながら上書きした方がいいかもしれません。
RSS Feedを全文配信にして、読みやすくする
RSSを抜粋から全文配信にして、HTMLタグの削除機能を削ってフィードを読みやすくします
-- <content:encoded><![CDATA[ the_content() ]]></content:encoded>
++ <content:encoded><![CDATA[ the_content('', 0, '', 0, 3) ]]></content:encoded>RSSの投稿日時の時間帯の違いを解決
標準ではGMTになっているようなので修正。買ったら積みますと言うサイトを参考にして、wp-includesにあるfeed-(なんたら).phpというファイルを以下のようにそれぞれ修正します。
- get_lastpostmodified(‘GMT’) → get_lastpostmodified(‘server’)
- +0000 → +0900
- get_post_timeという関数を見つけたら、全ての引数をfalseにする
RSS 2.0にロゴを付ける
RSS 2.0ではimage要素を追加することでロゴを指定することが出来ます
++ <image>
++ <title> bloginfo_rss('name'); wp_title_rss(); </title>
++ <url> bloginfo('template_url') /images/logo_rss.png</url>
++ <link> bloginfo_rss('url') </link>
++ </image>
++
do_action('rss2_head'); get_the_category_list()の空白を消す
HTMLリストで表示していると、この関数を実行したときの空白が気になるので消してしまおう。
-- {$thelist .= $separator. '';
++ {$thelist .= $separator;WordPressのins要素とdel要素のdatetimeを日本時間にする
デフォルトでは日本と時間がずれているので直しておきます
ins要素とdel要素を挿入時、p要素を挿入しない
ins要素とdel要素はブロック要素としてもインライン要素としても振る舞える要素ですが、実際にWordPress内で使ってみると、インライン要素として判断されて、pタグで括られてしまいます。今回はこれを修正すると共に、改行した際にbr要素を挿入しないようにします。
なお、インライン要素でins,del要素を使う際は属性なしでXHTMLに記述し、ブロック要素として使う際はCSSでブロック化してやる必要があります。また、Amazon Linkageプラグイン使用時にdivタグがpタグで囲われてしまう点も修正します。
以下、改変後のwpautopメソッドの全文を示します。
function wpautop($pee, $br = 1) {
$pee = $pee . "\n"; // just to make things a little easier, pad the end
$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
// Space things out a little
$allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|ins|del)';
$allblocks2 = (substr($allblocks, 0, -1)."|amazon)");
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
if ( strpos($pee, '<object') !== false ) {
$pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
$pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
}
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
$pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
$pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee);
$pee = preg_replace('|<p>|', "$1<p>", $pee );
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
$pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
$pee = preg_replace('!<li>\s*(<a[^>]*>(.+?))</p>!', "<li>$1", $pee); // <li>の後になぜか</p>が来る問題対策
$pee = preg_replace('!\n(\<amazon\>([a-zA-Z0-9]+),text)!', "\n<p>$1", $pee); // Amazon
$pee = preg_replace('!<p>\s*(</?' . $allblocks2 . '[^>]*>)!', "$1", $pee);
$pee = preg_replace('!(</?' . $allblocks2 . '[^>]*>)\s*</p>!', "$1", $pee);
if ($br) {
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee);
$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
$pee = str_replace('<WPPreserveNewline />', "\n", $pee);
}
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
$pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol|ins|del)[^>]*>)!', '$1', $pee);
if (strpos($pee, '<pre') !== false)
$pee = preg_replace_callback('!(<pre.*?>)(.*?)</pre>!is', 'clean_pre', $pee );
$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
$pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
$pee = preg_replace('!<\/(ins|del)>\n<p>!', '</$1>', $pee);
return $pee;
}アップロード画像の貼り付けコードを変更する
クラス名を消したり、lightbox用のコードを挿入したりします。
function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
$html = get_image_tag($id, $alt, $title, $align, $size);
-- $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
++ $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ' rel="lightbox"';
-- if ( $url )
$html = '<a href="' . clean_url($url) . "\"$rel>$html</a>";
function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
++ if ( $url ){
$html = (((!empty($align)) && ($align != "none")) ? '<p class="'. $align .'-box">' : '<p>').'<a href="' . clean_url($url) . "\"$rel>$html</a></p>";
}function get_image_tag($id, $alt, $title, $align, $size='medium') {
list( $img_src, $width, $height ) = image_downsize($id, $size);
$hwstring = image_hwstring($width, $height);
$class = 'align'.attribute_escape($align).' size-'.attribute_escape($size).' wp-image-'.$id;
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
-- $html = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'" '.$hwstring.'class="'.$class.'" />';
++ $html = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($title).'" title="'.attribute_escape($title).'" />';


