subscribe-modal
2 years ago
jetpack-user-content-link-redirection.php
2 years ago
readme.md
7 years ago
subscriptions.css
7 years ago
views.php
3 years ago
jetpack-user-content-link-redirection.php
56 lines
| 1 | <?php |
| 2 | /** |
| 3 | * User Content Link Redirection |
| 4 | * |
| 5 | * The purpose of this file is to track and redirect user content links in emails. |
| 6 | * This renders an iframe pointing to subscribe.wordpress.com which will track and |
| 7 | * return the destination url for the iframe parent to redirect to. |
| 8 | * |
| 9 | * @package automattic/jetpack |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Render a page containing an iframe to track and redirect the user content link in emails. |
| 14 | */ |
| 15 | function jetpack_user_content_link_redirection() { |
| 16 | if ( empty( $_SERVER['QUERY_STRING'] ) ) { |
| 17 | return; |
| 18 | } |
| 19 | $query_params = sanitize_text_field( wp_unslash( $_SERVER['QUERY_STRING'] ) ); |
| 20 | $iframe_url = "https://subscribe.wordpress.com/?$query_params"; |
| 21 | |
| 22 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 23 | echo <<<EOF |
| 24 | <!DOCTYPE html> |
| 25 | <html> |
| 26 | <head> |
| 27 | <script> |
| 28 | window.addEventListener( 'message', function(event) { |
| 29 | if ( event.origin !== 'https://subscribe.wordpress.com' ) { |
| 30 | return; |
| 31 | } |
| 32 | if ( event.data.redirectUrl ) { |
| 33 | window.location.href = event.data.redirectUrl; |
| 34 | } |
| 35 | } ); |
| 36 | </script> |
| 37 | </head> |
| 38 | <body> |
| 39 | EOF; |
| 40 | echo '<iframe id="user-content-link-redirection" hidden aria-hidden="true" tabindex="-1" width="0" height="0" style="display: none" src="' . esc_url( $iframe_url ) . '"></iframe>'; |
| 41 | echo <<<EOF |
| 42 | </body> |
| 43 | </html> |
| 44 | EOF; |
| 45 | // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 46 | exit; |
| 47 | } |
| 48 | |
| 49 | // The WPCOM_USER_CONTENT_LINK_REDIRECTION flag prevents this redirection logic from running |
| 50 | // on Atomic in case we'd like to override the redirection logic on the Atomic end. |
| 51 | |
| 52 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 53 | if ( ! defined( 'WPCOM_USER_CONTENT_LINK_REDIRECTION' ) && isset( $_GET['action'] ) && $_GET['action'] === 'user_content_redirect' ) { |
| 54 | add_action( 'init', 'jetpack_user_content_link_redirection' ); |
| 55 | } |
| 56 |