timber / starter-theme

The "_s" for Timber: a dead-simple theme that you can build anything from
MIT License
810 stars 275 forks source link

Password protected posts / pages form action issue #97

Open marcinkrzeminski opened 4 years ago

marcinkrzeminski commented 4 years ago

Today I have found a bug in the starter-theme/templates/single-password.twig. I was getting 502 on WP Engine for password-protected pages and posts. After some research, it turned out that WP Engine is appending an extra query string to the action URL. Currently, we have:

<form action="{{ site.site_url }}/wp-login.php?action=postpass" method="post">

I was able to fix it by adding this piece of code in my single.php and page.php:

$context['form_action'] = esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) );

Doing it this way allows hooks to alter the URL.

The form action field looks like this:

<form action="{{ form_action }}" method="post">

I got the idea from this issue: https://toolset.com/forums/topic/password-protected-post-bug-with-wpengine/

What do you think would be the best way to handle this? Is it better to provide a globally accessible variable like site.password_proteced_url or just modify the single.php and page.php as well as the templates/single-password.twig. Or maybe you have another suggestion? Let me know and I'll create a pull request.

Levdbas commented 8 months ago

PR at https://github.com/timber/starter-theme/pull/118