WordPress Plugin tinymce-templates-lite

15. Februar 2012 - tinymce, wordpress

Hier ist ein kleines Plugin, das der WordPress Konfiguration von tinymce das Template-Plugin  hinzufügt und eure Styles im Dropdown Menü anzeigt.

tinymce-templates

English Summary for „WordPress Plugin tinymce-templates-lite“:

This is a small plugin that extends the WordPress configuration of tinymce with the template plugin and displays your templates in the template dropdown.

Ich brauchte Templates in tinymce und die verfügbaren Plugins waren mir zu umfangreich und zu unpraktisch.

Bei dieser Lösung muss man seine Templates (*.htm oder *.html) nur in den Templates -Ordner des Plugins zu legen und kann sie dann in tinymce verwenden.

Hier ist ein Ausschnitt aus den wichtigsten Codezeilen.

Der Rest des Codes wird benötigt, um die Templates aus dem Ordner auszulesen und im Dropdown darzustellen.

if ( !class_exists( 'tinymce_templates_lite' ) ) {
class tinymce_templates_lite {
function tinymce_templates_lite() {
add_action( 'admin_head',array(&$this, 'tinymce_templates_lite_init'));
}
function tinymce_templates_lite_init() {
if (get_user_option('rich_editing') == 'true') {
add_filter('mce_external_plugins',array(&$this,'add_template_plugin'));
add_filter('mce_buttons',array(&$this,'register_template_button'));
add_filter('tiny_mce_before_init',array(&$this,'nf_tiny_init'));
}
}
public function register_template_button($buttons = array()) {
array_push($buttons, 'seperator','template');
return $buttons;
}
public function add_template_plugin ($plugin_array) {
$plugin_array['template']=plugins_url().'/tinymce_templates_lite/mce_plugins/plugins/template/editor_plugin.js';
return $plugin_array;
}
public function nf_tiny_init ($initArray) {
$tlist=array();
$get_temps=$this->get_templates();
$ww=count($get_temps);
if ($ww > 0) {
for ($i=0; $i<$ww; $i++) {
$expl=explode('.',$get_temps[$i]);
$tlist[]=array('title'=> $expl[0],'src'=>plugins_url().'/tinymce_templates_lite/templates/'.$get_temps[$i],'description' => $expl[0]);
}
$initArray['template_templates']=json_encode($tlist);
}
return $initArray;
}

Download tinymce_templates_lite

tinymce_templates_lite