Exemplo n.º 1
0
 /**
  * Collect metadata from all boxes.
  */
 function save_post($post_id, $post)
 {
     if ('revision' == $post->post_type || defined('DOING_AJAX')) {
         return;
     }
     if (isset($_POST['p2p_connections'])) {
         // Loop through the hidden fields instead of through $_POST['p2p_meta'] because empty checkboxes send no data.
         foreach ($_POST['p2p_connections'] as $p2p_id) {
             $data = scbForms::get_value(array('p2p_meta', $p2p_id), $_POST, array());
             $connection = p2p_get_connection($p2p_id);
             if (!$connection) {
                 continue;
             }
             $fields = p2p_type($connection->p2p_type)->fields;
             foreach ($fields as $key => &$field) {
                 $field['name'] = $key;
             }
             $data = scbForms::validate_post_data($fields, $data);
             scbForms::update_meta($fields, $data, $p2p_id, 'p2p');
         }
     }
     // Ordering
     if (isset($_POST['p2p_order'])) {
         foreach ($_POST['p2p_order'] as $key => $list) {
             foreach ($list as $i => $p2p_id) {
                 p2p_update_meta($p2p_id, $key, $i);
             }
         }
     }
 }
 protected function get_default($args, $p2p_id)
 {
     if (isset($args['default_cb'])) {
         return call_user_func($args['default_cb'], p2p_get_connection($p2p_id), $this->direction);
     }
     if (!isset($args['default'])) {
         return null;
     }
     return $args['default'];
 }
Exemplo n.º 3
0
 /**
  * 根据获取的 p2p 关联对象构造自定义
  * @param $object
  */
 function __construct($object)
 {
     if (is_numeric($object) || is_string($object)) {
         $this->p2p_id = intval($object);
     } elseif (@$object->p2p_id) {
         $this->p2p_id = $object->p2p_id;
     } else {
         wp_die(__('The given object is not a valid p2p object.', WCP_DOMAIN));
     }
     $conn = p2p_get_connection($this->p2p_id);
     $this->from = new static::$from_class(intval($conn->p2p_from));
     $this->to = new static::$to_class(intval($conn->p2p_to));
 }
Exemplo n.º 4
0
 /**
  * Adds a comment when a task's assignees are updated.
  *
  * @since    0.1.0
  */
 public function updated_assignees($p2p_id)
 {
     $current_user = wp_get_current_user();
     $connection = p2p_get_connection($p2p_id);
     if ('nervetask_to_user' == $connection->p2p_type) {
         $user_query = new WP_User_Query(array('fields' => array('ID', 'display_name')));
         // Query for users based on the meta data
         $assigned_user_query = new WP_User_Query(array('fields' => 'ID', 'connected_type' => 'nervetask_to_user', 'connected_items' => $connection->p2p_from));
         $assigned_users = '';
         foreach ($assigned_user_query->results as $user) {
             $user = get_user_by('id', $user);
             if (isset($prefix)) {
                 $assigned_users .= $prefix;
             }
             $assigned_users .= esc_html($user->display_name);
             $prefix = ', ';
         }
         $data = array('comment_author' => $current_user->display_name, 'comment_author_email' => $current_user->user_email, 'comment_content' => 'updated the assignee(s) to <strong>' . $assigned_users . '</strong>', 'comment_post_ID' => $connection->p2p_from, 'comment_type' => 'status');
         $comment_id = wp_insert_comment($data);
         if ($comment_id) {
             $statuses = get_the_terms($connection->p2p_from, 'nervetask_status');
             $comment_meta = update_comment_meta($comment_id, 'nervetask_status', $statuses);
         }
         return $comment_id;
     }
 }