<?php 
/**
 * Plugin Name: TinyMCE
 * Plugin URI: https://btobdesign.com
 * Description:Personnalisation de l'éditeur wysiwyg TinyMCE
 * Version: 1.0
 * Author: B-to-B Design
 * Author URI: https:///btobdesign.com
 *
 */


/*
///////////////////////////////////////////////////////////

// création d'1 liste de styles

 -----------------------------------------------------------------
*/
function themeit_mce_buttons_2( $buttons ) {
  array_unshift( $buttons, 'styleselect' );
  return $buttons;
}
add_filter( 'mce_buttons_2', 'themeit_mce_buttons_2' );
function themeit_tiny_mce_before_init( $settings ) {
  $settings['theme_advanced_blockformats'] = 'p,h2,h3,h4';
  $style_formats = array(
      array( 'title' => 'Introduction', 'selector' => 'p', 'classes' => 'intro' ),
      array( 'title' => 'Bouton jaune', 'selector' => 'a', 'classes' => 'cs-btn cs-btn-flat cs-btn-pill cs-btn-flat-yellow cs-btn-xs cs-btn-no-uppercase' ),
      array( 'title' => 'Bouton contour jaune', 'selector' => 'a', 'classes' => 'cs-btn cs-btn-flat cs-btn-pill cs-btn-flat-border-yellow cs-btn-xs cs-btn-no-uppercase' ),
      array( 'title' => 'Bouton gris', 'selector' => 'a', 'classes' => 'cs-btn cs-btn-flat cs-btn-pill cs-btn-flat-grey cs-btn-xs cs-btn-no-uppercase' ),
      array( 'title' => 'Bouton contour gris', 'selector' => 'a', 'classes' => 'cs-btn cs-btn-flat cs-btn-pill cs-btn-flat-border-grey cs-btn-xs cs-btn-no-uppercase' ),
  );
  $settings['style_formats'] = json_encode( $style_formats );
  return $settings;
}
add_filter( 'tiny_mce_before_init', 'themeit_tiny_mce_before_init' );



/*
///////////////////////////////////////////////////////////

// Nettoyage du code de Microsoft Word

 -----------------------------------------------------------------
*/
function cleanHTML($html) {
$html = preg_replace("~<(/)?(font|span|del|ins)[^>]*>~i","",$html);
$html = preg_replace("~<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>~i", "<$1>", $html);
return $html;
}