← All changes
|
includes/Frontend/Form/View/Theme/Fields/RecaptchaV2Field.php
+33
-13
2.0
→
V3.3.2
View file →
| @@ -2,31 +2,51 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 6 | +use BitCode\BitForm\Core\Util\Utilities; | |
| 6 | 7 | |
| 7 | -class RecaptchaV2Field { | |
| 8 | - public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) { | |
| 8 | +class RecaptchaV2Field | |
| 9 | +{ | |
| 10 | + public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) | |
| 11 | + { | |
| 9 | 12 | $integrationHandler = new IntegrationHandler(0); |
| 10 | 13 | $allFormIntegrations = $integrationHandler->getAllIntegration('app', 'gReCaptcha'); |
| 11 | - $siteKey = json_decode($allFormIntegrations[0]->integration_details)->siteKey; | |
| 14 | + if (is_wp_error($allFormIntegrations)) { | |
| 15 | + return ''; | |
| 16 | + } | |
| 17 | + $row = Utilities::firstRow($allFormIntegrations); | |
| 18 | + $siteKey = Utilities::jsonObj($row->integration_details ?? '')->siteKey ?? ''; | |
| 12 | 19 | return self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $siteKey, $error = null, $value = null); |
| 13 | 20 | } |
| 14 | 21 | |
| 15 | - private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $siteKey, $error = null, $value = null) { | |
| 16 | - $fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 22 | + private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $siteKey, $error = null, $value = null) | |
| 23 | + { | |
| 24 | + $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 17 | 25 | $theme = $field->config->theme; |
| 18 | 26 | $size = $field->config->size; |
| 19 | 27 | |
| 20 | - return <<<RECAPTCHAV2FIELD | |
| 21 | - <div | |
| 22 | - class="{$fieldHelpers->getAtomicCls('fld-wrp')} {$fieldHelpers->getCustomClasses('fld-wrp')}" | |
| 23 | - {$fieldHelpers->getCustomAttributes('fld-wrp')} | |
| 28 | + return sprintf( | |
| 29 | + '<div | |
| 30 | + %1$s | |
| 31 | + class="%2$s %3$s" | |
| 24 | 32 | > |
| 25 | - <div class="$rowID-recaptcha-wrp"> | |
| 26 | - <div class="g-recaptcha" data-theme="{$theme}" data-size="{$size}" data-sitekey="$siteKey"> | |
| 33 | + <div class="%4$s-recaptcha-wrp"> | |
| 34 | + <div | |
| 35 | + class="g-recaptcha" | |
| 36 | + data-theme="%5$s" | |
| 37 | + data-size="%6$s" | |
| 38 | + data-sitekey="%7$s" | |
| 39 | + > | |
| 27 | 40 | </div> |
| 28 | 41 | </div> |
| 29 | - </div> | |
| 30 | -RECAPTCHAV2FIELD; | |
| 42 | + </div>', | |
| 43 | + $fieldHelpers->getCustomAttributes('fld-wrp'), | |
| 44 | + $fieldHelpers->getAtomicCls('fld-wrp'), | |
| 45 | + $fieldHelpers->getCustomClasses('fld-wrp'), | |
| 46 | + $rowID, | |
| 47 | + $fieldHelpers->esc_attr($theme), | |
| 48 | + $fieldHelpers->esc_attr($size), | |
| 49 | + $fieldHelpers->esc_attr($siteKey) | |
| 50 | + ); | |
| 31 | 51 | } |
| 32 | 52 | } |