Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: from wordpress plugin, bb-load.php causes blank page

Most of this code was taken directly from the bbsync plugin (I’ve attempted to remove need for configuration, and some of the bbsync functionality/flexibility).

There are really truly NO errors logged anywhere for this.

here is my plugin in it’s entirety:

define('CRBBFORUMID', 1);

function cr_post($post_id) {
global $bbdb, $wpdb, $current_user;

require (dirname(__FILE__) . '/../../bbpress/config.php');
// get the post
$post = wp_get_single_post( $post_id );

if(!$current_user) {
return;
}
bb_set_current_user($current_user->ID);

$post_title = $bbdb->escape($post->post_title);

$bb_topic_arr = get_post_meta($post_id, 'bb_topic', $true);
$bb_topic_id = $bb_topic_arr[0];

// if bb has this post already, update the topic
$topic_exists = false;
if ($bb_topic_id) {
if(bb_update_topic($post_title, $bb_topic_id)) {
$topic_exists = true;
}
$reply = bb_get_first_post($bb_topic_id);
bb_update_post($post_text, $reply->post_id, $bb_topic_id);
}

// if not, create a new topic
if (!$topic_exists) {
$topic_id = bb_new_topic($post_title, CRBBFORUMID, $tags);
$reply_id = bb_new_post($bb_topic_id, $post_text);

$r = false;
if ($topic_id && $reply_id) {
bb_update_topicmeta($bb_topic_id, 'wp_post', $post_id);
if (!update_post_meta($post_id, 'bb_topic', $topic_id)) {
add_post_meta($post_id, 'bb_topic', $topic_id, true);
$r = true;
}
}
$oldcoms = get_approved_comments($post_id);
if($oldcoms) {
foreach($oldcoms AS $oldcom) {
if($user = bb_get_user($oldcom->comment_author)) {
$time = strtotime($oldcom->comment_date);
$text = '<em><strong>This comment was originally posted at ' . date('G:i', $time) . ' on ' . date('jS F Y', $time) . ".</strong></em>nn" . $oldcom->comment_content;
bb_set_current_user($user->ID);
bb_new_post($topic_id, mysql_real_escape_string($text));
}
}
}
}
return $r;
}

function cr_comment($comment_id, $approval_status) {
global $bbdb, $wpdb;
require_once(dirname(__FILE__) . '/../../bbpress/bb-load.php');

$comment = get_comment($comment_id);

$topic_id = get_post_meta($comment->comment_post_ID, 'bb_topic', $true);
if(($topic_id) && ($approval_status == 1) && ($comment->user_id) && bb_set_current_user($comment->user_id)) {
//topic linked, genuine comment, actual user, bb likes user
bb_new_post($topic_id, $comment->comment_content);
return true;
} else {
return false;
}
}

add_action('publish_post', 'cr_post');
add_action('comment_post', 'cr_comment');

Skip to toolbar