WordPress 4.2のPressThisも調整

WordPress 4.2 が出たので更新したのですが、Press Thisで引用して編集する際に生成されるHTMLも変わっていたので調整しました。元のPress Thisの話はこちら。
blockquoteタグの確認とWordPressのPressThis調整 | 曖昧/旬.

まず、Press Thisという機能が今までは wp-admin/press-this.php でほぼ完結していたのですが、それが機能とテンプレートに分かれたようです。機能は wp-admin/includes/class-wp-press-this.php へ移動したみたいですね。

そんで、引用HTMLを生成する機能は get_suggested_content() という関数に入っています。というわけで、引用時のHTMLを調整したい場合はここをいじる必要があるようです。自分はこんな感じ。

$ svn di
Index: wp-admin/includes/class-wp-press-this.php
===================================================================
--- wp-admin/includes/class-wp-press-this.php    (リビジョン 61)
+++ wp-admin/includes/class-wp-press-this.php    (作業コピー)
@@ -1070,7 +1070,7 @@
      * @returns string Discovered content, or empty
      */
     public function get_suggested_content( $data ) {
-        $content = $text = '';
+        $postfix = $content = $text = '';

         if ( ! empty( $data['s'] ) ) {
             $text = $data['s'];
@@ -1102,9 +1102,12 @@
                 $default_html['quote'] = '<blockquote>%1$s</blockquote>';
             }
         } else {
-            $default_html['quote'] = '<blockquote>%1$s</blockquote>';
-            $default_html['link'] = '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) .
-                ' <em><a href="%1$s">%2$s</a></em></p>';
+            $default_html['quote'] = '%1$s'."\n";
+            $default_html['link'] = '<a href="%1$s">%2$s</a>.';
+            if ( ! empty( $text ) ) {
+                $default_html['link'] = '<cite>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) .
+                    ' ' . $default_html['link'] . '</cite>';
+            }
         }

         /**
@@ -1123,7 +1126,8 @@

         // Wrap suggested content in the specified HTML.
         if ( ! empty( $default_html['quote'] ) && $text ) {
-            $content .= sprintf( $default_html['quote'], $text );
+            $content .= '<blockquote>' . sprintf( $default_html['quote'], $text );
+            $postfix = '</blockquote>';
         }

         // Add source attribution if there is one available.
@@ -1140,6 +1144,7 @@
             }
         }

+        $content .= $postfix;
         return $content;
     }

ここまでしてblockquoteタグで全体を囲むことに意味があるのかは分からないし、それが正しいのかも知りません。でもblockquote内にciteタグがある方が自然だと思うんだよね。

しかし、そこで問題が。Press Thisを押した時の画面がビジュアルリッチエディター決め打ちっぽくて、ソースをコピーできない。ならばとプロフィールでビジュアルリッチエディターをOffにしてみたらテキストが見えない。そう、背景色と同じ色になっている。wp-admin/css/press-this.css を見たところ、意図的に文字が見えないようにしているらしい。けど自分は見たい。というわけでCSS調整。wp-admin/css/press-this.min.css の #pressthis{color:#fff} を削除。これで見えるようになった。

うーん、コアにガンガン手を入れてる自分。いいのかなぁ。プラグイン的なものにまとめるか、WordPressにターゲットしないツールとして作ってもいいよね。ちょっと考えよう。