[wp-trac] [WordPress Trac] #64785: Add filter for redirect_to URL in get_the_password_form()

WordPress Trac noreply at wordpress.org
Tue Mar 3 17:18:33 UTC 2026


#64785: Add filter for redirect_to URL in get_the_password_form()
-----------------------------------+------------------------------
 Reporter:  regnalf                |       Owner:  (none)
     Type:  enhancement            |      Status:  new
 Priority:  normal                 |   Milestone:  Awaiting Review
Component:  Posts, Post Types      |     Version:  6.9.1
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+------------------------------
Changes (by westonruter):

 * keywords:  has-patch => has-patch 2nd-opinion


Comment:

 Replying to [ticket:64785 regnalf]:
 > While there is a filter for the entire form HTML (the_password_form),
 changing only the redirect URL requires brittle string manipulation (like
 str_replace or regex) on the rendered HTML block.

 Not quite, as now with the HTML Tag Processor it is safe and pretty
 trivial to update hidden input:

 {{{#!php
 <?php
 add_filter(
         'the_password_form',
         static function ( string $output, WP_Post $post ): string {
                 $processor = new WP_HTML_Tag_Processor( $output );
                 while ( $processor->next_tag( 'INPUT' ) ) {
                         if (
                                 $processor->get_attribute( 'type' ) ===
 'hidden' &&
                                 $processor->get_attribute( 'name' ) ===
 'redirect_to'
                         ) {
                                 $processor->set_attribute( 'value',
 my_plugin_get_password_redirect_url( $post ) );
                                 break;
                         }
                 }
                 return $processor->get_updated_html();
         },
         10,
         2
 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64785#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list