/**
  * Returns a single specified meta value for a term.
  *
  * This function is basically a wrapper for the WordPress core function `get_term_meta()`
  * when calling it with specification of a meta key. If the required field meta value is not available,
  * the function will automatically return its default value.
  *
  * Furthermore the $single parameter can be used to force an array or no array to be returned for the
  * meta field. You should generally leave it set to null.
  *
  * @since 0.6.0
  * @param integer $id the term ID to get the meta value for
  * @param string $meta_key the meta key (field slug) to get the meta value for
  * @param null|boolean $single whether to force an array or no array being returned (default is not to force anything)
  * @param boolean $formatted whether to return an automatically formatted value, ready for output (default is false)
  * @return mixed the meta value
  */
 function wpptd_get_term_meta_value($id, $meta_key, $single = null, $formatted = false)
 {
     if (!wpptd_supports_termmeta()) {
         if ($single) {
             return null;
         }
         return array();
     }
     $_meta_value = get_term_meta($id, $meta_key, false);
     if (doing_action('wpptd') || !did_action('wpptd')) {
         if ($single) {
             if (count($_meta_value) > 0) {
                 return $_meta_value[0];
             }
             return null;
         } else {
             return $_meta_value;
         }
     }
     $meta_value = null;
     $field = \WPDLib\Components\Manager::get('*.*.' . wpptd_get_taxonomy($id) . '.*.' . $meta_key, 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType.WPPTD\\Components\\Taxonomy.WPPTD\\Components\\TermMetabox', true);
     if ($field) {
         $meta_value = \WPPTD\Utility::parse_meta_value($_meta_value, $field, $single, $formatted);
     }
     return $meta_value;
 }
 /**
  * Checks whether all requirements to save meta values for a term are met.
  *
  * @since 0.6.0
  * @param integer $term_id the term ID to save
  * @param WP_Term $term the term object
  * @return bool whether the meta values can be saved
  */
 protected function can_save_meta($term_id, $term)
 {
     if (!wpptd_supports_termmeta()) {
         return false;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return false;
     }
     if (wpptd_get_taxonomy($term_id) != $this->slug) {
         return false;
     }
     $taxonomy_obj = get_taxonomy($this->slug);
     if (!current_user_can($taxonomy_obj->cap->edit_terms)) {
         return false;
     }
     return true;
 }
 /**
  * Renders the meta value of this field for usage in a terms list table column.
  *
  * @since 0.6.0
  * @param integer $term_id the term ID to display the meta value for
  */
 public function render_table_column($term_id)
 {
     $formatted = Utility::get_default_formatted($this->type);
     $output = wpptd_get_term_meta_value($term_id, $this->slug, null, $formatted);
     /**
      * This filter can be used by the developer to modify the way a specific meta value is printed in the terms list table.
      *
      * @since 0.6.0
      * @param mixed the formatted meta value
      * @param integer the term ID
      */
     echo apply_filters('wpptd_' . wpptd_get_taxonomy($term_id) . '_term_table_meta_' . $this->slug . '_output', $output, $term_id);
 }