Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

TinyMCE editor problems

Open dk-wordpress opened this issue 10 years ago • 7 comments

Hi guys!

It seems, i can't add custom styles for Uyson TinyMCE editor. For example, this code totally not working with Unyson Text Editor +breaks Visual Page Builder button (but it works for WPTinyMCE default editor):

add_filter( 'tiny_mce_before_init', 'add_tinymce_styles' );  

function add_tinymce_styles( $init_array ) {

    $style_formats = array(
        'title' => esc_html__('Custom styles', 'mytheme'),
        'items' => array(
            'title' => esc_html__('UPPERCASE TEXT', 'mytheme'),
            'inline' => 'span',
            'styles' => array( 'text-transform' => 'uppercase' )
        ) 
    );

    // Insert the array, JSON ENCODED, into 'style_formats'     
    $init_array['style_formats'] = json_encode( $style_formats );
  $init_array['fontsize_formats'] = '10px 12px 14px 16px 18px 20px 22px 24px 26px 28px 30px 32px 34px 36px 38px 40px';          
    return $init_array; 
}

is it a bug or feature xD thank you!

dk-wordpress avatar Aug 22 '16 08:08 dk-wordpress

When testing your exact code, I'm getting an error even if the Page Builder is disabled for the current post type and even if the wp-editor is not present on the current page. That is, you are doing something wrong at the TinyMce level. Please, check the main documentation for the feature you're using and test your example more rigorously.

I'm gonna close this issue for now and if you find something wrong in wp-editor option type -- feel free to re-open it.

andreiglingeanu avatar Aug 22 '16 12:08 andreiglingeanu

Hello! First of all - thanks for your great job! Unyson is really great! I'm using last version of WP and Unyson Version 4.6 | Unyson 2.5.12 I'm trying to use style formats according to Codex : https://codex.wordpress.org/TinyMCE_Custom_Styles#Using_style_formats In a default WP Editor it works: http://prntscr.com/cboq5m

But when i toggle to Visual Page Builder, formats dropdown is showing me default formats: http://prntscr.com/cboqrp

What I'm doing wrong?

Thanks!

yura-x avatar Aug 29 '16 13:08 yura-x

Hi,

Not sure if it will help, try this Unyson version

ghost avatar Aug 29 '16 13:08 ghost

Thanks, I have same issue in v 2.6.0

yura-x avatar Aug 29 '16 14:08 yura-x

@yura-x Please post here the code you are using.

andreiglingeanu avatar Aug 30 '16 13:08 andreiglingeanu

Hello! I'm using code snippet from the Codex; It's slightly modified:

//adding custom styles to TinyMCE
// Callback function to insert 'styleselect' into the $buttons array
if ( !function_exists( '_filter_mce_theme_format_insert_button' ) ) :
    function _filter_mce_theme_format_insert_button( $buttons ) {
        array_unshift( $buttons, 'styleselect' );
        return $buttons;
    }
endif; //_filter_mce_theme_format_insert_button
// Register our callback to the appropriate filter
add_filter( 'mce_buttons_2', '_filter_mce_theme_format_insert_button' );
// Callback function to filter the MCE settings
if ( !function_exists( '_filter_mce_theme_format_add_styles' ) ) :
    function _filter_mce_theme_format_add_styles( $init_array ) {
        // Define the style_formats array
        $style_formats = array(
            // Each array child is a format with it's own settings
            array(
                'title' => __('Excerpt'),
                'block' => 'p',
                'classes' => 'entry-excerpt',
                'wrapper' => false,
            ),
            array(
                'title' => 'Paragraph with dropcap',
                'block' => 'p',
                'classes' => 'big-first-letter',
                'wrapper' => false,
            ),
            array(
                'title' => 'Main theme color',
                'inline' => 'span',
                'classes' => 'highlight',
                'wrapper' => false,
            ),

        );
        // Insert the array, JSON ENCODED, into 'style_formats'
        $init_array['style_formats'] = json_encode( $style_formats );

        return $init_array;

    }
endif; //_filter_mce_theme_format_add_styles
// Attach callback to 'tiny_mce_before_init'
add_filter( 'tiny_mce_before_init', '_filter_mce_theme_format_add_styles' );

yura-x avatar Aug 30 '16 13:08 yura-x

Please refer to https://github.com/ThemeFuse/Unyson/issues/1932#issuecomment-245532878 and try to use the same code.

andreiglingeanu avatar Sep 08 '16 08:09 andreiglingeanu