public function get_meta($field = '', $single = false, $formatted = false) { $use_wpptd = null === $single || $formatted; if ($field) { if ($use_wpptd && function_exists('wpptd_get_term_meta_value')) { return wpptd_get_term_meta_value($this->item->term_id, $field, $single, $formatted); } if (!$single) { $single = false; } return get_term_meta($this->item->term_id, $field, $single); } else { if ($use_wpptd && function_exists('wpptd_get_term_meta_values')) { return wpptd_get_term_meta_values($this->item->term_id, $single, $formatted); } return get_term_meta($this->item->term_id); } }
/** * Validates a term's meta values for all meta fields of the taxonomy. * * It iterates through all the meta fields of the term and validates each one's value. * If a field is not set for some reason, its default value is saved. * * Furthermore this function adds settings errors if any occur. * * @since 0.6.0 * @param array $meta_values array of submitted meta values * @param integer $term_id the current term ID * @return array the validated meta values */ protected function validate_meta_values($meta_values, $term_id) { $meta_values_validated = array(); $meta_values_old = array(); $errors = array(); $changes = false; foreach ($this->get_children('WPPTD\\Components\\TermMetabox') as $metabox) { foreach ($metabox->get_children() as $field) { $meta_value_old = wpptd_get_term_meta_value($term_id, $field->slug); if ($meta_value_old === null) { $meta_value_old = $field->default; } $meta_values_old[$field->slug] = $meta_value_old; $meta_value = null; if (isset($meta_values[$field->slug])) { $meta_value = $meta_values[$field->slug]; } list($meta_value_validated, $error, $changed) = $this->validate_meta_value($field, $meta_value, $meta_value_old); $meta_values_validated[$field->slug] = $meta_value_validated; if ($error) { $errors[$field->slug] = $error; } elseif ($changed) { $changes = true; } } } if ($changes) { /** * This action can be used to perform additional steps when the meta values of this taxonomy were updated. * * @since 0.6.0 * @param array the updated meta values as $field_slug => $value * @param array the previous meta values as $field_slug => $value */ do_action('wpptd_update_term_meta_values_' . $this->slug, $meta_values_validated, $meta_values_old); } /** * This filter can be used by the developer to modify the validated meta values right before they are saved. * * @since 0.6.0 * @param array the associative array of meta keys (fields slugs) and their values */ $meta_values_validated = apply_filters('wpptd_validated_term_meta_values_' . $this->slug, $meta_values_validated); $this->add_settings_message($errors, $term_id); return $meta_values_validated; }
/** * 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); }