Hook for post permalink update

You need to exactly use wp_insert_post_data. This contains array of post data what will be store into database after WordPress has done all of the validation/sanitization.

add_filter('wp_insert_post_data', 'wpse_wp_insert_post_data', 10, 2);
function wpse_wp_insert_post_data($data, $post_attr)
{
    // you get the post_name using $data['post_name'];

    // post id will not be present for the first insert
    // but you can check $post_attr['ID'] to be sure if an ID has been passed.
    // note: $data won't contain post id ever, only the $post_attr will have it

    // if you want to compare the name, you could use -
    if( isset($post_attr['post_name']) 
        && !empty($post_attr['post_name']) 
        && $post_attr['post_name'] != $data['post_name'] )
    {
        // So here you can guess post name has been changed
        // note: $post_attr['post_name'] might come undefined or empty sometime.
        // and $data['post_name'] could also comes up empty, but it will be always defined
    }

    // you do not need to modify anything, so you should return it as it is
    return $data;
}

Hope it helps.

Leave a Comment