| 1 |
<?php |
| 2 |
/** |
| 3 |
* Utility functions pertaining to denying public access. |
| 4 |
* |
| 5 |
* @package FaustWP |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPE\FaustWP\Deny_Public_Access; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Checks if the current request is coming from the file editor. |
| 16 |
* |
| 17 |
* @see https://github.com/WordPress/wordpress-develop/blob/5.8.1/src/wp-includes/load.php#L1591-L1593 |
| 18 |
* |
| 19 |
* @return bool |
| 20 |
*/ |
| 21 |
function doing_file_editor_save() { |
| 22 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 23 |
// Disabling as we are mimicking WordPress core's own check. |
| 24 |
// https://github.com/WordPress/wordpress-develop/blob/5.8.1/src/wp-includes/load.php#L1591-L1595. |
| 25 |
if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) { |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
$key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 ); |
| 30 |
$nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] ); |
| 31 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 32 |
|
| 33 |
// Validate nonce. |
| 34 |
if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
return true; |
| 39 |
} |
| 40 |
|