PluginProbe
Faust.js / 0.7.7
Faust.js v0.7.7
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
faustwp / includes / deny-public-access / callbacks.php

callbacks.php in Faust.js 0.7.7, at includes/deny-public-access/callbacks.php

53 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Prevents access to WP front-end URLs by redirecting to a user-specified URL.
4 *
5 * @package FaustWP
6 */
7
8 namespace WPE\FaustWP\Deny_Public_Access;
9
10 use function WPE\FaustWP\Settings\{
11 faustwp_get_setting,
12 is_redirects_enabled
13 };
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 add_action( 'template_redirect', __NAMESPACE__ . '\\deny_public_access', 99 );
20 /**
21 * Redirects non-API requests for public URLs to the specified front-end URL.
22 *
23 * @return void
24 */
25 function deny_public_access() {
26 if ( ! is_redirects_enabled() || is_customize_preview() ) {
27 return;
28 }
29
30 $frontend_uri = faustwp_get_setting( 'frontend_uri' );
31
32 if ( ! $frontend_uri ) {
33 return;
34 }
35
36 $frontend_uri = trailingslashit( $frontend_uri );
37
38 // Get the request uri with query params.
39 $request_uri = home_url( add_query_arg( null, null ) );
40
41 // Allow saving from file editor.
42 if ( doing_file_editor_save() ) {
43 return;
44 }
45
46 $response_code = 302;
47 $redirect_url = str_replace( trailingslashit( get_home_url() ), $frontend_uri, $request_uri );
48
49 header( 'X-Redirect-By: WP Engine Headless plugin' ); // For support teams. See https://developer.yoast.com/blog/x-redirect-by-header/.
50 header( 'Location: ' . esc_url_raw( $redirect_url ), true, $response_code );
51 exit;
52 }
53