示例#1
0
function ap_add_recipients($recipient, $sender, $conversation_id)
{
    $recipient = sanitize_comma_delimited($recipient);
    $sender = filter_var($sender, FILTER_SANITIZE_NUMBER_INT);
    $users = array_unique(explode(',', str_replace(' ', '', $recipient . ',' . $sender)));
    if (!empty($users)) {
        foreach ($users as $user) {
            ap_add_meta($user, 'recipient', $conversation_id);
        }
    }
}
示例#2
0
/**
 * Insert and update AnsPress activity
 * If id is passed then existing activity will be updated.
 *
 * @param  array $args {
 *     Array of arguments.
 *     @type integer $id      			Activity id. If activity id is passed then activity will be updated.
 *     @type integer $user_id      		Main user ID of this activity. Default is current user.
 *     @type integer $secondary_user    Secondary user id.
 *     @type string  $secondary_user    Type of activity.
 *     @type string  $content    	    Activity content.
 *     @type integer $item_id    	    Related item id.
 *     @type integer $secondary_id	    Related secondary item id.
 *     @type string  $created	    	Created date.
 *     @type string  $updated	    	Updated date.
 * }
 * @return boolean|integer
 */
function ap_insert_activity($args)
{
    global $wpdb;
    $user_id = get_current_user_id();
    $defaults = array('user_id' => $user_id, 'secondary_user' => 0, 'type' => '', 'parent_type' => 'post', 'status' => 'publish', 'content' => '', 'permalink' => '', 'question_id' => '', 'answer_id' => '', 'item_id' => '', 'term_ids' => '', 'created' => '', 'updated' => '');
    $activity_id = isset($args['id']) ? intval($args['id']) : false;
    $args = wp_parse_args($args, $defaults);
    $args['user_id'] = intval($args['user_id']);
    $args['secondary_user'] = intval($args['secondary_user']);
    $args['type'] = sanitize_text_field(wp_unslash($args['type']));
    $args['parent_type'] = sanitize_text_field(wp_unslash($args['parent_type']));
    $args['status'] = sanitize_text_field(wp_unslash($args['status']));
    $args['content'] = esc_html(wp_kses_post(wp_unslash($args['content'])));
    $args['permalink'] = esc_url($args['permalink']);
    $args['question_id'] = (int) $args['question_id'];
    $args['answer_id'] = (int) $args['answer_id'];
    $args['item_id'] = (int) $args['item_id'];
    $args['term_ids'] = sanitize_comma_delimited($args['term_ids']);
    if (empty($args['created']) || '0000-00-00 00:00:00' == $args['created']) {
        $args['created'] = current_time('mysql');
    } else {
        $args['created'] = $args['created'];
    }
    if (empty($args['updated']) || '0000-00-00 00:00:00' == $args['updated']) {
        $args['updated'] = current_time('mysql');
    } else {
        $args['updated'] = $args['updated'];
    }
    // Remove extra args.
    $coulmns = array_intersect_key($args, $defaults);
    $format = array('%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%s', '%s');
    if (false === $activity_id) {
        $row = $wpdb->insert($wpdb->ap_activity, $coulmns, $format);
        if (false !== $row) {
            do_action('ap_after_inserting_activity', $wpdb->insert_id, $args);
            return $wpdb->insert_id;
        }
    } else {
        $row = $wpdb->update($wpdb->ap_activity, $coulmns, array('id' => $activity_id), $format, array('%d'));
        if (false !== $row) {
            wp_cache_delete($activity_id, 'ap_activity');
            do_action('ap_after_updating_activity', $id, $args);
            return $row;
        }
    }
    return false;
}