You should be able to get the ID of the post through the $_POST
variable.
EDIT: Maybe you should try doing this on the save_post
action, like so, but save_post
sometimes runs on other instances (ie. Autosave Drafts), so you’ll want to do some more verifying. save_post
will also return the ID as one of the function arguments so you already have that handy.
add_action('save_post', 'myfunction');
function myfunction( $id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// check if this is a page
if ( 'page' == $_POST['post_type'] ) {
// Return nothing if the user can't edit this page
if ( !current_user_can( 'edit_page', $id ) )
return;
// do stuff here, we have verified this is a page and you can edit it
}
}
Just tested this on localhost, works good for me.
Used a bit of code from here and you should read up on the save_post
action if you decide to try this out!