[bbDev] Re: Include bb from WP

fel64 at loinhead.net fel64 at loinhead.net
Mon Jun 4 17:17:32 GMT 2007


After some further digging, I think now that $bbdb is created but simply
not available later. Queries in bb-settings.php after $bbdb is created
work; queries made later in functions.php do not. Making a new $bbdb like
in this code in functions.php made everything run smoothly.

if( !isset( $bbdb ) ) {
	$bbdb = new bbdb('','','','');
	$bb_table_prefix = 'bb_';
	$bb->wp_table_prefix = 'wp_';
	$bbdb->forums    = $bb_table_prefix . 'forums';
	$bbdb->posts     = $bb_table_prefix . 'posts';
	$bbdb->topics    = $bb_table_prefix . 'topics';
	$bbdb->topicmeta = $bb_table_prefix . 'topicmeta';
	$bbdb->users     = ( $bb->wp_table_prefix ? $bb->wp_table_prefix :
$bb_table_prefix ) . 'users';
	$bbdb->usermeta  = ( $bb->wp_table_prefix ? $bb->wp_table_prefix :
$bb_table_prefix ) . 'usermeta';
	$bbdb->tags      = $bb_table_prefix . 'tags';
	$bbdb->tagged    = $bb_table_prefix . 'tagged';
}

An issue of scope? Declaring global $bbdb before db.php is loaded instead
also makes everything run smoothly. However I don't know why loading WP
first should affect the scope or $bbdb anyway. Does anyone know?

Anyway, solution: putting global $bbdb; in bb's config.php file.
Felix

> Hey,
>
> I was trying to make a wordpress plugin to achieve integration between
> blogposts and topics - so that each new blog post would create a topic,
> the replies would be shown instead of comments and you could 'comment' as
> before but it would be entered as a bb post in reply to the associated
> thread instead. To do this, I think using the bb API would be best, to
> create and edit the topic for example when making the blog post. Including
> bbPress at different stages in the WP plugin produces strange results, and
> I wonder how they could be resolved.
>
> Including in the main body of the plugin code loads it just fine and it
> works perfectly, except that that means bb is loaded all the time when
> it's mostly entirely unnecessary. I used
> require_once('path/to/bb-load.php');
> Including bb in a function called by a hook or filter always causes an
> error:
>
>> Fatal error: Call to a member function get_row() on a non-object in
> D:\xampp\htdocs\forums\bb-includes\functions.php on line 1224
>
> which I believe is because $bbdb is never created for some reason. This
> also happens if the hook is 'init'.
>
> I went through wp-settings.php and required bb systematically in different
> places. It worked at any point after requiring general-template.php (line
> 153), including after do_action('init');, which makes no sense to me at
> all.
>
> Is there a solution? A reliable way to load bb in functions called by
> hooks or filters?
>
> Cheers,
> Felix


More information about the bbDev mailing list