Created
April 9, 2026 07:54
-
-
Save marklchaves/1a3f0ecd1d74546ad74e49b268fc00f5 to your computer and use it in GitHub Desktop.
Popup Maker: Fix WP User Frontend Invalid Post error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * NOTE: Popup Maker 1.22.0 runs the template_redirect at priority 1 (before it was 10). | |
| * This snippet's outer action priority runs at -1 now so it can still fix | |
| * the Invalid Post error. If we left the original outer priority at 1, the | |
| * original non-Popup Maker pid would never get put back into the URL for | |
| * the redirect and we'd see the Invalid post error again. | |
| */ | |
| add_action( 'template_redirect', function () { | |
| if ( empty( $_GET['pid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| return; | |
| } | |
| // Normalize array to scalar (e.g. ?pid[]=1 from some page builders). | |
| if ( is_array( $_GET['pid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| $_GET['pid'] = reset( $_GET['pid'] ) ?: null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| if ( empty( $_GET['pid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| return; | |
| } | |
| } | |
| $popup_id = absint( $_GET['pid'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| // If pid doesn't point to an actual popup, temporarily remove it so Popup | |
| // Maker (priority 0) doesn't redirect, then restore it at priority 11 so | |
| // other plugins (e.g. WP User Frontend) can still use it during rendering. | |
| if ( $popup_id > 0 && 'popup' !== get_post_type( $popup_id ) ) { | |
| $saved_pid = $_GET['pid']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| unset( $_GET['pid'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| add_action( 'template_redirect', function () use ( $saved_pid ) { | |
| $_GET['pid'] = $saved_pid; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| }, 11 ); | |
| } | |
| }, -1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment