Support » Plugins » Hacks » Preventing Function Running at Post Preview

  • I’m writing a function that runs when a post is saved in the Edit Post panel, hooked onto the save_post action hook.

    I’m having problems preventing the function running also when the Preview button is pressed. Can anyone tell me how to stop this happening? It doesn’t need to run at this point (when it does, it breaks my plugin), as long as it does run when the update/publish button is pressed.



Viewing 2 replies - 1 through 2 (of 2 total)
  • OK, no idea if this is the correct way to do it, but I managed to find out that there’s an item in the $_POST array that gets sent when the post is previewed that can be tested for, and can then end my save_post function early, before it screws up.

    So I basically added

    if( in_array( 'dopreview', $_POST ) )
    		return $post_id;

    at the start of my function.

    As I said, no no idea if this is the proper way (I suspect not), but it seems to work at the moment.


    Can anyone tell me if the above is correct?



Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Preventing Function Running at Post Preview’ is closed to new replies.