You can use the pre_post_update
filter hook to achieve this.
Unfortunately the Codex isn’t very good for this hook, but it’s a simple enough one to understand and can be found in wp-includes/post.php
on line 3335 (WP 4.1).
add_filter( 'pre_post_update', 'my_replace_shortcode', 2, 99 );
function my_replace_shortcode( $post_id, $data ){
if(strpos($data['post_content'], '[myshorcode param1="') !== false) :
$data['post_content'] = do_shortcode('[myshorcode param1="aa" param2 = "bb"]');
endif;
return $data;
}
What’s happening here is a check to see if the post_content
part of the post contains [myshorcode param1="
(only check up to here as the value of param1
will change), and if it does, the whole of post_content
is replaced with the results of your shortcode.
The pre_post_update
filter hook is fired right before the post is inserted/updated in the database, and it is fired regardless of whether the post is being inserted or updated. You can check if it’s a new post and only run on that condition if necessary though.
You can also check for a post type if required, or any number of conditions seeing as you basically have the Post that is about to be inserted.