No need to write this too much code.
$pagePath = parse_url( $_SERVER['REQUEST_URI'] );
$pagePath = $pagePath['path'];
$pagePath = substr($pagePath, 1);
you can easily get current page path by calling global variable $pagenow.
global $pagenow; // return 'post-new.php'
Instead of using content_save_pre
filter you can do this same with wp_insert_post_data
filter more easily. try out this.
add_filter( 'wp_insert_post_data', 'appendContent', 99, 2 );
function appendContent( $data, $postarr ) {
// Retrieve referer path of current page through wp_get_referer().
$referer = basename( wp_get_referer() ); // post-new.php
if ( ! wp_is_post_revision( $postarr['ID'] ) && $referer == 'post-new.php' ) {
$data['post_content'] = $data['post_content'] . ' text before save to db';
}
return $data;
}
wp_insert_post_data
is called by the wp_insert_post function prior to inserting into or updating the database.