問題描述

WP 4.1 的功能之一是引入了新的 distraction-free 模式。

這是一個個人意見,但我認為這是可怕的,其實與 4.1 之前的模式相比:

  • 它的編輯風格更糟糕

  • 它提供更少的寫入空間

  • 它更分散注意力,因為每次移動滑鼠時,都會看到事物出現並再次消失。什麼比螢幕上的移動更為分散注意力?

BTW,這個問題的目的不是對功能提出意見,而是要問我怎麼才能得到 4.1 的 distraction-free 模式?

我在網上做了一個研究,發現很多人抱怨,但沒有解決方案,除了有人說 (不鼓勵) 選項是降級,當然不是一個選擇。

最佳解決方案

Edit

截至第 4.3 版,這將不再工作了。 WP 已經完全刪除了舊的 distraction-free 模式的 JavaScript 。

要在 4.3 版本中使用,請獲取一個 javascript 檔案 from WP 4.2 release 的副本,然後使用下面的程式碼排入它。


您可以:

  1. 使用'wp_editor_settings'過濾器將'_content_editor_dfw'選項設定為 false 。

  2. 使用'mce_buttons''teeny_mce_buttons'過濾器:

    • 刪除新的 distraction-free 按鈕,具有 id:'dfw'

    • 新增舊的 distraction-free 按鈕,其 ID 為:'wp_fullscreen'

  3. 使用'tiny_mce_plugins''teeny_mce_plugins'過濾器新增舊的外掛指令碼,幸運的是沒有刪除,它被命名為'wpfullscreen'

對於#1 和#2,您可以檢查編輯器是否是編號為'content'的編輯器。

作為外掛的上述所有步驟 (作為 Gist here 可用):

<?php namespace GMFSDFM;
/**
 * Plugin Name: Fullscreen Distraction-Free Mode (pre v4.1)
 * Plugin URI: https://gist.github.com/Giuseppe-Mazzapica/c081ce03a68b00d983d5
 * License: MIT
 */

if (!is_admin()) return;

function should($editor_id = 'content') {
  return (version_compare($GLOBALS['wp_version'], '4.1') >= 0)
    && in_array($GLOBALS['pagenow'], array('post.php','post-new.php'))
    && $editor_id === 'content';
}

function buttons($buttons, $editor_id) {
  return should($editor_id)
    ? array_diff(array_merge((array) $buttons, array('wp_fullscreen')), array('dfw'))
    : $buttons;
}

function plugins($plugins) {
  return should()
    ? array_diff(array_merge((array) $plugins, array('wpfullscreen')), array('fullscreen'))
    : $plugins;
}

function settings($settings, $editor_id) {
  if (should($editor_id)) {
    $settings['_content_editor_dfw'] = false;
  }
  return $settings;
}

add_filter('wp_editor_settings', __NAMESPACE__.'\settings', 30, 2);
add_filter('mce_buttons', __NAMESPACE__.'\buttons', 30, 2);
add_filter('teeny_mce_buttons', __NAMESPACE__.'\buttons', 30, 2);
add_filter('teeny_mce_plugins', __NAMESPACE__.'\plugins');
add_filter('tiny_mce_plugins', __NAMESPACE__.'\plugins');

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。