Search Results for 'code'
-
Search Results
-
Topic: on plugin deactivation…
Hi,
There is a hook so that, on plugin deactivation, you can do an action. In my case, I want to drop a table when the plugin is deactivated.
I can’t seem to get it to work. What am I missing?
The code:
function bb_deactivate_bbmenu() {
bb_register_deactivation_hook( bbmenu.php, 'drop_bbmenu_table' );
}
do_action( 'bb_deactivate_bbmenu' . $plugin );
function drop_bbmenu_table() {
global $bbdb;
$query = "DROP TABLE <code>$bbdb->menu</code>";
$bbdb->query( $query );
}Also where does
$plugincome from? Do I need to set it or does it grab the plugin’s name? And same about __file__ I used the plugins php file for this. Is this correct?Some help plz
The front page topics plugin was driving me crazy because I really did want to have a different number of topics for the front page, forum pages, view pages, while leaving the posts per topic page alone and not have to hack the core.
But there is a huge flaw in the fundamental design in that if you force bbpress to see a different number of topics-per-page, it will calculate the last post page entirely wrong, based on the page IT’S ON, vs the destination page.
ie. front page set to 50 topics, posts-per-topic-page set to 25, last post is #30 on the page -> bbpress will calculate the page number for the last post as PAGE ONE off the front page, because that’s what the topic count is set to for the front page.
This got me really annoyed so I researched the heck out of it and figured out this trick – it’s nasty but works (for 8.2.1 at least).
so in config.php you’ve got
// The number of topics that show on each page.
$bb->page_topics = 20;now you can make a plugin with this, edit each page limit to your heart’s desire (anything without a $limit defined uses the config.php default)
function custom_topic_limit($limit) {
switch (bb_get_location()) :
case 'front-page': $limit=45; break;
case 'forum-page': $limit=35; break;
case 'tag-page': break;
case 'topic-page': break;
case 'feed-page': break;
case 'search-page': break;
case 'profile-page': break;
case 'favorites-page': break;
case 'view-page': $limit=50; break;
case 'stats-page': $limit=50; break;
case 'login-page': break;
default: $limit=20;
endswitch;
return $limit;
}
add_action( 'bb_get_option_page_topics', 'custom_topic_limit' );
function fix_post_link ($link,$post_id) {
remove_action( 'bb_get_option_page_topics', 'custom_topic_limit' );
$bb_post = bb_get_post( get_post_id( $post_id ) );
$page = get_page_number( $bb_post->post_position );
return get_topic_link( $bb_post->topic_id, $page ) . "#post-$bb_post->post_id";
}
add_filter( 'get_post_link','fix_post_link',10, 2);The magic is in fix_post_link where it trashes whatever incorrect calculation that “get_post_link” has now done because of custom topic limits, and relculates it after unhooking the custom_topic_limit.
No core hacks required!

Even better if a user can choose this when seeing the results: