From da37dba17e8bf9a78fefc547eb1d04e26f2e50dc Mon Sep 17 00:00:00 2001
From: Regnalf <43412166+Regnalf@users.noreply.github.com>
Date: Tue, 3 Mar 2026 11:52:52 +0100
Subject: [PATCH 1/4] Add the_password_form_redirect_url filter to
get_the_password_form(). See #64785.
---
src/wp-includes/post-template.php | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php
index 2429ab3adb776..e9a8bf9ba509e 100644
--- a/src/wp-includes/post-template.php
+++ b/src/wp-includes/post-template.php
@@ -1803,9 +1803,20 @@ function get_the_password_form( $post = 0 ) {
}
if ( ! empty( $post->ID ) ) {
+
+ /**
+ * Filters the redirect URL used in the post password form.
+ *
+ * @since 6.x.x
+ *
+ * @param string $redirect_url The redirect URL. Default is the post permalink.
+ * @param WP_Post $post The post object.
+ */
+ $redirect_url = apply_filters ('the_password_form_redirect_url', get_permalink ($post->ID), $post);
+
$redirect_field = sprintf(
'',
- esc_attr( get_permalink( $post->ID ) )
+ esc_attr ($redirect_url)
);
}
From 76e5327d6a0729bd009b7c2183a71f3e8e7f561f Mon Sep 17 00:00:00 2001
From: Regnalf <43412166+Regnalf@users.noreply.github.com>
Date: Tue, 3 Mar 2026 12:16:59 +0100
Subject: [PATCH 2/4] dd unit test for the_password_form_redirect_url filter.
See #64785.
---
.../phpunit/tests/post/getThePasswordForm.php | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
create mode 100644 tests/phpunit/tests/post/getThePasswordForm.php
diff --git a/tests/phpunit/tests/post/getThePasswordForm.php b/tests/phpunit/tests/post/getThePasswordForm.php
new file mode 100644
index 0000000000000..7d580f9e18732
--- /dev/null
+++ b/tests/phpunit/tests/post/getThePasswordForm.php
@@ -0,0 +1,26 @@
+post->create();
+ $custom_url = 'https://example.com/custom-preview-link/';
+
+ add_filter( 'the_password_form_redirect_url', function() use ( $custom_url ) {
+ return $custom_url;
+ } );
+
+ $form = get_the_password_form( $post_id );
+
+ $this->assertStringContainsString( 'value="' . $custom_url . '"', $form );
+ }
+}
From a3ae60d68986f12202b564061d7f1417449b8b5e Mon Sep 17 00:00:00 2001
From: Regnalf <43412166+Regnalf@users.noreply.github.com>
Date: Tue, 3 Mar 2026 12:35:05 +0100
Subject: [PATCH 3/4] =?UTF-8?q?Mein=20Vorschlag=20f=C3=BCr=20die=20Commit-?=
=?UTF-8?q?Message:=20Coding=20Standards:=20Fix=20PHPCS=20issues=20in=20ge?=
=?UTF-8?q?t=5Fthe=5Fpassword=5Fform().=20See=20#64785?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/wp-includes/post-template.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php
index e9a8bf9ba509e..70974f7210811 100644
--- a/src/wp-includes/post-template.php
+++ b/src/wp-includes/post-template.php
@@ -1807,16 +1807,16 @@ function get_the_password_form( $post = 0 ) {
/**
* Filters the redirect URL used in the post password form.
*
- * @since 6.x.x
+ * @since 6.x.x
*
* @param string $redirect_url The redirect URL. Default is the post permalink.
* @param WP_Post $post The post object.
*/
- $redirect_url = apply_filters ('the_password_form_redirect_url', get_permalink ($post->ID), $post);
-
+ $redirect_url = apply_filters( 'the_password_form_redirect_url', get_permalink( $post->ID ), $post );
+
$redirect_field = sprintf(
'',
- esc_attr ($redirect_url)
+ esc_attr( $redirect_url )
);
}
From c3f256251694b346d61b7a8a7c8f1175711bafb4 Mon Sep 17 00:00:00 2001
From: Regnalf <43412166+Regnalf@users.noreply.github.com>
Date: Tue, 3 Mar 2026 12:45:36 +0100
Subject: [PATCH 4/4] Coding Standards: Fix PHPCS issues in unit test. See
#64785.
---
tests/phpunit/tests/post/getThePasswordForm.php | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tests/phpunit/tests/post/getThePasswordForm.php b/tests/phpunit/tests/post/getThePasswordForm.php
index 7d580f9e18732..d767647ea1171 100644
--- a/tests/phpunit/tests/post/getThePasswordForm.php
+++ b/tests/phpunit/tests/post/getThePasswordForm.php
@@ -1,5 +1,4 @@
post->create();
+ $post_id = self::factory()->post->create();
$custom_url = 'https://example.com/custom-preview-link/';
- add_filter( 'the_password_form_redirect_url', function() use ( $custom_url ) {
+ $callback = function () use ( $custom_url ) {
return $custom_url;
- } );
+ };
+
+ add_filter( 'the_password_form_redirect_url', $callback );
$form = get_the_password_form( $post_id );