問題描述

當我手動更改 TinyMCE 編輯器的樣式表時,是否有強制刷新 editor-style.css 的方法?修改不會立即顯示,但它們將被緩存在管理後端的管理端。

例如:

editor-style.css?ver=3393201

最佳解決方案

有一個鈎子:’mce_css’ 。它在_WP_Editors :: editor_settings() 中調用,並且您將所有加載的樣式表逗號分隔為第一個也是唯一的參數。

現在很容易:使用全局變量 $editor_styles(這裏是您的主題和父主題的編輯器樣式表已存儲),將文件最後一次修改的時間添加為參數並重建字符串。

作為 plugin

<?php # -*- coding: utf-8 -*-
/**
 * Plugin Name: T5 Fresh Editor Stylesheets
 * Description: Enforces fresh editor stylesheets per version parameter.
 * Version:     2012.07.21
 * Author:      Thomas Scholz
 * Plugin URI:  http://wordpress.stackexchange.com/q/33318/73
 * Author URI:  http://toscho.de
 * License:     MIT
 * License URI: http://www.opensource.org/licenses/mit-license.php
 */

    add_filter( 'mce_css', 't5_fresh_editor_style' );

    /**
     * Adds a parameter of the last modified time to all editor stylesheets.
     *
     * @wp-hook mce_css
     * @param  string $css Comma separated stylesheet URIs
     * @return string
     */
    function t5_fresh_editor_style( $css )
    {
        global $editor_styles;

        if ( empty ( $css ) or empty ( $editor_styles ) )
        {
            return $css;
        }

        // Modified copy of _WP_Editors::editor_settings()
        $mce_css   = array();
        $style_uri = get_stylesheet_directory_uri();
        $style_dir = get_stylesheet_directory();

        if ( is_child_theme() )
        {
            $template_uri = get_template_directory_uri();
            $template_dir = get_template_directory();

            foreach ( $editor_styles as $key => $file )
            {
                if ( $file && file_exists( "$template_dir/$file" ) )
                {
                    $mce_css[] = add_query_arg(
                        'version',
                        filemtime( "$template_dir/$file" ),
                        "$template_uri/$file"
                    );
                }
            }
        }

        foreach ( $editor_styles as $file )
        {
            if ( $file && file_exists( "$style_dir/$file" ) )
            {
                $mce_css[] = add_query_arg(
                    'version',
                    filemtime( "$style_dir/$file" ),
                    "$style_uri/$file"
                );
            }
        }

        return implode( ',', $mce_css );
    }

次佳解決方案

我有同樣的問題 (2012,WP 3.4.2 !!) 。可能的解決方案,而這個錯誤是:

1) 如果您使用 firebug,[x] 在網絡面板中禁用瀏覽器緩存有助於。我甚至有一個非常奇怪的問題,緩存的 editor-style 短暫地出現 (在 css-filtered)Firebug 網絡面板中分裂,而不再消失。拍攝截圖來證明自己。

2) 完整的瀏覽器緩存清除有助於。無論何種原因,此問題未重新出現。

3) 最後,我最喜歡的建議,如果你還要確保,即你的客户在分期或即時服務器上得到你的增量改進 (沒有任何煩人的緩存清除建議):

重新定位文件並繼續計數:

// add_editor_style('editor-style-01.css'); bump for every deployment
// add_editor_style('editor-style-02.css');
add_editor_style('editor-style-03.css');

哈基,但可靠。

參考文獻

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