A
A
Aligatro2017-09-12 03:43:44
JavaScript
Aligatro, 2017-09-12 03:43:44

How to remove styles when copying text in tinymce wordpress?

Goodnight. Strictly speaking subject. I tried almost everything, but when copying text from the site, tinymce still pulls up the styles. The filter now stands with the following settings:

function my_format_TinyMCE( $in ) {
  global $post;
    $post_type = get_post_type( $post->ID );
    if( $post_type == 'pubedit'){
    $in['remove_linebreaks'] = false;
    $in['gecko_spellcheck'] = false;
    $in['keep_styles'] = false;
    $in['accessibility_focus'] = false;
    $in['tabfocus_elements'] = 'major-publishing-actions';
    $in['media_strict'] = false;
    $in['paste_remove_styles'] = true;
    $in['paste_remove_spans'] = true;
    $in['paste_strip_class_attributes'] = 'none';
    $in['paste_text_use_dialog'] = false;
    $in['wpeditimage_disable_captions'] = true;
    $in['plugins'] = 'wordpress,wplink';
    //$in['content_css'] = get_template_directory_uri() . "/editor-style.css";
    $in['wpautop'] = true;
    $in['apply_source_formatting'] = false;
    $in['block_formats'] = "Paragraph=p";
    $in['toolbar1'] = 'bold, italic, underline, strikethrough, link, unlink';
    $in['toolbar2'] = '';
    $in['toolbar3'] = '';
    $in['toolbar4'] = '';
    return $in;
  } else {
    $in['toolbar1'] = 'bold,italic,strikethrough,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,wp_fullscreen,wp_adv ';
    $in['toolbar2'] = 'formatselect,underline,alignjustify,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help ';
    $in['toolbar3'] = '';
    $in['toolbar4'] = '';
    return $in;
  }
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );

If anyone faced similar problem, please advise how to solve it.

Ps I can copy without styles on my own, it is important for me that site users cannot copy styles.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Aligatro, 2017-09-14
@Aligatro

Still solved the problem. Even I completely forgot to connect the tinymce paste plugin.
As a result, it is enough to make the following settings:

function my_format_TinyMCE( $in ) {
  $in['keep_styles'] = false;
  $in['paste_remove_styles'] = true;
  $in['paste_remove_spans'] = true;
  $in['paste_as_text'] = true;
  $in['plugins'] = 'wordpress,wplink,paste';
  return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );

Most importantly, this will prevent any user from pasting text while maintaining styles.

E
EvgenyMorozov, 2017-09-12
@EvgenyMorozov

In this case, I insert not in visual, but in text mode.

A
Alexander, 2017-09-12
@mais64

ctrl+shift+v

Paste as text.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question