Skip to content

Instantly share code, notes, and snippets.

@johnpbloch
Last active November 17, 2015 23:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save johnpbloch/16426869cf455de9b209 to your computer and use it in GitHub Desktop.
<?php
namespace JPB\Yassss;
add_filter( 'wp_insert_post_data', __NAMESPACE__ . '\\replace_values' );
function replace_values( $post_data ) {
$content = empty( $post_data['post_content'] ) ? '' : $post_data['post_content'];
$content = str_replace( '{{ my_marker }}', some_really_long_running_function(), $content );
$post_data['post_content'] = $content;
return $post_data;
}
<?php
namespace JPB\WTF;
add_action( 'save_post', __NAMESPACE__ . '\\replace_values' );
function replace_values( $post_id ) {
$content = get_post( $post_id )->post_content;
$content = str_replace( '{{ my_marker }}', some_really_long_running_function(), $content );
remove_action( 'save_post', __FUNCTION__ );
wp_update_post( [ 'ID' => $post_id, 'post_content' => $content ] );
add_action( 'save_post', __FUNCTION__ )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment