Hi Zaerl,
I’m working on a plugin and have hit a similar issue.
I need to call certain functions before any data is sent to the browser, but after $forum and $topic etc have been worked out.
bb_init actions are called before this.
Did you ever find the action that we can call ?
thanks
Kev
Use bb_topic.php_pre_db
action.
Thank you Gautam!
EDIT: Actually I’m looking for an action that gets called on every page after the options and database hits have been done, and before any info has been sent to a browser.
I’ve tried:
bb_options_loaded
bb_plugins_loaded
bb_send_headers
EDIT 2: Actually, fingers crossed bb_index.php_pre_db
will work.
bb_index.php_pre_db didn’t work. It only worked on the homepage.
Hi Kevin. I found a “solution”. But I’m not proud of my code:
add_action('bb_topic.php', 'the_function');
add_action('bb_edit-post.php', 'the_function');
add_action('bb_forum.php', 'the_function');
add_action('bb_front-page.php', 'the_function');
add_action('whatever_other_template_page.php', 'the_function');
Basically speaking I hook those template pages that I need. The files in the root folder call:
bb_load_template('template_file.php', some_stuff);
in the very last line. That function calls the action bb_template_file.php
, include() template_file.php
and than calls the action bb_after_template_file.php
Maybe there’s a better solution. I’m not a bbPress expert.
This is a long time bug with bbpress that I’ve pointed out a few times but it’s too late now I guess to change it’s behavior.
The problem is that repermalink is not called before the bb_init hook so little is known about the page you are on.
If you try to call repermalink manually, it may mess up things later because it doesn’t like to be called twice. However in some cases you can get away with it.
Note it’s almost ALWAYS more efficient to bypass the bbpress API unless the data you need is already loaded in memory/cache.
You can calculate the last page with a single get_var query, so it’s more efficient to do that yourself if you need it right away and can’t wait for when the templates start loading (or are bypassing the templates loading).
Since bbpress does not re-calculate post-position when a post is deleted, if there are deleted posts in a topic, the page calculation from the API will almost certainly be wrong (the more deleted, the more likely wrong if the user is not admin). Hence using your own query will again be better.
Somewhere I have a really fancy mysql query to calculate the real page a post is on, let me know if you want me to dig for it.