/vendor/wordimpress/maps-builder-core/includes/libraries/metabox/includes/types/CMB2_Type_Taxonomy_Base.php

  1. <?php 
  2. /** 
  3. * CMB Taxonomy base field type 
  4. * 
  5. * @since 2.2.2 
  6. * 
  7. * @category WordPress_Plugin 
  8. * @package CMB2 
  9. * @author WebDevStudios 
  10. * @license GPL-2.0+ 
  11. * @link http://webdevstudios.com 
  12. */ 
  13. abstract class CMB2_Type_Taxonomy_Base extends CMB2_Type_Multi_Base { 
  14.  
  15. /** 
  16. * Checks if we can get a post object, and if so, uses `get_the_terms` which utilizes caching 
  17. * @since 1.0.2 
  18. * @return mixed Array of terms on success 
  19. */ 
  20. public function get_object_terms() { 
  21. $object_id = $this->field->object_id; 
  22. $taxonomy = $this->field->args( 'taxonomy' ); 
  23.  
  24. if ( ! $post = get_post( $object_id ) ) { 
  25.  
  26. $cache_key = "cmb-cache-{$taxonomy}-{$object_id}"; 
  27.  
  28. // Check cache 
  29. $cached = get_transient( $cache_key ); 
  30. if ( $cached ) { 
  31. return $cached; 
  32.  
  33. $cached = wp_get_object_terms( $object_id, $taxonomy ); 
  34. // Do our own (minimal) caching. Long enough for a page-load. 
  35. set_transient( $cache_key, $cached, 60 ); 
  36. return $cached; 
  37.  
  38. // WP caches internally so it's better to use 
  39. return get_the_terms( $post, $taxonomy ); 
  40.  
  41. /** 
  42. * Wrapper for `get_terms` to account for changes in WP 4.6 where taxonomy is expected 
  43. * as part of the arguments. 
  44. * @since 2.2.2 
  45. * @return mixed Array of terms on success 
  46. */ 
  47. public function get_terms() { 
  48. return cmb2_utils()->wp_at_least( '4.5.0' ) 
  49. ? get_terms( array( 'taxonomy' => $this->field->args( 'taxonomy' ), 'hide_empty' => false ) ) 
  50. : get_terms( $this->field->args( 'taxonomy' ), 'hide_empty=0' ); 
  51.  
.