Created
November 22, 2019 13:58
-
-
Save binzorellino/5de940c61b82609613d26316ff972ecb to your computer and use it in GitHub Desktop.
Wordpress - force to refresh the cached TinyMCE editor style css file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'mce_css', 'fresh_editor_style' ); | |
function fresh_editor_style( $css ) { | |
global $editor_styles; | |
if ( empty ( $css ) or empty ( $editor_styles ) ) { | |
return $css; | |
} | |
$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 ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment