예제 #1
0
/**
 * Return the edit link of the topic
 *
 * @since 2.0.0 bbPress (r2727)
 *
 * @param array $args This function supports these args:
 *  - id: Optional. Topic id
 *  - link_before: Before the link
 *  - link_after: After the link
 *  - edit_text: Edit text
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic() To get the topic
 * @uses current_user_can() To check if the current user can edit the
 *                           topic
 * @uses bbp_get_topic_edit_url() To get the topic edit url
 * @uses apply_filters() Calls 'bbp_get_topic_edit_link' with the link
 *                        and args
 * @return string Topic edit link
 */
function bbp_get_topic_edit_link($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('id' => 0, 'link_before' => '', 'link_after' => '', 'edit_text' => esc_html__('Edit', 'bbpress')), 'get_topic_edit_link');
    // Get the topic
    $topic = bbp_get_topic($r['id']);
    // Bypass check if user has caps
    if (!current_user_can('edit_others_topics')) {
        // User cannot edit or it is past the lock time
        if (empty($topic) || !current_user_can('edit_topic', $topic->ID) || bbp_past_edit_lock($topic->post_date_gmt)) {
            return;
        }
    }
    // Get uri
    $uri = bbp_get_topic_edit_url($topic->ID);
    // Bail if no uri
    if (empty($uri)) {
        return;
    }
    $retval = $r['link_before'] . '<a href="' . esc_url($uri) . '" class="bbp-topic-edit-link">' . $r['edit_text'] . '</a>' . $r['link_after'];
    return apply_filters('bbp_get_topic_edit_link', $retval, $r, $args);
}
예제 #2
0
/**
 * Return the edit link of the topic
 *
 * @since bbPress (r2727)
 *
 * @param mixed $args This function supports these args:
 *  - id: Optional. Topic id
 *  - link_before: Before the link
 *  - link_after: After the link
 *  - edit_text: Edit text
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic() To get the topic
 * @uses current_user_can() To check if the current user can edit the
 *                           topic
 * @uses bbp_get_topic_edit_url() To get the topic edit url
 * @uses apply_filters() Calls 'bbp_get_topic_edit_link' with the link
 *                        and args
 * @return string Topic edit link
 */
function bbp_get_topic_edit_link($args = '')
{
    $defaults = array('id' => 0, 'link_before' => '', 'link_after' => '', 'edit_text' => __('Edit', 'bbpress'));
    $r = bbp_parse_args($args, $defaults, 'get_topic_edit_link');
    extract($r);
    $topic = bbp_get_topic(bbp_get_topic_id((int) $id));
    // Bypass check if user has caps
    if (!current_user_can('edit_others_topics')) {
        // User cannot edit or it is past the lock time
        if (empty($topic) || !current_user_can('edit_topic', $topic->ID) || bbp_past_edit_lock($topic->post_date_gmt)) {
            return;
        }
    }
    // Get uri
    $uri = bbp_get_topic_edit_url($id);
    // Bail if no uri
    if (empty($uri)) {
        return;
    }
    $retval = $link_before . '<a href="' . $uri . '">' . $edit_text . '</a>' . $link_after;
    return apply_filters('bbp_get_topic_edit_link', $retval, $args);
}