Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Checkbox for e-mail subscription + ideas for better backend

@dimadin

Participant

I have found solution for problem. Since I based form on Subscribe to Topics, I mistakenly used it’s arguments. So working function should be:

function bb_checkbox_subscription_update($post_id) {

global $bbdb, $bb_current_user, $bb_post, $topic, $wp_taxonomy_object;

$bb_post=bb_get_post($post_id);

if (!empty($_REQUEST)) {

$checkbox_status = $_REQUEST;

if ( ‘add’ == $checkbox_status ) {

$tt_ids = $wp_taxonomy_object->set_object_terms( $bb_current_user->ID, ‘topic-‘ . $bb_post->topic_id, ‘bb_subscribe’, array( ‘append’ => true, ‘user_id’ => $bb_current_user->ID ) );

} elseif ( ‘remove’ == $checkbox_status ) {

// I hate this with the passion of a thousand suns

$term_id = $bbdb->get_var( “SELECT term_id FROM $bbdb->terms WHERE slug = ‘topic-$bb_post->topic_id'” );

$term_taxonomy_id = $bbdb->get_var( “SELECT term_taxonomy_id FROM $bbdb->term_taxonomy WHERE term_id = $term_id AND taxonomy = ‘bb_subscribe'” );

$bbdb->query( “DELETE FROM $bbdb->term_relationships WHERE object_id = $bb_current_user->ID AND term_taxonomy_id = $term_taxonomy_id” );

$bbdb->query( “DELETE FROM $bbdb->term_taxonomy WHERE term_id = $term_id AND taxonomy = ‘bb_subscribe'” );

}

}

}

Also, I made a code for improvements I suggested in first post. You can see it here. Also check this ticket.

Skip to toolbar