My hacks to make this plugin work for now
-
I had 2 main problems getting this plugin to work:
1. It doesn’t seem to make any attempt to insert points/title info in the topics pages.
2. The function to go through all posts to recount fails.
I’m sure this plugin will be fixed at some point. But for now, I did the following to make it work for me. Perhaps someone else will find it useful:
1. NOTHING SHOWS UP NEXT TO USER
I don’t see how anything should be able to show up, because the plugin doesn’t hook into the bbpress theme hooks for displaying something in the author pane of a reply.I found it to be most easy to just insert code in the BBPress template file (loop-single-reply.php):
Insert before or after the line
<?php do_action( 'bbp_theme_after_reply_author_details' ); ?>
this:<?php $rank = autorank_get_rank(bbp_get_reply_author_id(bbp_get_reply_id())); echo '<div class="author-rank">' . $rank[0] . '</div><div class="author-points">' . $rank[1] . ' points</div>'; ?>
.. or something similar
2. RE-COUNTING FAILS
On the Admin -> Tools -> Forum page (where all the re-count posts, topics, etc. etc. for the forum in general is) and at the bottom there is a checkbox saying “Re-score all posts.”. Check this and run to have it go through all users’ post and recount all the user scores.The function that does this is
autorank_recount()
in the plugin’sbbp-autorank.php
file.This fails for me however for 2 reasons. Firstly, the wordpress get_post function is called with some params, including the “post_author”. For some reason this results in an SQL select statement WITHOUT post_author in the WHERE clause. So WP tries to pull out all forum replies from the database one time per user.
To circumvent this, I’ve changed the function to this to bypass WP’s post retrieval:
function autorank_recount() { global $wpdb; $user_ids = $wpdb->get_col( "SELECT <code>ID</code> FROM <code>$wpdb->users</code>" ); foreach ( $user_ids as $id ) { $user_score = 0; $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM wp_posts WHERE post_author = %d AND post_type IN ('reply', 'topic') AND post_status = 'publish' ORDER BY ID ASC", $id)); foreach ( $post_ids as $post_id ) $user_score += autorank_get_post_score( $post_id ); update_user_meta( $id, 'autorank_score', $user_score ); } return array( 0, __( 'All scores recounted.', 'autoscore' ) ); }
Even still the function fails for me, but this is because I have over 200,000 replies in the forum, and that simply takes longer than the standard PHP timeout to go through.
This I solved by calling the autorank_recount() from another file with PHP timeout set to 10 minutes or so.
—-
I know this solution is ugly, but it’ll do for me, so someone else might find it useful.
- The topic ‘My hacks to make this plugin work for now’ is closed to new replies.