PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.8
JetFormBuilder — Dynamic Blocks Form Builder v3.0.8
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / request / fields / media-field-parser.php
jetformbuilder / includes / request / fields Last commit date
date-field-parser.php 3 years ago datetime-field-parser.php 3 years ago datetime-trait.php 3 years ago hidden-field-parser.php 3 years ago media-field-parser.php 3 years ago repeater-field-parser.php 3 years ago text-field-parser.php 3 years ago wysiwyg-field-parser.php 3 years ago
media-field-parser.php
61 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Request\Fields;
5
6 use Jet_Form_Builder\Classes\Resources\Media_Block_Value;
7 use Jet_Form_Builder\Exceptions\Request_Exception;
8 use Jet_Form_Builder\Request\Exceptions\Sanitize_Value_Exception;
9 use Jet_Form_Builder\Classes\Resources\Upload_Exception;
10 use Jet_Form_Builder\Request\Field_Data_Parser;
11 use Jet_Form_Builder\Request\File_Uploader;
12
13 class Media_Field_Parser extends Field_Data_Parser {
14
15 public function type() {
16 return 'media-field';
17 }
18
19 /**
20 * @since 3.0.4 Added `jet-form-builder/media-field/before-upload` hook
21 *
22 * @return array|false|int|string|null
23 * @throws Sanitize_Value_Exception
24 */
25 public function get_response() {
26 if ( empty( $this->context->get_file() ) ) {
27 return false;
28 }
29 do_action( 'jet-form-builder/media-field/before-upload', $this );
30
31 $uploader = ( new File_Uploader() )->set_context( $this->context );
32
33 try {
34 /** @var Media_Block_Value $uploads */
35 $uploads = $uploader->upload();
36 } catch ( Upload_Exception $exception ) {
37 throw new Sanitize_Value_Exception( $exception->getMessage() );
38 }
39
40 jet_fb_request_handler()->update_file( $this->name, $uploads );
41
42 switch ( $this->get_value_format() ) {
43 case 'id':
44 return $uploads->get_attachment_id();
45 case 'both':
46 return $uploads->get_attachment_both();
47 default:
48 return $uploads->get_attachment_url();
49 }
50 }
51
52 protected function get_value_format(): string {
53 if ( empty( $this->get_context()->get_settings()['insert_attachment'] ) ) {
54 return 'url';
55 }
56
57 return $this->get_context()->get_settings()['value_format'] ?? 'url';
58 }
59
60 }
61