DataInconsistency
2 weeks ago
License
2 months ago
Notices
2 months ago
pQuery
2 months ago
APIPermissionHelper.php
1 year ago
CdnAssetUrl.php
3 years ago
ConflictResolver.php
1 month ago
Cookies.php
2 months ago
DBCollationChecker.php
2 months ago
DOM.php
2 years ago
DateConverter.php
3 years ago
FreeDomains.php
3 years ago
Headers.php
1 year ago
Helpers.php
1 month ago
Installation.php
1 year ago
LegacyDatabase.php
1 year ago
Request.php
2 months ago
SecondLevelDomainNames.php
3 years ago
Security.php
2 months ago
ThirdPartyOutput.php
1 month ago
Url.php
2 months ago
index.php
3 years ago
Request.php
34 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Util; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class Request { |
| 9 | public function isPost(): bool { |
| 10 | return isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' || count($_POST) > 0; |
| 11 | } |
| 12 | |
| 13 | public function getStringParam(string $key): ?string { |
| 14 | if ($this->isPost()) { |
| 15 | return $this->getSanitizedParam($_POST, $key, 'sanitize_text_field'); |
| 16 | } |
| 17 | return $this->getSanitizedParam($_GET, $key, 'sanitize_text_field'); |
| 18 | } |
| 19 | |
| 20 | public function getTextareaParam(string $key): ?string { |
| 21 | if ($this->isPost()) { |
| 22 | return $this->getSanitizedParam($_POST, $key, 'sanitize_textarea_field'); |
| 23 | } |
| 24 | return $this->getSanitizedParam($_GET, $key, 'sanitize_textarea_field'); |
| 25 | } |
| 26 | |
| 27 | private function getSanitizedParam(array $source, string $key, callable $sanitize): ?string { |
| 28 | if (!isset($source[$key]) || !is_scalar($source[$key])) { |
| 29 | return null; |
| 30 | } |
| 31 | return $sanitize(wp_unslash((string)$source[$key])); |
| 32 | } |
| 33 | } |
| 34 |