Info
- 7 posts
- 4 voices
- Started 2 years ago by usmentr
- Latest reply from _ck_
- This topic is not resolved
Get last page in bb_init
-
- Posted 2 years ago #
Hi there. I'm writing a small plugin and I need to check if the actual page is the last page of a topic. I've seen that this is the standard way:
if(bb_current_user_can('write_posts') && bb_is_topic()) { global $topic, $page; $add = topic_pages_add(); $last_page = get_page_number( $topic->topic_posts + $add ); if($last_page == $page) do whatever you want }but I want to use this code during the bb_init callback. It doesn't work and after some simple tests I've seen that $topic isn't defined (yet). Is there a way to get last page during this callback?
Thanks in advance.
-
- Posted 1 year ago #
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 -
- Posted 1 year ago #
Use
bb_topic.php_pre_dbaction. -
- Posted 1 year ago #
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_headersEDIT 2: Actually, fingers crossed
bb_index.php_pre_dbwill work. -
- Posted 1 year ago #
bb_index.php_pre_db didn't work. It only worked on the homepage.
-
- Posted 1 year ago #
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.phpand than calls the action bb_after_template_file.phpMaybe there's a better solution. I'm not a bbPress expert.
-
- Posted 1 year ago #
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.
-
You must log in to post.