From your comment above, I believe you’re running into issues with the _wpnonce
piece of the puzzle. Looking at the code in /wp-admin/post.php
, it appears that the untrash
instruction is checking for a valid WordPress nonce, and not getting one.
This might do the trick:
<?php
function wpse_95348_undelete_post( $post_id ) {
// no post?
if( !$post_id || !is_numeric( $post_id ) ) {
return false;
}
$_wpnonce = wp_create_nonce( 'untrash-post_' . $post_id );
$url = admin_url( 'post.php?post=" . $post_id . "&action=untrash&_wpnonce=" . $_wpnonce );
return $url;
}
?>
It uses wp_create_nonce()
to generate the nonce you need and admin_url()
to get a proper wp-admin
URL.