actions-meta.php
2 years ago
args-meta.php
2 years ago
base-meta-type.php
2 years ago
gateways-meta.php
2 years ago
messages-meta.php
2 years ago
preset-meta.php
2 years ago
recaptcha-meta.php
2 years ago
validation-meta.php
2 years ago
messages-meta.php
118 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Post_Meta; |
| 5 | |
| 6 | use Jet_Form_Builder\Classes\Tools; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die; |
| 11 | } |
| 12 | |
| 13 | class Messages_Meta extends Base_Meta_Type { |
| 14 | |
| 15 | private $messages; |
| 16 | |
| 17 | public function __construct() { |
| 18 | $this->messages = apply_filters( |
| 19 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 20 | 'jet-form-builder/message-types', |
| 21 | $this->get_messages() |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | public function get_id(): string { |
| 26 | return '_jf_messages'; |
| 27 | } |
| 28 | |
| 29 | public function get_type(): string { |
| 30 | return 'string'; |
| 31 | } |
| 32 | |
| 33 | public function get_default(): string { |
| 34 | return Tools::encode_json( $this->get_values() ); |
| 35 | } |
| 36 | |
| 37 | private function get_messages(): array { |
| 38 | return array( |
| 39 | 'success' => array( |
| 40 | 'label' => __( 'Form successfully submitted.', 'jet-form-builder' ), |
| 41 | 'value' => 'Form successfully submitted.', |
| 42 | ), |
| 43 | 'failed' => array( |
| 44 | 'label' => __( 'Submit failed.', 'jet-form-builder' ), |
| 45 | 'value' => 'There was an error trying to submit form. Please try again later.', |
| 46 | ), |
| 47 | 'validation_failed' => array( |
| 48 | 'label' => __( 'Validation error', 'jet-form-builder' ), |
| 49 | 'value' => 'One or more fields have an error. Please check and try again.', |
| 50 | ), |
| 51 | 'captcha_failed' => array( |
| 52 | 'label' => __( 'Captcha validation failed', 'jet-form-builder' ), |
| 53 | 'value' => __( 'Captcha validation failed', 'jet-form-builder' ), |
| 54 | ), |
| 55 | 'invalid_email' => array( |
| 56 | 'label' => __( 'Entered an invalid email', 'jet-form-builder' ), |
| 57 | 'value' => 'The e-mail address entered is invalid.', |
| 58 | ), |
| 59 | 'empty_field' => array( |
| 60 | 'label' => __( 'Required field is empty', 'jet-form-builder' ), |
| 61 | 'value' => 'The field is required.', |
| 62 | ), |
| 63 | 'internal_error' => array( |
| 64 | 'label' => __( 'Internal server error', 'jet-form-builder' ), |
| 65 | 'value' => 'Internal server error. Please try again later.', |
| 66 | ), |
| 67 | 'upload_max_files' => array( |
| 68 | 'label' => __( 'Media Specific: Max files limit', 'jet-form-builder' ), |
| 69 | 'value' => 'Maximum upload files limit is reached.', |
| 70 | ), |
| 71 | 'upload_max_size' => array( |
| 72 | 'label' => __( 'Media Specific: Max size reached', 'jet-form-builder' ), |
| 73 | 'value' => 'Upload max size exceeded.', |
| 74 | ), |
| 75 | 'upload_mime_types' => array( |
| 76 | 'label' => __( 'Media Specific: File type error', 'jet-form-builder' ), |
| 77 | 'value' => 'File type is not allowed.', |
| 78 | ), |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | public function messages(): array { |
| 83 | return $this->messages; |
| 84 | } |
| 85 | |
| 86 | public function query( $form_id ) { |
| 87 | $messages = parent::query( $form_id ); |
| 88 | |
| 89 | if ( empty( $messages ) ) { |
| 90 | return $this->messages; |
| 91 | } |
| 92 | |
| 93 | return array_merge( $this->messages, $messages ); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | public function get_values() { |
| 98 | return $this->get_by_key( 'label' ); |
| 99 | } |
| 100 | |
| 101 | public function get_labels(): array { |
| 102 | return $this->get_by_key( 'label' ); |
| 103 | } |
| 104 | |
| 105 | public function get_by_key( $key ): array { |
| 106 | $messages = array(); |
| 107 | |
| 108 | foreach ( $this->messages as $type => $message ) { |
| 109 | if ( ! isset( $message[ $key ] ) ) { |
| 110 | break; |
| 111 | } |
| 112 | $messages[ $type ] = $message[ $key ]; |
| 113 | } |
| 114 | |
| 115 | return $messages; |
| 116 | } |
| 117 | } |
| 118 |