Concerns
3 years ago
Conditions
4 years ago
Contracts
3 years ago
Exceptions
3 years ago
Facades
4 years ago
Checkbox.php
4 years ago
Date.php
4 years ago
Element.php
3 years ago
Email.php
4 years ago
Factory.php
4 years ago
Field.php
3 years ago
File.php
3 years ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
4 years ago
Html.php
4 years ago
Option.php
3 years ago
Phone.php
4 years ago
Radio.php
4 years ago
Section.php
3 years ago
Select.php
4 years ago
Text.php
4 years ago
Textarea.php
4 years ago
Types.php
4 years ago
Url.php
4 years ago
File.php
75 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | use function get_allowed_mime_types; |
| 6 | use function wp_max_upload_size; |
| 7 | |
| 8 | /** |
| 9 | * A file upload field. |
| 10 | * |
| 11 | * @since 2.12.0 |
| 12 | * @since 2.23.1 Moved default rule values inline since inherited constructor is final. |
| 13 | */ |
| 14 | class File extends Field |
| 15 | { |
| 16 | |
| 17 | use Concerns\AllowMultiple; |
| 18 | use Concerns\HasEmailTag; |
| 19 | use Concerns\HasHelpText; |
| 20 | use Concerns\HasLabel; |
| 21 | use Concerns\ShowInReceipt; |
| 22 | use Concerns\StoreAsMeta; |
| 23 | use Concerns\AllowMultiple; |
| 24 | |
| 25 | const TYPE = 'file'; |
| 26 | |
| 27 | /** |
| 28 | * Set the maximum file size. |
| 29 | * |
| 30 | * @param int $maxSize |
| 31 | * |
| 32 | * @return $this |
| 33 | */ |
| 34 | public function maxSize($maxSize) |
| 35 | { |
| 36 | $this->validationRules->rule('maxSize', $maxSize); |
| 37 | |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Access the maximum file size. |
| 43 | * |
| 44 | * @return int |
| 45 | */ |
| 46 | public function getMaxSize() |
| 47 | { |
| 48 | return $this->validationRules->getRule('maxSize') || wp_max_upload_size(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Set the allowed file types. |
| 53 | * |
| 54 | * @param string[] $allowedTypes |
| 55 | * |
| 56 | * @return $this |
| 57 | */ |
| 58 | public function allowedTypes($allowedTypes) |
| 59 | { |
| 60 | $this->validationRules->rule('allowedTypes', $allowedTypes); |
| 61 | |
| 62 | return $this; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Access the allowed file types. |
| 67 | * |
| 68 | * @return string[] |
| 69 | */ |
| 70 | public function getAllowedTypes() |
| 71 | { |
| 72 | return $this->validationRules->getRule('allowedTypes') || get_allowed_mime_types(); |
| 73 | } |
| 74 | } |
| 75 |