Exemplo n.º 1
0
/**
 * Output the required hidden fields when creating/editing a reply
 *
 * @since bbPress (r2753)
 *
 * @uses bbp_is_reply_edit() To check if it's the reply edit page
 * @uses wp_nonce_field() To generate hidden nonce fields
 * @uses bbp_reply_id() To output the reply id
 * @uses bbp_topic_id() To output the topic id
 * @uses bbp_forum_id() To output the forum id
 */
function bbp_reply_form_fields()
{
    if (bbp_is_reply_edit()) {
        ?>

		<input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php 
        printf(__('Reply To: %s', 'bbpress'), bbp_get_topic_title());
        ?>
" maxlength="<?php 
        bbp_get_title_max_length();
        ?>
" />
		<input type="hidden" name="bbp_reply_id"    id="bbp_reply_id"    value="<?php 
        bbp_reply_id();
        ?>
" />
		<input type="hidden" name="action"          id="bbp_post_action" value="bbp-edit-reply" />

		<?php 
        if (current_user_can('unfiltered_html')) {
            wp_nonce_field('bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false);
        }
        ?>

		<?php 
        wp_nonce_field('bbp-edit-reply_' . bbp_get_reply_id());
    } else {
        ?>

		<input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php 
        printf(__('Reply To: %s', 'bbpress'), bbp_get_topic_title());
        ?>
" maxlength="<?php 
        bbp_get_title_max_length();
        ?>
" />
		<input type="hidden" name="bbp_topic_id"    id="bbp_topic_id"    value="<?php 
        bbp_topic_id();
        ?>
" />
		<input type="hidden" name="action"          id="bbp_post_action" value="bbp-new-reply" />

		<?php 
        if (current_user_can('unfiltered_html')) {
            wp_nonce_field('bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false);
        }
        ?>

		<?php 
        wp_nonce_field('bbp-new-reply');
        // Show redirect field if not viewing a specific topic
        if (bbp_is_query_name('bbp_single_topic')) {
            bbp_redirect_to_field(get_permalink());
        }
    }
}
Exemplo n.º 2
0
/**
 * Return the link to subscribe/unsubscribe from a topic
 *
 * @since bbPress (r2668)
 *
 * @param mixed $args This function supports these arguments:
 *  - subscribe: Subscribe text
 *  - unsubscribe: Unsubscribe text
 *  - user_id: User id
 *  - topic_id: Topic id
 *  - before: Before the link
 *  - after: After the link
 * @param int $user_id Optional. User id
 * @uses bbp_get_user_id() To get the user id
 * @uses current_user_can() To check if the current user can edit user
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_is_user_subscribed() To check if the user is subscribed
 * @uses bbp_is_subscriptions() To check if it's the subscriptions page
 * @uses bbp_get_subscriptions_permalink() To get subscriptions link
 * @uses bbp_get_topic_permalink() To get topic link
 * @uses apply_filters() Calls 'bbp_get_user_subscribe_link' with the
 *                        link, args, user id & topic id
 * @return string Permanent link to topic
 */
function bbp_get_user_subscribe_link($args = '', $user_id = 0)
{
    if (!bbp_is_subscriptions_active()) {
        return;
    }
    $defaults = array('subscribe' => __('Subscribe', 'bbpress'), 'unsubscribe' => __('Unsubscribe', 'bbpress'), 'user_id' => 0, 'topic_id' => 0, 'before' => '&nbsp;|&nbsp;', 'after' => '');
    $args = bbp_parse_args($args, $defaults, 'get_user_subscribe_link');
    extract($args);
    // Validate user and topic ID's
    $user_id = bbp_get_user_id($user_id, true, true);
    $topic_id = bbp_get_topic_id($topic_id);
    if (empty($user_id) || empty($topic_id)) {
        return false;
    }
    // No link if you can't edit yourself
    if (!current_user_can('edit_user', (int) $user_id)) {
        return false;
    }
    // Decine which link to show
    $is_subscribed = bbp_is_user_subscribed($user_id, $topic_id);
    if (!empty($is_subscribed)) {
        $text = $unsubscribe;
        $query_args = array('action' => 'bbp_unsubscribe', 'topic_id' => $topic_id);
    } else {
        $text = $subscribe;
        $query_args = array('action' => 'bbp_subscribe', 'topic_id' => $topic_id);
    }
    // Create the link based where the user is and if the user is
    // subscribed already
    if (bbp_is_subscriptions()) {
        $permalink = bbp_get_subscriptions_permalink($user_id);
    } elseif (is_singular(bbp_get_topic_post_type())) {
        $permalink = bbp_get_topic_permalink($topic_id);
    } elseif (is_singular(bbp_get_reply_post_type())) {
        $permalink = bbp_get_topic_permalink($topic_id);
    } elseif (bbp_is_query_name('bbp_single_topic')) {
        $permalink = get_permalink();
    }
    $url = esc_url(wp_nonce_url(add_query_arg($query_args, $permalink), 'toggle-subscription_' . $topic_id));
    $is_subscribed = $is_subscribed ? 'is-subscribed' : '';
    $html = '<span id="subscription-toggle">' . $before . '<span id="subscribe-' . $topic_id . '" class="' . $is_subscribed . '"><a href="' . $url . '" class="dim:subscription-toggle:subscribe-' . $topic_id . ':is-subscribed">' . $text . '</a></span>' . $after . '</span>';
    // Return the link
    return apply_filters('bbp_get_user_subscribe_link', $html, $args, $user_id, $topic_id);
}