PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
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
77 lines 1.5 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 use Concerns\AllowMultiple;
16 use Concerns\HasEmailTag;
17 use Concerns\HasHelpText;
18 use Concerns\HasLabel;
19 use Concerns\ShowInReceipt;
20 use Concerns\StoreAsMeta;
21 use Concerns\AllowMultiple;
22
23 const TYPE = 'file';
24
25 /**
26 * @param string $name
27 *
28 * @since 2.16.0 File size unit is bytes, so no need to convert WordPress max file upload size to kilo bytes.
29 */
30 public function __construct( $name ) {
31 parent::__construct( $name );
32
33 $this->validationRules->rule( 'maxSize', wp_max_upload_size() ); // in bytes
34 $this->validationRules->rule( 'allowedTypes', get_allowed_mime_types() );
35 }
36
37 /**
38 * Set the maximum file size.
39 *
40 * @param int $maxSize
41 * @return $this
42 */
43 public function maxSize( $maxSize ) {
44 $this->validationRules->rule( 'maxSize', $maxSize );
45 return $this;
46 }
47
48 /**
49 * Access the maximum file size.
50 *
51 * @return int
52 */
53 public function getMaxSize() {
54 return $this->validationRules->getRule( 'maxSize' );
55 }
56
57 /**
58 * Set the allowed file types.
59 *
60 * @param string[] $allowedTypes
61 * @return $this
62 */
63 public function allowedTypes( $allowedTypes ) {
64 $this->validationRules->rule( 'allowedTypes', $allowedTypes );
65 return $this;
66 }
67
68 /**
69 * Access the allowed file types.
70 *
71 * @return string[]
72 */
73 public function getAllowedTypes() {
74 return $this->validationRules->getRule( 'allowedTypes' );
75 }
76 }
77