CMB2_Type_Taxonomy_Select

CMB taxonomy_select field type.

Defined (1)

The class is defined in the following location(s).

/vendor/wordimpress/maps-builder-core/includes/libraries/metabox/includes/types/CMB2_Type_Taxonomy_Select.php  
  1. class CMB2_Type_Taxonomy_Select extends CMB2_Type_Taxonomy_Base { 
  2.  
  3. public function render() { 
  4. $names = $this->get_object_terms(); 
  5.  
  6. $saved_term = is_wp_error( $names ) || empty( $names ) ? $this->field->get_default() : $names[key( $names )]->slug; 
  7. $terms = $this->get_terms(); 
  8. $options = ''; 
  9. $option_none = $this->field->args( 'show_option_none' ); 
  10.  
  11. if ( ! empty( $option_none ) ) { 
  12.  
  13. $field_id = $this->_id(); 
  14.  
  15. /** 
  16. * Default (option-none) taxonomy-select value. 
  17. * @since 1.3.0 
  18. * @param string $option_none_value Default (option-none) taxonomy-select value. 
  19. */ 
  20. $option_none_value = apply_filters( 'cmb2_taxonomy_select_default_value', '' ); 
  21.  
  22. /** 
  23. * Default (option-none) taxonomy-select value. 
  24. * The dynamic portion of the hook name, $field_id, refers to the field id attribute. 
  25. * @since 1.3.0 
  26. * @param string $option_none_value Default (option-none) taxonomy-select value. 
  27. */ 
  28. $option_none_value = apply_filters( "cmb2_taxonomy_select_{$field_id}_default_value", $option_none_value ); 
  29.  
  30. $options .= $this->select_option( array( 
  31. 'label' => $option_none,  
  32. 'value' => $option_none_value,  
  33. 'checked' => $saved_term == $option_none_value,  
  34. ) ); 
  35.  
  36. if ( ! empty( $terms ) ) { 
  37. foreach ( $terms as $term ) { 
  38. $options .= $this->select_option( array( 
  39. 'label' => $term->name,  
  40. 'value' => $term->slug,  
  41. 'checked' => $saved_term === $term->slug,  
  42. ) ); 
  43.  
  44. return $this->rendered( 
  45. $this->types->select( array( 'options' => $options ) ) 
  46. );