PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Placeholder / PlaceholderLocalizationHelper.php

PlaceholderLocalizationHelper.php in The Innovative Form Builder – IvyForms 1.5.1, at backend/src/Services/Placeholder/PlaceholderLocalizationHelper.php

60 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Services\Placeholder;
9
10 /**
11 * Resolves {{wp.*}} placeholders in public form field strings at serve time.
12 */
13 class PlaceholderLocalizationHelper
14 {
15 /**
16 * @return array<string, string|int>
17 */
18 public static function getGeneralData(): array
19 {
20 return PlaceholderService::buildGeneralData(0, [
21 'postId' => self::resolvePostId(),
22 'referer' => wp_get_referer() ?: '',
23 ]);
24 }
25
26 /**
27 * @param array<string, string|int> $generalData
28 */
29 public static function resolveFieldString(string $value, array $generalData): string
30 {
31 if (strpos($value, '{{') === false) {
32 return $value;
33 }
34
35 return PlaceholderService::replacePlaceholders($value, [], $generalData);
36 }
37
38 private static function resolvePostId(): int
39 {
40 $postId = get_queried_object_id();
41 if ($postId) {
42 return (int) $postId;
43 }
44
45 $theId = get_the_ID();
46 if ($theId) {
47 return (int) $theId;
48 }
49
50 if (is_admin()) {
51 $adminPostId = filter_input(INPUT_GET, 'post', FILTER_VALIDATE_INT);
52 if (is_int($adminPostId) && $adminPostId > 0) {
53 return $adminPostId;
54 }
55 }
56
57 return 0;
58 }
59 }
60