Ejemplo n.º 1
0
 /**
  * @param $comment_id
  */
 public function save_comment($comment_id)
 {
     $groups = $this->groups_get('comment', 'comment');
     if (empty($groups)) {
         return $comment_id;
     } elseif (empty($_POST)) {
         return $comment_id;
     } elseif (!wp_verify_nonce(pods_v('pods_meta', 'post'), 'pods_meta_comment')) {
         return $comment_id;
     }
     $data = array();
     $id = $comment_id;
     $pod = null;
     foreach ($groups as $group) {
         if (empty($group['fields'])) {
             continue;
         }
         if (null === $pod || is_object($pod) && $pod->id() != $id) {
             if (!is_object(self::$current_pod) || self::$current_pod->pod != $group['pod']['name']) {
                 self::$current_pod = pods($group['pod']['name'], $id, true);
             } elseif (self::$current_pod->id() != $id) {
                 self::$current_pod->fetch($id);
             }
             $pod = self::$current_pod;
         }
         foreach ($group['fields'] as $field) {
             if (false === PodsForm::permission($field['type'], $field['name'], $field, $group['fields'], $pod, $id)) {
                 if (!pods_var('hidden', $field['options'], false)) {
                     continue;
                 }
             }
             $data[$field['name']] = '';
             if (isset($_POST['pods_meta_' . $field['name']])) {
                 $data[$field['name']] = $_POST['pods_meta_' . $field['name']];
             }
         }
     }
     do_action('pods_meta_save_pre_comment', $data, $pod, $id, $groups);
     if (!empty($pod)) {
         // Fix for Pods doing it's own sanitization
         $data = pods_unslash((array) $data);
         $pod->save($data);
     } elseif (!empty($id)) {
         pods_no_conflict_on('comment');
         foreach ($data as $field => $value) {
             update_comment_meta($id, $field, $value);
         }
         pods_no_conflict_off('comment');
     }
     do_action('pods_meta_save_comment', $data, $pod, $id, $groups);
     return $comment_id;
 }