Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using WP 3.4. My problem occurs when I attempt to copy and paste anything into the post or page editor of WordPress. The situation arises every time I save or attempt to preview the post. The post gets truncated and about 65% of the text gets chopped off the end of the post. This does not happen if I manually enter content into the text box and then preview or save it.

This works well on my other WP site but not this new install. I have used text editors to strip out formatting. I have also used the text editor copy and paste feature within WordPress but nothing works.

Here’s some background. I first installed WordPress 3.4 through Bluehost. That's when I discovered the problem. I then reinstalled WP through BlueHost. This did nothing to resolve the issue. I then downloaded WordPress and uploaded it to BlueHost but the problem still exists.

I tried using the 20/10 theme. Then I tried using the Genesis Framework theme. I also tried using the Genesis Framework with the Prose child theme. The problem would occur each and every time. I should note here that all plugins are turned off while attempting to create a post.

I did not link to the site as it is under construction and the only post available was manually entered into the text editor and saved which does not cause a problem.

Here is an example of what happens. I copy this text into the text box.

I have been involved in Local SEO long enough to remember my old friend the Local Business Center. This service offered free business listing similar to a local directory site. I thought what a great idea.
The fact that these listings were being featured by Google for local searches made them extremely useful. If your local website was having problems, ranking in the organic results this was a godsend.
In the early days just claiming or setting up a listing got your business onto the first page of the Google results. It was often a one and done situation for many small business owners.
With little or no effort, you could easily land on the first page of the Google results in most markets. Moreover, this wasn’t always true for many websites trying to get onto Google results front page.

(for the full text see revision history)

This is what is left after I save or preview it.

"I have been involved in Local SEO long enough to remember my old friend the Local Business Center. This service offered free business listing similar to a local directory site. I thought what a great idea.
The fact that these listings were being featured by Google for local searches made them extremely useful. If your local website was having problems, ranking in the organic results this was a godsend.
In the early days just claiming or setting up a listing got your business onto the first page of the Google results. It was often a one and done situation for many small business owners.
With little or no effort, you could easily land on the first page of the Google results in most markets. Moreover, this wasn"

It also occurs with much smaller posts as well.

I have been working on this problem for about a week and could use any help available.

share|improve this question
    
Have you done a full troubleshooting? Also, have you searched WordPress forums? There are lots of "3.4 upgrade" topics there... –  brasofilo Jun 25 '12 at 0:04
    
Please could anyone give more details on how to apply these fixes? for example: exactly WHERE can we find the files that should be set to UTC-8? How do we assure that everything we copy is UTC-8 compatible? Where exactly would we put your "plugin" in wordpress to make it work? Thank you, Sandra –  user18845 Aug 3 '12 at 10:00
    
@Sandra Install the code as plugin. You can download it from here. –  toscho Aug 3 '12 at 10:32

3 Answers 3

Your browser doesn’t send the copied text UTF-8 encoded to the server. On the first character that isn’t UTF-8 compatible, in your example the apostrophe – ’ –, the stream to the data base is broken and not recovered. That’s a browser issue.
If I had to guess – well, I have because you didn’t mention it – I would say Internet Explorer.

There are two ways to fix that.

  1. Get a better browser.

  2. Make sure everything you try to save is UTF-8 compatible. And here is finally a chance to bring this issue on topic for our site. :)

You can filter 'wp_insert_post_data' and prepare all the data. The following code should work as a plugin (not tested, it is just a prototype).

<?php
/* Plugin Name: Force UTF-8 */
add_filter( 'wp_insert_post_data', 'wpse_56411_force_utf8' );

function wpse_56411_force_utf8( $data ) 
{
    $out = array();
    foreach ( $data as $key => $value )
    {
        if ( ! seems_utf8( $value ) )
        {
            if ( function_exists( 'mb_convert_encoding' ) )
            {
                $out[ $key ] = mb_convert_encoding( $value, 'UTF-8', 'windows-1252' );
            }
            elseif ( function_exists( 'iconv' ) )
            {
                $out[ $key ] = iconv( 'windows-1252', 'UTF-8', $value );
            }
            else
            {
                $out[ $key ] = utf8_encode( $value );
            }
        }
        else
        {
            $out[ $key ] = $value;
        }
    }
    return $out;
}
share|improve this answer
    
That's the amazing analytical eye that all sees in this site. +1+ –  brasofilo Jun 25 '12 at 0:46
    
Ok, what browser would you suggest? I have tried using the latest version of Chrome,Firefox 10.02 and 12.0. It doesn't work with any of these. I have also tried using 2 different computers. As for the code suggestion that's way above my skill set. Nothing works. Ok, what browser would you suggest? –  Urban Scurry Jun 25 '12 at 5:09
    
If none of these browsers work something on your server changes the data after you sent it. Could be a wrongly configured security module or the database connection/storage. Ask your web hoster. –  toscho Jun 25 '12 at 10:00
    
@toscho nice example for bracket style, there is not easy to read ;) #insider –  bueltge Aug 3 '12 at 21:21

The problem is fixed. I had the location setting as UTC 7 for Arizona. When that was changed everything worked. WOW! Thanks for the help!

share|improve this answer
4  
...Ummm... what? Your timezone has nothing to do with it. Don't confuse UTC with UTF. –  Otto Aug 3 '12 at 21:33

I had the problem just as well, first Umlaut (or in other term: first non-ascii latin1-character aka first invalid unicode character) and things got truncated on save. I am on Firefox 15, not IE.

Root cause: Client requests require me to deliver latin1 and (hence?) work with a latin1 database (aka ISO-8559-1, let's skip the subtleties).

Fixed in wp-config.php by:

  • define('DB_CHARSET', 'latin1'); //this one matters mosted
  • define('DB_COLLATE', 'latin1_swedish_ci');

Before I did this, I converted my database to latin1 (exporting in phpmyadmin, a bunch of search and replace, re-import). I think, the latter doesn't matter (though it makes sense to have), the first part does: Invalid unicode (aka latin1) does not like to travel accross a utf8 connection.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.