Backoffice
2 months ago
build_widget_data_attributes.php
2 months ago
get_widget_settings.php
2 months ago
load_script_file.php
2 months ago
load_script_template_file.php
2 months ago
load_translations.php
2 years ago
register_shortcode.php
2 months ago
sanitize_restaurant_id.php
2 months ago
sanitize_widget_settings.php
2 months ago
sanitize_restaurant_id.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Zenchef\Widget\Widget; |
| 4 | |
| 5 | use function preg_match; |
| 6 | use function trim; |
| 7 | |
| 8 | /** |
| 9 | * Trims and validates a restaurant ID against the two supported formats: |
| 10 | * - legacy numeric ID (e.g. "367219") |
| 11 | * - new prefixed ID (e.g. "rpid_CTF3YNH3") |
| 12 | * |
| 13 | * Returns the trimmed value if valid or empty, or null if a non-empty value is invalid. |
| 14 | * |
| 15 | * @param mixed $value |
| 16 | * @return string|null |
| 17 | */ |
| 18 | function sanitize_restaurant_id($value) |
| 19 | { |
| 20 | $trimmed = trim((string) $value); |
| 21 | |
| 22 | if ($trimmed === '') { |
| 23 | return ''; |
| 24 | } |
| 25 | |
| 26 | if (preg_match('/^(\d+|rpid_[A-Za-z0-9]+)$/', $trimmed) !== 1) { |
| 27 | return null; |
| 28 | } |
| 29 | |
| 30 | return $trimmed; |
| 31 | } |
| 32 |