function bb_update_postmeta($post_id, $meta_key, $meta_value) { return bb_update_meta($post_id, $meta_key, $meta_value, 'post'); }
/** * Custom insert post function so that we could do what we need * * All counting functions have been removed from here, recount should be done * after running this script. * * @param mixed $args * @return int|bool New post ID if post was created, otherwise false */ function w2bc_insert_post($args = null) { global $bbdb, $bb_current_user, $bb; if (!($args = wp_parse_args($args))) { return false; } $fields = array_keys($args); $defaults = array('topic_id' => 0, 'post_text' => '', 'post_time' => bb_current_time('mysql'), 'poster_id' => bb_get_current_user_info('id'), 'poster_ip' => $_SERVER['REMOTE_ADDR'], 'post_status' => 0, 'post_position' => false); // Insert all args $fields = array_keys($defaults); $fields[] = 'forum_id'; extract(wp_parse_args($args, $defaults)); if (!($topic = get_topic($topic_id))) { return false; } $topic_id = (int) $topic->topic_id; $forum_id = (int) $topic->forum_id; if (false === $post_position) { $post_position = $topic_posts = intval(0 == $post_status ? $topic->topic_posts + 1 : $topic->topic_posts); } $bbdb->insert($bbdb->posts, compact($fields)); $post_id = $topic_last_post_id = (int) $bbdb->insert_id; // if anonymous posting, save user data as meta data if (!$user) { if ($post_author) { bb_update_meta($post_id, 'post_author', $post_author, 'post'); } // Atleast this should be there if ($post_email) { bb_update_meta($post_id, 'post_email', $post_email, 'post'); } if ($post_url) { bb_update_meta($post_id, 'post_url', $post_url, 'post'); } } $topic_time = $post_time; $topic_last_poster = !bb_is_user_logged_in() && !bb_is_login_required() ? -1 : $poster_id; $topic_last_poster_name = !bb_is_user_logged_in() && !bb_is_login_required() ? $post_author : $user->user_login; $bbdb->update($bbdb->topics, compact('topic_time', 'topic_last_poster', 'topic_last_poster_name', 'topic_last_post_id', 'topic_posts'), compact('topic_id')); wp_cache_delete($topic_id, 'bb_topic'); wp_cache_delete($topic_id, 'bb_thread'); wp_cache_delete($forum_id, 'bb_forum'); wp_cache_flush('bb_forums'); wp_cache_flush('bb_query'); wp_cache_flush('bb_cache_posts_post_ids'); if (bb_get_option('enable_pingback')) { bb_update_postmeta($post_id, 'pingback_queued', ''); wp_schedule_single_event(time(), 'do_pingbacks'); } return $post_id; }
function bb_insert_post($args = null) { global $bbdb, $bb_current_user, $bb; if (!($args = nxt_parse_args($args))) { return false; } $fields = array_keys($args); if (isset($args['post_id']) && false !== $args['post_id']) { $update = true; if (!($post_id = (int) get_post_id($args['post_id']))) { return false; } // Get from db, not cache. Good idea? $post = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->posts} WHERE post_id = %d", $post_id)); $defaults = get_object_vars($post); unset($defaults['post_id']); // Only update the args we passed $fields = array_intersect($fields, array_keys($defaults)); if (in_array('topic_id', $fields)) { $fields[] = 'forum_id'; } // No need to run filters if these aren't changing // bb_new_post() and bb_update_post() will always run filters $run_filters = (bool) array_intersect(array('post_status', 'post_text'), $fields); } else { $post_id = false; $update = false; $now = bb_current_time('mysql'); $current_user_id = bb_get_current_user_info('id'); $ip_address = $_SERVER['REMOTE_ADDR']; $defaults = array('topic_id' => 0, 'post_text' => '', 'post_time' => $now, 'poster_id' => $current_user_id, 'poster_ip' => $ip_address, 'post_status' => 0, 'post_position' => false); // Insert all args $fields = array_keys($defaults); $fields[] = 'forum_id'; $run_filters = true; } $defaults['throttle'] = true; extract(nxt_parse_args($args, $defaults)); // If the user is not logged in and loginless posting is ON, then this function expects $post_author, $post_email and $post_url to be sanitized (check bb-post.php for example) if (!($topic = get_topic($topic_id))) { return false; } if (bb_is_login_required() && !($user = bb_get_user($poster_id))) { return false; } $topic_id = (int) $topic->topic_id; $forum_id = (int) $topic->forum_id; if ($run_filters && !($post_text = apply_filters('pre_post', $post_text, $post_id, $topic_id))) { return false; } if ($update) { // Don't change post_status with this function. Use bb_delete_post(). $post_status = $post->post_status; } if ($run_filters) { $post_status = (int) apply_filters('pre_post_status', $post_status, $post_id, $topic_id); } if (false === $post_position) { $post_position = $topic_posts = intval(0 == $post_status ? $topic->topic_posts + 1 : $topic->topic_posts); } unset($defaults['throttle']); if ($update) { $bbdb->update($bbdb->posts, compact($fields), compact('post_id')); nxt_cache_delete($post_id, 'bb_post'); } else { $bbdb->insert($bbdb->posts, compact($fields)); $post_id = $topic_last_post_id = (int) $bbdb->insert_id; if (0 == $post_status) { $topic_time = $post_time; $topic_last_poster = !bb_is_user_logged_in() && !bb_is_login_required() ? -1 : $poster_id; $topic_last_poster_name = !bb_is_user_logged_in() && !bb_is_login_required() ? $post_author : $user->user_login; $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts + 1 WHERE forum_id = %d;", $topic->forum_id)); $bbdb->update($bbdb->topics, compact('topic_time', 'topic_last_poster', 'topic_last_poster_name', 'topic_last_post_id', 'topic_posts'), compact('topic_id')); $query = new BB_Query('post', array('post_author_id' => $poster_id, 'topic_id' => $topic_id, 'post_id' => "-{$post_id}")); if (!$query->results) { $topics_replied_key = $bbdb->prefix . 'topics_replied'; bb_update_usermeta($poster_id, $topics_replied_key, $user->{$topics_replied_key} + 1); } } else { bb_update_topicmeta($topic->topic_id, 'deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts + 1 : 1); } } bb_update_topic_voices($topic_id); // if user not logged in, save user data as meta data if (!$user) { bb_update_meta($post_id, 'post_author', $post_author, 'post'); bb_update_meta($post_id, 'post_email', $post_email, 'post'); bb_update_meta($post_id, 'post_url', $post_url, 'post'); } if ($throttle && !bb_current_user_can('throttle')) { if ($user) { bb_update_usermeta($poster_id, 'last_posted', time()); } else { bb_set_transient($_SERVER['REMOTE_ADDR'] . '_last_posted', time()); } } if (!bb_is_login_required() && !($user = bb_get_user($poster_id))) { $post_cookie_lifetime = apply_filters('bb_post_cookie_lifetime', 30000000); setcookie('post_author_' . BB_HASH, $post_author, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain); setcookie('post_author_email_' . BB_HASH, $post_email, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain); setcookie('post_author_url_' . BB_HASH, $post_url, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain); } nxt_cache_delete($topic_id, 'bb_topic'); nxt_cache_delete($topic_id, 'bb_thread'); nxt_cache_delete($forum_id, 'bb_forum'); nxt_cache_flush('bb_forums'); nxt_cache_flush('bb_query'); nxt_cache_flush('bb_cache_posts_post_ids'); if ($update) { // fire actions after cache is flushed do_action('bb_update_post', $post_id); } else { do_action('bb_new_post', $post_id); } do_action('bb_insert_post', $post_id, $args, compact(array_keys($args))); // post_id, what was passed, what was used if (bb_get_option('enable_pingback')) { bb_update_postmeta($post_id, 'pingback_queued', ''); nxt_schedule_single_event(time(), 'do_pingbacks'); } return $post_id; }
echo "<br/>Create a new BBPress user {$uid} | {$obj->login} | {$obj->email} | {$obj->home_page} <br/>"; // Break up name into first and last names if ($num <= 1) { bb_update_meta($uid, 'first_name', $obj->name, 'user'); } else { $last_name = $names[$num - 1]; unset($names[$num - 1]); $first_name = implode(' ', $names); bb_update_meta($uid, 'first_name', $first_name, 'user'); bb_update_meta($uid, 'last_name', $last_name, 'user'); } // Add users location, occupation, interests, timezone bb_update_meta($uid, 'from', $obj->location, 'user'); bb_update_meta($uid, 'occ', $obj->occupation, 'user'); bb_update_meta($uid, 'interest', $obj->interests, 'user'); bb_update_meta($uid, 'time_zone', $obj->time_zone, 'user'); echo "Update user meta info <br/>"; // Update users joined date and alias $date = date('Y-m-d H:i:s', $obj->join_date); $sql1 = "UPDATE wp_users SET user_registered = '{$date}', display_name = '{$obj->alias}' WHERE ID = {$uid}"; $bbdb->query($sql1); // Update users role switch ($obj->level_id) { case 1: $role = 'seniormember'; break; case 2: $role = 'member'; break; case 3: $role = 'juniormember';