PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.1
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
71 lines 1.3 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 /**
6 * A file upload field.
7 *
8 * @since 2.12.0
9 */
10 class File extends Field {
11
12 use Concerns\AllowMultiple;
13 use Concerns\HasEmailTag;
14 use Concerns\HasHelpText;
15 use Concerns\HasLabel;
16 use Concerns\ShowInReceipt;
17 use Concerns\StoreAsMeta;
18
19 const TYPE = 'file';
20
21 /**
22 * @param $name
23 */
24 public function __construct( $name ) {
25 parent::__construct( $name );
26
27 $this->validationRules->rule( 'maxSize', 1024 );
28 $this->validationRules->rule( 'allowedTypes', [ '*' ] );
29 }
30
31 /**
32 * Set the maximum file size.
33 *
34 * @param int $maxSize
35 * @return $this
36 */
37 public function maxSize( $maxSize ) {
38 $this->validationRules->rule( 'maxSize', $maxSize );
39 return $this;
40 }
41
42 /**
43 * Access the maximum file size.
44 *
45 * @return int
46 */
47 public function getMaxSize() {
48 return $this->validationRules->getRule( 'maxSize' );
49 }
50
51 /**
52 * Set the allowed file types.
53 *
54 * @param string[] $allowedTypes
55 * @return $this
56 */
57 public function allowedTypes( $allowedTypes ) {
58 $this->validationRules->rule( 'allowedTypes', $allowedTypes );
59 return $this;
60 }
61
62 /**
63 * Access the allowed file types.
64 *
65 * @return string[]
66 */
67 public function getAllowedTypes() {
68 return $this->validationRules->getRule( 'allowedTypes' );
69 }
70 }
71