/**
 * Delete term meta for term
 *
 * @param string $taxonomy 
 * @param integer $term_id 
 * @param string $meta_key 
 * @param string|array $meta_value 
 * @return boolean
 * @author Amaury Balmer
 */
function delete_term_meta($taxonomy = '', $term_id = 0, $meta_key = '', $meta_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 delete_term_taxonomy_meta($term->term_taxonomy_id, $meta_key, $meta_value);
}
 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();
 }
예제 #3
0
 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;
 }