/**
  * Callback to delete the term meta when when a term is deleted.
  *
  * @access private
  * @since  8.2
  * @static
  *
  * @param int    $term          Term ID.
  * @param int    $tt_id         Term taxonomy ID.
  * @param string $taxonomy      Taxonomy slug.
  * @param mixed  $deleted_term  Copy of the already-deleted term, in the form specified
  *                              by the parent function. WP_Error otherwise.
  */
 public static function deleteTermMeta($term, $tt_id, $taxonomy, $deleted_term)
 {
     if (!is_wp_error($deleted_term)) {
         $meta = cnMeta::get('term', $term);
         if (!empty($meta)) {
             foreach ($meta as $key => $value) {
                 cnMeta::delete('term', $term, $key);
             }
         }
     }
 }
 /**
  * Add `meta_key` to term when updating
  *
  * @access public
  * @since  8.5.2
  *
  * @param  int $term_id Term ID.
  * @param  int $tt_id   Taxonomy Term ID.
  */
 public function save($term_id, $tt_id)
 {
     // Get the term being posted
     $term_key = 'term-' . $this->meta_key;
     // Bail if not updating meta_key
     $value = !empty($_POST[$term_key]) ? $_POST[$term_key] : '';
     if (empty($value)) {
         cnMeta::delete('term', $term_id, $this->meta_key);
         // Update meta_key value
     } else {
         cnMeta::update('term', $term_id, $this->meta_key, $value);
     }
 }
Пример #3
0
 /**
  * Load meta data for the player.
  */
 protected function loadMeta()
 {
     if ($this->meta !== null) {
         return $this->meta;
     }
     $meta = $this->entry->getMeta();
     if (!is_array($meta)) {
         $myMeta = array();
     } else {
         $myMeta = array();
         foreach ($meta as $key => $values) {
             if (count($values) > 1 && count(array_unique($values)) == 1) {
                 cnMeta::delete('entry', $this->entry->getId(), $key);
                 cnMeta::add('entry', $this->entry->getId(), $key, $values[0]);
             }
             $myMeta[$key] = $values[0];
         }
     }
     $this->meta = $myMeta;
     return $myMeta;
 }
 /**
  * Add, update or delete the meta of the specified entry ID.
  *
  * @access public
  * @since 0.8
  * @param  string $action The action to be performed.
  * @param  int    $id     The entry ID.
  * @param  array  $meta   [optional] An array of meta data the action is to be performed on.
  *
  * @return array          The meta IDs of the meta data the action was performed on.
  */
 public static function meta($action, $id, $meta = array())
 {
     $metaIDs = array();
     switch ($action) {
         case 'add':
             foreach ($meta as $row) {
                 $metaIDs[] = cnMeta::add('entry', $id, $row['key'], $row['value']);
             }
             break;
         case 'update':
             foreach ($meta as $metaID => $row) {
                 cnMeta::update('entry', $id, $row['key'], $row['value']);
                 $metaIDs[] = $metaID;
             }
             break;
         case 'delete':
             if (empty($meta)) {
                 $meta = cnMeta::get('entry', $id);
             }
             if ($meta) {
                 foreach ($meta as $key => $value) {
                     cnMeta::delete('entry', $id, $key);
                     $metaIDs[] = $key;
                 }
             }
             break;
     }
     return $metaIDs;
 }