[wp-trac] [WordPress Trac] #37880: External Plugins On TeenyMCE
WordPress Trac
noreply at wordpress.org
Wed Aug 31 16:21:00 UTC 2016
#37880: External Plugins On TeenyMCE
-----------------------------+------------------------------
Reporter: dylancb | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: TinyMCE | Version: 4.4.3
Severity: normal | Resolution:
Keywords: | Focuses: ui
-----------------------------+------------------------------
Comment (by dylancb):
In `wp-includes/class-wp-editor.php` if I add the following, then it
works. But I don't want to overwrite core files.
Line 355 under `if( $set['teeny'] ) {`
{{{#!php
$ext_plugins = '';
$teeny_mce_external_plugins =
apply_filters( 'teeny_mce_external_plugins', array() );
if ( ! empty( $teeny_mce_external_plugins ) ) {
/**
* Filter the translations
loaded for external TinyMCE 3.x plugins.
*
* The filter takes an
associative array ('plugin_name' => 'path')
* where 'path' is the
include path to the file.
*
* The language file
should follow the same format as wp_mce_translation(),
* and should define a
variable ($strings) that holds all translated strings.
*
* @since 2.5.0
*
* @param array
$translations Translations for external TinyMCE plugins.
*/
$mce_external_languages =
apply_filters( 'mce_external_languages', array() );
$loaded_langs = array();
$strings = '';
if ( ! empty(
$mce_external_languages ) ) {
foreach (
$mce_external_languages as $name => $path ) {
if (
@is_file( $path ) && @is_readable( $path ) ) {
include_once( $path );
$ext_plugins .= $strings . "\n";
$loaded_langs[] = $name;
}
}
}
foreach (
$mce_external_plugins as $name => $url ) {
if ( in_array(
$name, $plugins, true ) ) {
unset(
$mce_external_plugins[ $name ] );
continue;
}
$url =
set_url_scheme( $url );
$mce_external_plugins[ $name ] = $url;
$plugurl =
dirname( $url );
$strings = '';
// Try to load
langs/[locale].js and langs/[locale]_dlg.js
if ( ! in_array(
$name, $loaded_langs, true ) ) {
$path =
str_replace( content_url(), '', $plugurl );
$path =
WP_CONTENT_DIR . $path . '/langs/';
if (
function_exists('realpath') )
$path = trailingslashit( realpath($path) );
if (
@is_file( $path . $mce_locale . '.js' ) )
$strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
if (
@is_file( $path . $mce_locale . '_dlg.js' ) )
$strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
if ( 'en'
!= $mce_locale && empty( $strings ) ) {
if
( @is_file( $path . 'en.js' ) ) {
$str1 = @file_get_contents( $path . 'en.js' );
$strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.',
$str1, 1 ) . "\n";
}
if
( @is_file( $path . 'en_dlg.js' ) ) {
$str2 = @file_get_contents( $path . 'en_dlg.js' );
$strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.',
$str2, 1 ) . "\n";
}
}
if ( !
empty( $strings ) )
$ext_plugins .= "\n" . $strings . "\n";
}
$ext_plugins .=
'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' .
"\n";
$ext_plugins .=
'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
}
}
self::$ext_plugins = $ext_plugins;
}}}
This code is directly from the `else` beneath it. May need further testing
but I did a few quick tests and this made it work.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37880#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list