function addTermImage($term) { $taxonomies = get_option(STI_OPTIONS_NAME); if (in_array($term->taxonomy, $taxonomies['taxonomies'])) { $term->term_taxo_image = get_term_taxonomy_meta($term->term_taxonomy_id, 'term_taxo_image', true); } return $term; }
/** * Get a term meta field * * @param string $taxonomy * @param integer $term_id * @param string|array $meta_key * @param boolean $single * @return boolean * @author Amaury Balmer */ function get_term_meta($taxonomy = '', $term_id = 0, $meta_key = '', $single = false) { // Taxonomy is valid ? if (!taxonomy_exists($taxonomy)) { return false; } // Term ID exist for this taxonomy ? $term = get_term((int) $term_id, $taxonomy); if ($term == false || is_wp_error($term)) { return false; } return get_term_taxonomy_meta($term->term_taxonomy_id, $meta_key, $single); }
/** * Return the value of a term meta. Support before and after wrapper. Use WP_Query term by default, with parameters for specificy a custom term. * * @param (string) $meta_key * @param (string) $before * @param (string) $after * @param (integer) $term_id * @param (string) $taxonomy * @param (array) $filters */ function st_get_term_meta($meta_key = '', $before = '', $after = '', $term_id = null, $taxonomy = '', $filters = array()) { if (empty($meta_key) || $meta_key == false) { return ''; } $term = false; if ($term_id != null && !empty($taxonomy) && taxonomy_exists($taxonomy)) { // Manual term with param ? $term = get_term($term_id, $taxonomy); } if ($term == false || is_wp_error($term) || $term == null) { // Get current term from WP_Query $term = get_current_term(); if ($term == false) { return ''; } } if ((int) $term->term_taxonomy_id == 0) { // Last check if term is valid. return ''; } $meta_value = get_term_taxonomy_meta($term->term_taxonomy_id, $meta_key, true); $meta_value = maybe_unserialize($meta_value); if ($meta_value == false || is_wp_error($meta_value) || empty($meta_value)) { return ''; } if (is_string($meta_value)) { $meta_value = trim(stripslashes($meta_value)); if (is_array($filters) && !empty($filters)) { foreach ($filters as $filter) { $meta_value = apply_filters($filter, $meta_value, $term, $meta_key); } } } if (!is_string($meta_value)) { return apply_filters('st_get_term_meta', $meta_value, $meta_key, $term); } return $before . apply_filters('st_get_term_meta', $meta_value, $meta_key, $term) . $after; }
function removeAssociation() { if (!isset($_POST['tt_id'])) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('tt_id not sent', 'sti'))); } $tt_id = absint($_POST['tt_id']); if (empty($tt_id)) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('tt_id is empty', 'sti'))); } if (!$this->checkPermissions($tt_id)) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('You do not have the correct capability to manage this term', 'sti'))); } if (!isset($_POST['wp_nonce'])) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('No nonce included', 'sti'))); } if (!wp_verify_nonce($_POST['wp_nonce'], 'sti-remove-association')) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('Nonce did not match', 'sti'))); } $meta = get_term_taxonomy_meta($tt_id, 'term_taxo_image'); if (!isset($meta)) { $this->jsonResponse(array('status' => 'good', 'why' => esc_html__('Nothing to remove', 'sti'))); } if (delete_term_taxonomy_meta($tt_id, 'term_taxo_image')) { $this->jsonResponse(array('status' => 'good', 'why' => esc_html__('Association successfully removed', 'sti'))); } else { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('Association could not be removed', 'sti'))); } /* Don't know why, but something didn't work. */ $this->jsonResponse(); }
function updateEntries($args, $number) { if (!isset($this->option_fields[$this->option_name][$number]['slug']) || empty($this->option_fields[$this->option_name][$number]['slug'])) { $this->slug = $this->option_name . '__' . $number; } else { $this->slug = $this->option_fields[$this->option_name][$number]['slug']; } if (isset($args['post_id']) && $args['post_id'] != null) { $test = get_post_meta($args['post_id'], $this->slug, true); if ($test == false && empty($args['entries'])) { return false; } elseif ($test !== false && empty($args['entries'])) { delete_post_meta($args['post_id'], $this->slug); return false; } else { $entries['entries'] = update_post_meta($args['post_id'], $this->slug, $args['entries']); } } elseif ($args['tt_id'] != null) { $test = get_term_taxonomy_meta($args['tt_id'], $this->slug, true); if ($test == false && empty($args['entries'])) { return false; } elseif ($test !== false && empty($args['entries'])) { delete_term_taxonomy_meta($args['tt_id'], $this->slug); return false; } else { $entries['entries'] = update_term_taxonomy_meta($args['tt_id'], $this->slug, $args['entries']); } } else { return false; } return true; }