#37880 closed feature request (wontfix)
External Plugins On TeenyMCE
Reported by: | dylancb | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4.3 |
Component: | TinyMCE | Keywords: | |
Focuses: | ui | Cc: |
Description
Hi,
I have tried to add an external plugin to TeenyMCE but it seems that it's not possible as if teeny is set in the wp-editor class, the external plugins script doesn't get loaded.
Is there any way this can be achieved, and if not could you add an action or the external plugins to the wp-editor for TeenyMCE, as well as Tiny.
Thanks
Change History (3)
#2
@
8 years ago
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'] ) {
$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.
#3
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
As @afercia said above, this is a minimal configuration for use in places that require only a minimal editing capabilities. It was intended for use in Press This but is not used in core any more.
In that terms don't think we should be adding any more filters to it. If you really need to, you can access all the TinyMCE options form the teeny_mce_before_init
filter, including adding of external plugins.
As far as I understand, this is more related to the TinyMCE minimal configuration option ("teeny") rather than to accessibility.