0

I have a small filter below. It does a regular expression replace of a particular string when the user saves the draft.

However, using this filter causes the warning "The backup of this post in your browser is different from the version below."

Is there a way to 'tell' Wordpress not to display the warning when that filter runs?

To re-create:

  1. Create a draft post.

  2. In the body, enter a line of text:

    rcq[whatever]

    eg.

    rcqTestMsg

  3. Save the draft.

Here is the code.

UPDATE: WHAT I THINK IS GOING ON: I think that somehow this is triggering the autosave.js CheckPost() function which (apparently) compares the text on screen with the current saved version. Is there a way to disable the autosave or revision just when this filter is triggered? Or is there something in my code that is confusing the revision system?


function jchwebdev_rant_quote_question( $content ) { global $post; $pattern = '/rcq/'; $replacement = 'RC$1'; if ($post->post_status == 'draft') { return preg_replace($pattern, $replacement, $content); } else return $content; } add_filter( 'content_save_pre' , 'jchwebdev_rant_quote_question' , 10, 1);

  • I used the same code but didn't get any warnings like that on the edit post page. – Ahmed Fouad Sep 27 '16 at 21:02
  • Was your post in draft mode? It only displays the Warning when post is in draft mode. – jchwebdev Sep 27 '16 at 21:25
  • Certainly it was a draft post. Tried for almost 10minutes and got no warning still. – Ahmed Fouad Sep 27 '16 at 21:26
  • Please see my update. It gives a method to re-create. Can you test and let me know if you get the Warning? Thanks in advance. – jchwebdev Sep 27 '16 at 23:08
  • Could you please edit your question again with correct function? it's messed up now. – Ahmed Fouad Sep 27 '16 at 23:11
1

The way to avoid this error is to make sure the wp-saving-post cookie is being set to a value of [post id]-saved, as seen here. As you can see, if that occurs, then WordPress won't complain about the difference, because it then knows that the post was saved properly.

Also take a look at this line and note that WordPress handles this for you already. So the error you're seeing, it likely has to do with some mild cookie corruption in your browser.

I ran several tests with your plugin and I was unable to reproduce the issue that you reported. So my feeling is that you should clear all browser cookies for your domain and eliminate the possibility of corruption causing the problem. Also be sure to do a review of WordPress config settings related to cookie storage. If there's something wrong with cookie settings on your site, it may have an impact on the behavior that you're seeing when running tests against this.

Finally, check to be sure you're not filtering the content, and then immediately redirecting, or exiting the script, or doing something else that would prevent this line from running once your filter is applied. That too, may lead to the problem that you're seeing.

0

i think javascript will help you. Use this code, and see if it helps:

add_action( 'add_meta_boxes', function () { add_meta_box('myhtml_ID_123',  'smth', 'draft_title_remover');} );
function draft_title_remover( $post ) { ?>
    <script>
    nIntervId = setInterval(RemoveMyDiv, 1000);
    function RemoveMyDiv() {
      if(document.getElementById("message")){
          var x = document.getElementById("message");
          if( x.innerHTML.indexOf("The backup of this post in your browser") > -1){
            x.style.display="none";
          }
      }
    }
    </script>
    <?php 
}
-1

The possible reason of getting warning can be solved from your wp-config.php file. Check if in this file WP_DEBUG is true or false. If you don't want to see warnings then it must be set to false like this

define('WP_DEBUG', false);

If your WP_DEBUG is true (define('WP_DEBUG', true);) then simply make it false(define('WP_DEBUG', false);).

However if this don't work for your then try to replace your WP_DEBUG Change your following line of code

define('WP_DEBUG', false);

Into this

ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Note: Before trying any change in this file, first take backup of it Because if you mistakenly did any mistake while changing code then it may cause some unwanted problems.

  • 3
    I don't think this has anything to do with that 'Warning'. It's not a PHP notice or error or Warning. – jchwebdev Sep 28 '16 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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