Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter begona.alvarezd

    (@begonaalvarezd)

    What I would like to explain is the situation when you or me or anybody take a piece of code from: sublime text or eclipse or notepad++ or any code editor…and paste it in the visual editor of tinyMCE.

    In a normal plain text area, like this forum for example, If I copy and paste part of my code here it looks like this:

    function woo_add_custom_general_fields_save( $post_id ){
    
    	// Text Field subtitle
    	$woocommerce_subtitle_field = $_POST['_subtitle_field'];
    	if( !empty( $woocommerce_subtitle_field ) )
    		update_post_meta( $post_id, '_subtitle_field', esc_attr( $woocommerce_subtitle_field ) );
    
    	// Text Field Documentation url
    	$woocommerce_subtitle_field = $_POST['_documentation_url'];
    	if( !empty( $woocommerce_subtitle_field ) )
    		update_post_meta( $post_id, '_documentation_url', esc_attr( $woocommerce_subtitle_field ) );
    
    }

    But doing it in the visual editor of TinyMCE Advanced has the following result:

    function woo_add_custom_general_fields_save( $post_id ){
    
    // Text Field subtitle
    $woocommerce_subtitle_field = $_POST['_subtitle_field'];
    if( !empty( $woocommerce_subtitle_field ) )
    update_post_meta( $post_id, '_subtitle_field', esc_attr( $woocommerce_subtitle_field ) );
    
    // Text Field Documentation url
    $woocommerce_subtitle_field = $_POST['_documentation_url'];
    if( !empty( $woocommerce_subtitle_field ) )
    update_post_meta( $post_id, '_documentation_url', esc_attr( $woocommerce_subtitle_field ) );
    
    }

    As you can see the white spaces at the beginning of each line are gone.

    I didn’t mean that I want to keep HTML tags since copying and pasting from a plain text editor has nothing to do with HTML tags, I just wanted to keep the white spaces that give structure to the code.

    And my main point is that…while having teeny : true this white spaces DONT disappear.

    So there has to be an internal configuration of tinyMCE that is removing this white spaces.

    Thanks! 🙂

    Thread Starter begona.alvarezd

    (@begonaalvarezd)

    Hi Andrew, I wrote also in my post (see that there are two instead of just one, I wrote twice) :

    I am using your plugin mainly for BBPress Forum and I just realized that is BBPress who is setting teeny to true.

    I also attached the code that is actually doing it.

    Additionally, I already tested deactivating the syntax highlighter. It is inferring zero in the way of writing in the editor, syntax highlighter just works after pressing the button “submit” so the issue is not there.

    Is there some configuration that I am missing to force tinyMCE to keep formatted text? Some idea then how to force tinyMCE to preserve my indentations? I’ve tried several configurations and none of them successfully 🙁

    Thread Starter begona.alvarezd

    (@begonaalvarezd)

    You also suggested:

    Best way to keep pasted code properly formatted is to use one of the syntax highlighting plugins

    I am using Crayon Syntax Highlighter already, but it looks like it has no effect in the way of pasting and formatting indentations. It just highlights code. Any idea or advised plugin?

    PS: still would be better to find some configuration I could add like:

    function my_format_TinyMCE( $in ) {
    	$in['content_css'] = home_url() . "/wp-content/themes/tisson-child/tinyMCE-editor-style.css";
    	$in['entity_encoding'] = "named"; //something like this but working!!
    	return $in;
    }
    add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );
    Thread Starter begona.alvarezd

    (@begonaalvarezd)

    I am using your plugin mainly for BBPress Forum and I just realized that is BBPress who is setting teeny to true.

    function bbp_get_the_content( $args = array() ) {
    
    		// Parse arguments against default values
    		$r = bbp_parse_args( $args, array(
    			'context'           => 'topic',
    			'before'            => '<div class="bbp-the-content-wrapper">',
    			'after'             => '</div>',
    			'wpautop'           => true,
    			'media_buttons'     => false,
    			'textarea_rows'     => '12',
    			'tabindex'          => bbp_get_tab_index(),
    			'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags',
    			'editor_class'      => 'bbp-the-content',
    			'tinymce'           => false,
    			'teeny'             => true,
    			'quicktags'         => true,
    			'dfw'               => false
    		), 'get_the_content' );
    ......etc

    This code is in bbpress/includes/common/template.php

    Some idea then how to force tinyMCE to preserve my indentations? I’ve tried several configurations and none of them successful 🙁

    I need teeny to be false since I have custom buttons and they dont appear if teeny is true. And on the other hand I miss indentations when teeny is set to false. Is there some configuration that I am missing to force tinyMCE to keep formatted text?

    Thank you very much for your help!

    Thread Starter begona.alvarezd

    (@begonaalvarezd)

    I am already using a plugin to highlight code.
    I am currently using Crayon Syntax Highlighter. It is a real pity because I managed to have everything working so super nice but this problem pasting indentation can be a nightmare…since our forum is mainly to solve software issues.

    I don’t understand why this is happening and how is possible that activating tenny leads to a correct pasting action.

    Thread Starter begona.alvarezd

    (@begonaalvarezd)

    Thank you very much for your response Andrew.

    If I may ask you, I would like to understand what is going on exactly and maybe try to fix it my myself, but I dont have the time to study in deep your entire code.

    As I posted above

    I figured out that removing the line $args['teeny'] = false; from my above code fixes this problem

    . How is it possible that deactivating this “tiny tinyMCE” then I loose all my indentation?

    The behavior is as follows:

    Original Code:

    if ( typeof window.tadvTranslation === 'object' ) {
    		$( '.tadvitem' ).each( function( i, element ) {
    			var $element = $( element ),
    				$descr = $element.find( '.descr' ),
    				text = $descr.text();
    
    			if ( text ) {
    				text = translate( text );
    				$descr.text( text );
    				$element.find( '.mce-ico' ).attr( 'title', text );
    			}
    		});
    
    		$( '#tadv-mce-menu .tadv-translate' ).each( function( i, element ) {
    			var $element = $( element ),
    				text = $element.text();
    
    			if ( text ) {
    				$element.text( translate( text ) );
    			}
    		});
    	}

    Pasting code in tinymCE visual editor with $args['teeny'] = false;

    if ( typeof window.tadvTranslation === 'object' ) {
    $( '.tadvitem' ).each( function( i, element ) {
    var $element = $( element ),
    $descr = $element.find( '.descr' ),
    text = $descr.text();
    
    if ( text ) {
    text = translate( text );
    $descr.text( text );
    $element.find( '.mce-ico' ).attr( 'title', text );
    }
    });
    
    $( '#tadv-mce-menu .tadv-translate' ).each( function( i, element ) {
    var $element = $( element ),
    text = $element.text();
    
    if ( text ) {
    $element.text( translate( text ) );
    }
    });
    }

    Pasting code in tinymCE visual editor without $args['teeny'] = false;

    if ( typeof window.tadvTranslation === 'object' ) {
    
    		$( '.tadvitem' ).each( function( i, element ) {
    
    			var $element = $( element ),
    
    				$descr = $element.find( '.descr' ),
    
    				text = $descr.text();
    
    			if ( text ) {
    
    				text = translate( text );
    
    				$descr.text( text );
    
    				$element.find( '.mce-ico' ).attr( 'title', text );
    
    			}
    
    		});
    
    		$( '#tadv-mce-menu .tadv-translate' ).each( function( i, element ) {
    
    			var $element = $( element ),
    
    				text = $element.text();
    
    			if ( text ) {
    
    				$element.text( translate( text ) );
    
    			}
    
    		});
    
    	}

    There is really something happening that escapes from my knowledge.

    If you dont have a child theme activated, it will get deleted as soon as you theme is updated. Child-themes are to prevent this kind of problems. If you dont activate one, just have a copy of that file somewhere to upload it again when your theme is updated. Keep it in mind and hopefully the plugin developers will fix it soon.

    PS: pay attention on the new update of the yith plugin, if you experience something weird with the future update, remove what you just created. Or just post something in this topic and I will receive an email notifying me your problem 🙂 Happy to help!

    I found a beautiful solution for this after studying their code.
    Just go to your theme directory (or child-theme better if you have one) and create a folder called: single-product

    Inside that directory, copy the file product-thumbnails-magnifier.php of the yith plugin that you find in: wp-content/plugins/yith-woocommerce-zoom-magnifier/templates/single-product/product-thumbnails-magnifier.php

    There, just below the line 17 that says:

    if ( ! empty( $attachment_ids ) ) array_unshift( $attachment_ids, get_post_thumbnail_id() );

    paste the following:

    $attachment_ids = array_unique($attachment_ids);

    And voilá! It works! The problem is that the array generated in line 17 returns a duplicated ID. With my code I am just forcing this array of IDs to contain only unique numbers and not duplicated ones.

    I found a beautiful solution for this after studying their code.
    Just go to your theme directory (or child-theme better if you have one) and create a folder called: single-product

    Inside that directory, copy the file product-thumbnails-magnifier.php of the yith plugin that you find in: wp-content/plugins/yith-woocommerce-zoom-magnifier/templates/single-product/product-thumbnails-magnifier.php

    There, just below the line 17 that says:

    if ( ! empty( $attachment_ids ) ) array_unshift( $attachment_ids, get_post_thumbnail_id() );

    paste the following:

    $attachment_ids = array_unique($attachment_ids);

    And voilá! It works! The problem is that the array generated in line 17 returns a duplicated ID. With my code I am just forcing this array of IDs to contain only unique numbers and not duplicated ones.

    Some improvement here? I am experiencing the same issue. WooCommerce has been updated a few weeks ago and maybe the last update of YITH Zoom Magnifier is not fixing this problem anymore.

    I will keep looking for a solution by myself meanwhile and will share it if I find how.

Viewing 10 replies - 1 through 10 (of 10 total)