PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / FieldsAPI / File.php

File.php in GiveWP – Donation Plugin and Fundraising Platform 2.19.6, at src/Framework/FieldsAPI/File.php

88 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 */
13 class File extends Field
14 {
15
16 use Concerns\AllowMultiple;
17 use Concerns\HasEmailTag;
18 use Concerns\HasHelpText;
19 use Concerns\HasLabel;
20 use Concerns\ShowInReceipt;
21 use Concerns\StoreAsMeta;
22 use Concerns\AllowMultiple;
23
24 const TYPE = 'file';
25
26 /**
27 * @since 2.16.0 File size unit is bytes, so no need to convert WordPress max file upload size to kilo bytes.
28 *
29 * @param string $name
30 *
31 */
32 public function __construct($name)
33 {
34 parent::__construct($name);
35
36 $this->validationRules->rule('maxSize', wp_max_upload_size()); // in bytes
37 $this->validationRules->rule('allowedTypes', get_allowed_mime_types());
38 }
39
40 /**
41 * Set the maximum file size.
42 *
43 * @param int $maxSize
44 *
45 * @return $this
46 */
47 public function maxSize($maxSize)
48 {
49 $this->validationRules->rule('maxSize', $maxSize);
50
51 return $this;
52 }
53
54 /**
55 * Access the maximum file size.
56 *
57 * @return int
58 */
59 public function getMaxSize()
60 {
61 return $this->validationRules->getRule('maxSize');
62 }
63
64 /**
65 * Set the allowed file types.
66 *
67 * @param string[] $allowedTypes
68 *
69 * @return $this
70 */
71 public function allowedTypes($allowedTypes)
72 {
73 $this->validationRules->rule('allowedTypes', $allowedTypes);
74
75 return $this;
76 }
77
78 /**
79 * Access the allowed file types.
80 *
81 * @return string[]
82 */
83 public function getAllowedTypes()
84 {
85 return $this->validationRules->getRule('allowedTypes');
86 }
87 }
88