/** * Get the forum subscription link * * A custom wrapper for bbp_get_user_subscribe_link() * * @since 2.5.0 bbPress (r5156) * * @uses bbp_parse_args() * @uses bbp_get_user_subscribe_link() * @uses apply_filters() Calls 'bbp_get_topic_subscribe_link' */ function bbp_get_topic_subscription_link($args = array()) { // No link $retval = false; // Parse the arguments $r = bbp_parse_args($args, array('user_id' => 0, 'topic_id' => 0, 'before' => ' | ', 'after' => '', 'subscribe' => esc_html__('Subscribe', 'bbpress'), 'unsubscribe' => esc_html__('Unsubscribe', 'bbpress')), 'get_topic_subscribe_link'); // Get the link $retval = bbp_get_user_subscribe_link($r); return apply_filters('bbp_get_topic_subscribe_link', $retval, $r, $args); }
/** * AJAX handler to Subscribe/Unsubscribe a user from a topic * * @since bbPress (r3732) * * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_is_user_logged_in() To check if user is logged in * @uses bbp_get_current_user_id() To get the current user id * @uses current_user_can() To check if the current user can edit the user * @uses bbp_get_topic() To get the topic * @uses wp_verify_nonce() To verify the nonce * @uses bbp_is_user_subscribed() To check if the topic is in user's subscriptions * @uses bbp_remove_user_subscriptions() To remove the topic from user's subscriptions * @uses bbp_add_user_subscriptions() To add the topic from user's subscriptions * @uses bbp_ajax_response() To return JSON */ public function ajax_subscription() { // Bail if subscriptions are not active if (!bbp_is_subscriptions_active()) { bbp_ajax_response(false, __('Subscriptions are no longer active.', 'bbpress'), 300); } // Bail if user is not logged in if (!is_user_logged_in()) { bbp_ajax_response(false, __('Please login to subscribe to this topic.', 'bbpress'), 301); } // Get user and topic data $user_id = bbp_get_current_user_id(); $id = intval($_POST['id']); // Bail if user cannot add favorites for this user if (!current_user_can('edit_user', $user_id)) { bbp_ajax_response(false, __('You do not have permission to do this.', 'bbpress'), 302); } // Get the topic $topic = bbp_get_topic($id); // Bail if topic cannot be found if (empty($topic)) { bbp_ajax_response(false, __('The topic could not be found.', 'bbpress'), 303); } // Bail if user did not take this action if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'toggle-subscription_' . $topic->ID)) { bbp_ajax_response(false, __('Are you sure you meant to do that?', 'bbpress'), 304); } // Take action $status = bbp_is_user_subscribed($user_id, $topic->ID) ? bbp_remove_user_subscription($user_id, $topic->ID) : bbp_add_user_subscription($user_id, $topic->ID); // Bail if action failed if (empty($status)) { bbp_ajax_response(false, __('The request was unsuccessful. Please try again.', 'bbpress'), 305); } // Put subscription attributes in convenient array $attrs = array('topic_id' => $topic->ID, 'user_id' => $user_id); // Action succeeded bbp_ajax_response(true, bbp_get_user_subscribe_link($attrs, $user_id, false), 200); }
/** * Output the link to subscribe/unsubscribe from a topic * * @since 2.0.0 bbPress (r2668) * * @param array $args See {@link bbp_get_user_subscribe_link()} * @param int $user_id Optional. User id * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">. * @uses bbp_get_user_subscribe_link() To get the subscribe link */ function bbp_user_subscribe_link($args = array(), $user_id = 0, $wrap = true) { echo bbp_get_user_subscribe_link($args, $user_id, $wrap); }
/** * Get the forum subscription link * * A custom wrapper for bbp_get_user_subscribe_link() * * @since bbPress (r5156) * * @uses bbp_parse_args() * @uses bbp_get_user_subscribe_link() * @uses apply_filters() Calls 'bbp_get_forum_subscribe_link' */ function bbp_get_forum_subscription_link($args = array()) { // No link $retval = false; // Parse the arguments $r = bbp_parse_args($args, array('forum_id' => 0, 'user_id' => 0, 'before' => '', 'after' => '', 'subscribe' => __('Subscribe', 'bbpress'), 'unsubscribe' => __('Unsubscribe', 'bbpress')), 'get_forum_subscribe_link'); // No link for categories until we support subscription hierarchy // @see http://bbpress.trac.wordpress.org/ticket/2475 if (!bbp_is_forum_category()) { $retval = bbp_get_user_subscribe_link($r); } return apply_filters('bbp_get_forum_subscribe_link', $retval, $r); }
/** * Output the link to subscribe/unsubscribe from a topic * * @since bbPress (r2668) * * @param mixed $args See {@link bbp_get_user_subscribe_link()} * @uses bbp_get_user_subscribe_link() To get the subscribe link */ function bbp_user_subscribe_link($args = '') { echo bbp_get_user_subscribe_link($args); }