editor_config();
//Fix a few non-optimal things
$this->send_to_editor();
}
private function send_to_editor(){
add_filter('image_send_to_editor', function($html, $id, $captions, $title, $align, $url, $size, $alt){
// return $html;
$img_src = wp_get_attachment_image_src($id, $size);
$img_url = $img_src[0];
$img_width = $img_src[1]; //The width is required for Wordpress Editor to stop crying.
$img_height = $img_src[2]; //We can use this to fix some foucs, through javascript data-vars
$height_vs_width = round(($img_height / $img_width), 2);
$no_captions = '';
$img_classes = array();
if($url){
$link_prefix = '';
$link_suffix = '';
}else{
$link_prefix = '';
$link_suffix = '';
}
//What if we insert an icon? Oh well, let's override in that case!
if($img_width <= 225 || $img_height <= 225){
$caption_class = ' too-tiny-for-captions';
}
if($captions){
//Prepare caption output - is used only if captions are available
$caption_prefix = '[caption id="attachment_'.$id.'" align="align'.$align.'" width="'.$img_width.'" class="sircontheme-inserted"]';
$caption_suffix = ' '.$captions.'[/caption]';
}else{
/* No caption, make sure the image gets alignment class */
$img_classes[] = 'align'.$align;
}
//prepare classes
$img_classes = $img_classes
? ' class="'.implode(' ', $img_classes).'"'
: '';
$new_html = $caption_prefix.
$link_prefix.
'
'.
$link_suffix
.$caption_suffix;
return $new_html;
}, 9001, 8);
}
/* Responsive images do not care much for static selection of size */
private function editor_config(){
add_action('tiny_mce_before_init', function($mceInit){
$mceInit['block_formats'] = 'Paragraph=p;Header 1=h1;Header 2=h2;Header 3=h3;Header 4=h4;Header 5=h5;Header 6=h6;Blockquote=blockquote';
/*
$mceInit['setup'] .= "function(ed){
setInterval(function(){
//regular tweaks
}, 500);
}";/**/
$valid_children =array(
'-p[img|figure]',
'+body[img]'
);
$mceInit['valid_children'] .= implode(',', $valid_children);/**/
//$mceInit['forced_root_block'] = false;/* This does bad things */
return $mceInit;
});
}
}