function createAssociation() { 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'))); die; } if (!isset($_POST['wp_nonce'])) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('No nonce included.', 'sti'))); die; } if (!wp_verify_nonce($_POST['wp_nonce'], 'sti-create-association')) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('Nonce did not match', 'sti'))); die; } if (!isset($_POST['attachment_id'])) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('Image id not sent', 'sti'))); die; } $image_id = absint($_POST['attachment_id']); if (empty($image_id)) { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('Image id is not a positive integer', 'sti'))); die; } if (update_term_taxonomy_meta($tt_id, 'term_taxo_image', $image_id)) { $this->jsonResponse(array('status' => 'good', 'why' => esc_html__('Image successfully associated', 'sti'), 'attachment_thumb_src' => $this->getImageSrc($image_id))); die; } else { $this->jsonResponse(array('status' => 'bad', 'why' => esc_html__('Association could not be created', 'sti'))); die; } }
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; }
function a_migration() { if (!($ttoptions = get_option('taxonomy_image_plugin'))) { STI_Admin::jsonResponse(array('status' => 'bad', 'why' => esc_html__('No options founded', 'sti'))); } foreach ($ttoptions as $tt => $attachId) { update_term_taxonomy_meta($tt, 'term_taxo_image', $attachId); } STI_Admin::jsonResponse(array('status' => 'good', 'why' => esc_html__('Migration successfull !', 'sti'))); die; }
/** * Update a term meta field * * @param string $taxonomy * @param integer $term_id * @param string $meta_key * @param string|array $meta_value * @param string|array $prev_value * @return boolean * @author Amaury Balmer */ function update_term_meta($taxonomy = '', $term_id = 0, $meta_key, $meta_value, $prev_value = '') { // 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 update_term_taxonomy_meta($term->term_taxonomy_id, $meta_key, $meta_value, $prev_value); }