/** * Outputs the post form subscription checkbox. * * Checks if user is subscribed and outputs checkbox based on status. * * @since 1.1 */ function bb_user_subscribe_checkbox($args = null) { if (!bb_is_user_logged_in()) { return false; } $is_current = false; $defaults = array('tab' => false); $args = wp_parse_args($args, $defaults); $tab = $args['tab'] !== false ? ' tabindex="' . $args['tab'] . '"' : ''; $is_current = bb_get_user_id(get_post_author_id()) == bb_get_current_user_info('id'); // Change subscription checkbox message if current or moderating if (bb_is_topic_edit() && !$is_current) { $text = __('This user should be notified of follow-up posts via email'); } else { $text = __('Notify me of follow-up posts via email'); } echo ' <label for="subscription_checkbox"> <input name="subscription_checkbox" id="subscription_checkbox" type="checkbox" value="subscribe" ' . checked(true, bb_is_user_subscribed(), false) . $tab . ' /> ' . apply_filters('bb_user_subscribe_checkbox_label', $text, (bool) $is_current) . ' </label>'; }
/** * Process subscription checkbox submission. * * Get ID of and new subscription status and pass values to * bb_user_subscribe_checkbox_update function * * @since 1.1 * * @param int $post_id ID of new/edited post */ function bb_user_subscribe_checkbox_update($post_id) { if (!bb_is_user_logged_in()) { return false; } $post = bb_get_post($post_id); $topic_id = (int) $post->topic_id; $subscribed = bb_is_user_subscribed(array('topic_id' => $topic_id, 'user_id' => $post->poster_id)) ? true : false; $check = $_REQUEST['subscription_checkbox']; do_action('bb_user_subscribe_checkbox_update', $post_id, $topic_id, $subscribe, $check); if ('subscribe' == $check && !$subscribed) { bb_subscription_management($topic_id, 'add'); } elseif (!$check && $subscribed) { bb_subscription_management($topic_id, 'remove'); } }