PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / helpers / redirect-helper.php

redirect-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/helpers/redirect-helper.php

71 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Helpers;
4
5 /**
6 * A helper object for redirects.
7 */
8 class Redirect_Helper {
9
10 /**
11 * Wraps wp_redirect to allow testing for redirects.
12 *
13 * @codeCoverageIgnore It only wraps a WordPress function.
14 *
15 * @param string $location The path to redirect to.
16 * @param int $status The status code to use.
17 * @param string $reason The reason for the redirect.
18 *
19 * @return void
20 */
21 public function do_unsafe_redirect( $location, $status = 302, $reason = 'Yoast SEO' ) {
22 // phpcs:ignore WordPress.Security.SafeRedirect -- intentional, function has been renamed to make unsafe more clear.
23 \wp_redirect( $location, $status, $reason );
24 exit();
25 }
26
27 /**
28 * Wraps wp_safe_redirect to allow testing for safe redirects.
29 *
30 * @codeCoverageIgnore It only wraps a WordPress function.
31 *
32 * @param string $location The path to redirect to.
33 * @param int $status The status code to use.
34 * @param string $reason The reason for the redirect.
35 *
36 * @return void
37 */
38 public function do_safe_redirect( $location, $status = 302, $reason = 'Yoast SEO' ) {
39 \wp_safe_redirect( $location, $status, $reason );
40 exit();
41 }
42
43 /**
44 * Sets a header.
45 * This is a tiny helper function to enable better testing.
46 *
47 * @codeCoverageIgnore It only wraps a WordPress function.
48 *
49 * @param string $header The header to set.
50 *
51 * @return void
52 */
53 public function set_header( $header ) {
54 \header( $header );
55 }
56
57 /**
58 * Removes a header.
59 * This is a tiny helper function to enable better testing.
60 *
61 * @codeCoverageIgnore It only wraps a WordPress function.
62 *
63 * @param string $header The header to remove.
64 *
65 * @return void
66 */
67 public function remove_header( $header ) {
68 \header_remove( $header );
69 }
70 }
71