OK, so the new_to_publish
hook is probably not the right hook to use here.
The status_to_status
hooks run during a posts transition from the first status to the second. By this stage, the editor is no longer in play.
If my understanding of the_editor_content
is correct, this filters the default content displayed in the editor when the post edit screen is loaded.
Do you need the signature to be appended to the actual post content within the database or just to display the on the front end?
If the latter, you could use the the_content
filter…
function mh_add_signature_after_content( $content ) {
global $post;
$signature="";
// Specify the post type on which to display, otherwise you'll see on pages also!
if ( 'post' == $post->post_type ) {
$author_name = get_the_author_meta( 'display_name', 25 );
$signature="<br><br><br><br><br>--<br>" . $author_name;
}
return $content . $signature;
} // kbs_after_article_content
add_filter( 'the_content', 'mh_add_signature_after_content', 999 );
The result of this would be that in the post edit screen, the editor will display the post content, no signature. But when loaded on the front end of your site, the post will include the signature.
UPDATED
This should achieve what you want…
add_action( 'save_post', 'my_new_post');
function my_new_post( $post_id ) {
// Specify the post type on which to run
if ( 'post' == $post->post_type ) {
// Prevent loops
remove_action( 'save_post', 'my_new_post' );
// Make sure we haven't already run for this post
if ( get_post_meta( $post_id, 'signature_added', true ) ) {
return;
}
$signature="";
$post = get_post( $post_id );
$author_name = get_the_author_meta( 'display_name', $post_id );
$signature="<br><br><br><br><br>--<br>" . $author_name;
$update = wp_update_post( array(
'ID' => $post_id,
'post_content' => $post->post_content . $signature
) );
// Add a placeholder so we know the signature was added
if ( ! is_wp_error( $update ) ) {
add_post_meta( $post_id, 'signature_added', true, true );
}
add_action( 'save_post', 'my_new_post' );
}
}