| 1 |
<?php |
| 2 |
namespace FluentForm\App\Helpers\Traits; |
| 3 |
|
| 4 |
use FluentForm\Framework\Helpers\ArrayHelper as Arr; |
| 5 |
|
| 6 |
trait GlobalDefaultMessages |
| 7 |
{ |
| 8 |
private static $globalDefaultMessages = []; |
| 9 |
|
| 10 |
public static function getGlobalDefaultMessage($key) |
| 11 |
{ |
| 12 |
if (isset(static::$globalDefaultMessages[$key])) { |
| 13 |
return static::$globalDefaultMessages[$key]; |
| 14 |
} |
| 15 |
$globalSettings = get_option('_fluentform_global_form_settings'); |
| 16 |
if (!$globalSettings || !Arr::get($globalSettings, 'default_messages')) { |
| 17 |
static::setGlobalDefaultMessages(); |
| 18 |
} else if ($message = Arr::get($globalSettings, 'default_messages.' . $key, '')) { |
| 19 |
static::$globalDefaultMessages[$key] = $message; |
| 20 |
} else { |
| 21 |
static::setGlobalDefaultMessages(); |
| 22 |
} |
| 23 |
return apply_filters('fluentform/global_default_message', Arr::get(static::$globalDefaultMessages, $key , ''), $key); |
| 24 |
} |
| 25 |
|
| 26 |
public static function getAllGlobalDefaultMessages() |
| 27 |
{ |
| 28 |
static::setGlobalDefaultMessages(); |
| 29 |
return static::$globalDefaultMessages; |
| 30 |
} |
| 31 |
|
| 32 |
private static function setGlobalDefaultMessages() |
| 33 |
{ |
| 34 |
$default_messages = []; |
| 35 |
foreach (static::globalDefaultMessageSettingFields() as $key => $field) { |
| 36 |
$default_messages[$key] = $field['value']; |
| 37 |
} |
| 38 |
$globalSettings = get_option('_fluentform_global_form_settings'); |
| 39 |
if ($globalSettings && $messages = Arr::get($globalSettings, 'default_messages', [])) { |
| 40 |
$default_messages = array_merge($default_messages, $messages); |
| 41 |
} |
| 42 |
static::$globalDefaultMessages = apply_filters('fluentform/global_default_messages', $default_messages); |
| 43 |
} |
| 44 |
|
| 45 |
public static function globalDefaultMessageSettingFields() |
| 46 |
{ |
| 47 |
$default_message_setting_fields = [ |
| 48 |
'required' => [ |
| 49 |
'label' => __('Required Field', 'fluentform'), |
| 50 |
'value' => __('This field is required', 'fluentform'), |
| 51 |
'help_text' => __("This message will be shown if validation fails for required field.", |
| 52 |
'fluentform'), |
| 53 |
], |
| 54 |
'email' => [ |
| 55 |
'label' => __('Email', 'fluentform'), |
| 56 |
'value' => __('This field must contain a valid email', 'fluentform'), |
| 57 |
'help_text' => __("This message will be shown if validation fails for email.", 'fluentform'), |
| 58 |
], |
| 59 |
'numeric' => [ |
| 60 |
'label' => __('Numeric', 'fluentform'), |
| 61 |
'value' => __('This field must contain numeric value', 'fluentform'), |
| 62 |
'help_text' => __("This message will be shown if validation fails for numeric value.", 'fluentform'), |
| 63 |
], |
| 64 |
'min' => [ |
| 65 |
'label' => __('Minimum', 'fluentform'), |
| 66 |
'value' => __('Validation fails for minimum value', 'fluentform'), |
| 67 |
'help_text' => __("This message will be shown if validation fails for minimum value.", 'fluentform'), |
| 68 |
], |
| 69 |
'max' => [ |
| 70 |
'label' => __('Maximum', 'fluentform'), |
| 71 |
'value' => __('Validation fails for maximum value', 'fluentform'), |
| 72 |
'help_text' => __("This message will be shown if validation fails for maximum value.", 'fluentform'), |
| 73 |
], |
| 74 |
'digits' => [ |
| 75 |
'label' => __('Digits', 'fluentform'), |
| 76 |
'value' => __('Validation fails for limited digits', 'fluentform'), |
| 77 |
'help_text' => __("This message will be shown if validation fails for digits value.", 'fluentform'), |
| 78 |
], |
| 79 |
'url' => [ |
| 80 |
'label' => __('Url', 'fluentform'), |
| 81 |
'value' => __('This field must contain a valid url', 'fluentform'), |
| 82 |
'help_text' => __("This message will be shown if validation fails for validate URL.", 'fluentform'), |
| 83 |
], |
| 84 |
'allowed_image_types' => [ |
| 85 |
'label' => __('Allowed Image Types', 'fluentform'), |
| 86 |
'value' => __('Allowed image types does not match', 'fluentform'), |
| 87 |
'help_text' => __("This message will be shown if validation fails for image types.", 'fluentform'), |
| 88 |
], |
| 89 |
'allowed_file_types' => [ |
| 90 |
'label' => __('Allowed File Types', 'fluentform'), |
| 91 |
'value' => __('Invalid file type', 'fluentform'), |
| 92 |
'help_text' => __("This message will be shown if validation fails for allowed file type.", 'fluentform'), |
| 93 |
], |
| 94 |
'max_file_size' => [ |
| 95 |
'label' => __('Maximum File Size', 'fluentform'), |
| 96 |
'value' => __('Validation fails for maximum file size', 'fluentform'), |
| 97 |
'help_text' => __("This message will be shown if validation fails for maximum file size.", 'fluentform'), |
| 98 |
], |
| 99 |
'max_file_count' => [ |
| 100 |
'label' => __('Maximum File Count', 'fluentform'), |
| 101 |
'value' => __('Validation fails for maximum file count', 'fluentform'), |
| 102 |
'help_text' => __("This message will be shown if validation fails for maximum file count.", 'fluentform'), |
| 103 |
], |
| 104 |
]; |
| 105 |
|
| 106 |
if (defined('FLUENTFORMPRO')) { |
| 107 |
$default_message_setting_fields['valid_phone_number'] = [ |
| 108 |
'label' => __('Valid Phone Number', 'fluentform'), |
| 109 |
'value' => __('Phone number is not valid', 'fluentform'), |
| 110 |
'help_text' => __("This message will be shown if validation fails for validate phone number.", |
| 111 |
'fluentform'), |
| 112 |
]; |
| 113 |
} |
| 114 |
return apply_filters('fluentform/global_default_message_setting_fields', $default_message_setting_fields); |
| 115 |
} |
| 116 |
} |