From e0d874a1be4c702df187ef182636074406be86d8 Mon Sep 17 00:00:00 2001
From: Sukhendu Sekhar Guria
Date: Fri, 8 May 2026 17:36:28 +0530
Subject: [PATCH] Fix expired post nonce retry redirect
---
src/wp-includes/functions.php | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 7d71c8c56963d..ba7558b40f768 100644
--- a/src/wp-includes/functions.php
+++ b/src/wp-includes/functions.php
@@ -3712,8 +3712,22 @@ function wp_nonce_ays( $action ) {
} else {
$html = __( 'The link you followed has expired.' );
- if ( wp_get_referer() ) {
- $wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
+ $wp_http_referer = wp_get_referer();
+
+ if ( preg_match( '/^update-post_([0-9]+)$/', $action, $matches ) && isset( $_REQUEST['post_ID'] ) ) {
+ $post_id = (int) $_REQUEST['post_ID'];
+
+ if ( $post_id === (int) $matches[1] && current_user_can( 'edit_post', $post_id ) ) {
+ $edit_post_link = get_edit_post_link( $post_id, 'url' );
+
+ if ( $edit_post_link ) {
+ $wp_http_referer = $edit_post_link;
+ }
+ }
+ }
+
+ if ( $wp_http_referer ) {
+ $wp_http_referer = remove_query_arg( 'updated', $wp_http_referer );
$wp_http_referer = wp_validate_redirect( sanitize_url( $wp_http_referer ) );
$html .= '
';