I have a custom admin page on a WordPress that allows showing the posts in a certain required way.
Each post is represented as a card that includes a trash icon to send the post to the trash. It’s easy with:
<?php $trash_link = get_delete_post_link( $id ); ?> <a href="<?= $trash_link ?>"><span class="dashicons dashicons-trash"></span></a>
I’d like to replace this icon/link for a restore one when I’m currently viewing my trashed posts but I cannot figure out how to get the link since it doesn’t seem to exist a
Trash links look like:
While untrash links look like:
So I tried:
<?php $trash_link = get_delete_post_link( $id ); if ( $post->post_status == 'trash' ): $restore_link = str_replace( 'trash', 'untrash', $trash_link ); endif;
That gives an apparently correct link but, of course, it doesn’t work since nonce doesn’t verify.
I guess I could build my own system using
wp_untrash_post(), but is there any easier way?
Read more here: How to get (or generate) link to untrash a post?