140 lines
3.3 KiB
PHP
140 lines
3.3 KiB
PHP
<?php
|
|
|
|
// Enable formats (styleselect) in TinyMCE
|
|
add_filter( 'mce_buttons', 'headless_tinymce_styleselect' );
|
|
function headless_tinymce_styleselect( $buttons ) {
|
|
array_unshift( $buttons, 'styleselect' );
|
|
return $buttons;
|
|
}
|
|
|
|
// Configure TinyMCE
|
|
add_filter( 'tiny_mce_before_init', 'headless_tiny_mce_before_init' );
|
|
function headless_tiny_mce_before_init( $settings ) {
|
|
// Reset TinyMCE editor CSS
|
|
if ( isset( $settings['content_css'] ) ) {
|
|
$content_css = explode( ',', $settings['content_css'] );
|
|
unset( $content_css[1] ); // wp-content.min.css
|
|
$settings['content_css'] = implode( ',', $content_css );
|
|
}
|
|
|
|
// Format styles
|
|
$settings['style_formats'] = wp_json_encode(
|
|
array(
|
|
array(
|
|
'title' => "Caractères",
|
|
'items' => array(// Inline styles
|
|
array(
|
|
'title' => __( "Semi-bold", 'headless' ),
|
|
'inline' => 'span',
|
|
'classes' => 'font-semibold',
|
|
),
|
|
),
|
|
),
|
|
array(
|
|
'title' => "Liens",
|
|
'items' => array(// Link styles
|
|
array(
|
|
'title' => "Lien (opacité)",
|
|
'selector' => 'a',
|
|
'classes' => 'link-opacity',
|
|
),
|
|
),
|
|
),
|
|
array(
|
|
'title' => "Listes",
|
|
'items' => array(// List styles
|
|
array(
|
|
'title' => "Liste horizontale",
|
|
'selector' => 'ul,ol',
|
|
'classes' => 'list-horizontal',
|
|
),
|
|
),
|
|
),
|
|
array(
|
|
'title' => "Paragraphes",
|
|
'items' => array(// Paragraph styles
|
|
array(
|
|
'title' => "Paragraphe vedette",
|
|
'block' => 'p',
|
|
'classes' => 'paragraph-lead',
|
|
),
|
|
),
|
|
),
|
|
array(
|
|
'title' => "Titres",
|
|
'items' => array(// Heading styles
|
|
array(
|
|
'title' => "Titre 1",
|
|
'selector' => 'h1,h2,h3,h4',
|
|
'classes' => 'heading-1',
|
|
),
|
|
array(
|
|
'title' => "Titre 2",
|
|
'selector' => 'h1,h2,h3,h4',
|
|
'classes' => 'heading-2',
|
|
),
|
|
array(
|
|
'title' => "Titre 3",
|
|
'selector' => 'h1,h2,h3,h4',
|
|
'classes' => 'heading-3',
|
|
),
|
|
array(
|
|
'title' => "Titre 4",
|
|
'selector' => 'h1,h2,h3,h4',
|
|
'classes' => 'heading-4',
|
|
),
|
|
),
|
|
),
|
|
)
|
|
);
|
|
|
|
// Block styles
|
|
$settings['block_formats'] = implode(
|
|
';',
|
|
array(
|
|
'Paragraph=p',
|
|
'Heading 1=h1',
|
|
'Heading 2=h2',
|
|
'Heading 3=h3',
|
|
'Heading 4=h4',
|
|
)
|
|
);
|
|
|
|
return $settings;
|
|
}
|
|
|
|
// Override TinyMCE editor styles
|
|
add_filter( 'mce_css', 'headless_override_editor_styles' );
|
|
function headless_override_editor_styles() {
|
|
return get_stylesheet_directory_uri() . '/editor-style.css';
|
|
}
|
|
|
|
// Remove default TinyMCE styles for all editors (WordPress & ACF)
|
|
add_action( 'admin_print_footer_scripts', 'headless_remove_tinymce_default_styles', 99 );
|
|
function headless_remove_tinymce_default_styles() {
|
|
?>
|
|
<script>
|
|
(function($) {
|
|
if (typeof tinymce !== 'undefined') {
|
|
tinymce.on('AddEditor', function({editor}) {
|
|
editor.on('init', function() {
|
|
$(editor.iframeElement).contents().find("link[href*='content.min.css']").remove();
|
|
});
|
|
});
|
|
}
|
|
})(jQuery);
|
|
</script>
|
|
<?php
|
|
}
|
|
// Convert absolute URLs to relative in link query
|
|
add_filter( 'wp_link_query', 'headless_tinymce_relative_urls' );
|
|
function headless_tinymce_relative_urls( $results ) {
|
|
foreach ( $results as &$result ) {
|
|
if ( empty( $result['permalink'] ) ) {
|
|
continue;
|
|
}
|
|
$result['permalink'] = str_replace( get_home_url(), '', $result['permalink'] );
|
|
}
|
|
return $results;
|
|
}
|