Skip to content

Instantly share code, notes, and snippets.

@kovshenin
Created May 20, 2012 04:21
Show Gist options
  • Select an option

  • Save kovshenin/2745451 to your computer and use it in GitHub Desktop.

Select an option

Save kovshenin/2745451 to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: Foo Bar
*/
add_action( 'save_post', 'my_save_post' );
function my_save_post( $post_id ) {
if ( wp_is_post_revision( $post_id ) )
return;
$post = get_post( $post_id );
$post->post_content = str_replace( 'foo', 'bar', $post->post_content );
remove_action( 'save_post', 'my_save_post' ); // избегаем infinite loop
wp_update_post( $post );
add_action( 'save_post', 'my_save_post' ); // добавляем хук обратно
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment