PS Disable Auto Formatting関連についてのまとめ

  • 投稿 : 2016-11-08

PS Disable Auto Formattingは、内部で何をやっているのか?

PS Disable Auto Formattingは、WordPressの段落自動整形(wpautop)を停止させると共に、ビジュアルエディタが生成するhtmlソースを改変。HTMLモードでの編集時に、意図しないbrタグ、pタグの除去、pタグの付加が発生しないようにすると共に、ビジュアルモード編集時における意図した通りの自然な改行・段落の生成を実現します。
Modify paragraph formatting plugin “PS Disable Auto Formatting” | WordPress Plugin for CMS(インターネットアーカイブ)

公式のページにちゃんと書かれてました。現在はページがなくなっていたので気づかなかったのですが、引用している人たちがいたのでそういう情報が記載されていたのを知りました。

・記事の表示時:WordPressの段落自動整形(wpautop)を停止
・編集画面の時:ビジュアル、HTMLモードでの編集時に、何かをする

大きくはこの2つに集約されるようです。実際にソースを読んでもそんな感じですね。

Stops the automatic forming and the HTML tag removal in the html mode of WordPress, and generates a natural paragraph and changing line.

WordPress.org



PS Disable Auto Formattingを停止するとレイアウトが崩れる場合の対応

「WordPressの段落自動整形(wpautop)を停止」の機能がなくなったために、レイアウトが崩れるのだと思います。プラグインを停止すると、過去記事のレイアウトも含めて崩れる場合の原因はこれだと思います。

remove_filter( 'the_content', 'wpautop' ); //記事の場合
テーマファイルの「functions.php 」に上記を追加するとOKなはずです。
プラグインでやってることを、「functions.php 」に書いてしまうという路線ですね。

remove_filter('comment_text', 'wpautop', 30); //コメントの場合
remove_filter('the_excerpt', 'wpautop'); //抜粋の場合
remove_filter('term_description', 'wpautop'); //カテゴリの説明
記事以外も自動整形停止の設定をしていたら、停止していたものだけを「functions.php 」に追記してください。

補足:
ps_disable_auto_formatting.phpの中の「remove_filter( $hook, 'wpautop', $priority );」という部分が上記に該当する部分です。

ビジュアルエディタに変更できないエラーの暫定回避

function __construct() {
    global $wp_version;

    if ( version_compare( $wp_version, '2.5', '>=' ) ) {
        add_action( 'init'                , array( $this, 'disable_auto_formatting_init' ) );
        add_action( 'admin_menu'          , array( $this, 'add_disable_formatting_setting_page') );
        //add_filter( 'print_scripts_array' , array( $this, 'rewrite_default_script' ) );
        add_filter( 'wp_insert_post_data' , array( $this, 'formatting_quickpress_post' ) );
        add_action( 'media_buttons'       , array( $this, 'check_edit_mode_and_add_richedit_pre' ), 9 );
        add_action( 'media_buttons'       , array( $this, 'delete_filtering_wp_richedit_pre' ) );
    } else {
        add_action('admin_notices'        , array( $this, 'version_too_old' ) );
    }
}
「add_filter( 'print_scripts_array' , array( $this, 'rewrite_default_script' ) );」の行の前に「//」をいれてコメントアウトしてください。そうすれば、ビジュアルエディタに切り替えすることはできるようになるかと思います。

PS Disable Auto Formattingの代わりになるプラグインについて

記事の表示時:WordPressの段落自動整形(wpautop)を停止

上記の「functions.php 」に追記する方法で対応

編集画面の時:ビジュアル、HTMLモードでの編集時に、何かをする

Extends and enhances TinyMCE, the WordPress Visual Editor.

WordPress.org


上記プラグインを導入します。

ps-disable-auto-formatting01.png

プラグインの設定の中の「高度なオプション」の「段落タグの保持」にチェックを入れてください。(英語表記の場合は、「Advanced Option」の「Keep paragraph tags」です。)

スポンサーリンク