コード例 #1
0
/**
 * Helper function for checking if a user can read forums, topics, or replies. We need this to handle 
 * users who are not logged in but should have permission to read (e.g, non-private forums).  This 
 * function is meant to be used in conjunction with a filter on `map_meta_cap`.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $user_id
 * @param  string  $cap
 * @param  int     $post_id
 * @return bool
 */
function mb_user_can($user_id, $cap, $post_id)
{
    // @todo Check hierarchy.
    if (in_array($cap, array('read_forum', 'read_topic', 'read_reply'))) {
        if ('read_forum' === $cap) {
            $status_obj = get_post_status_object(mb_get_forum_status($post_id));
        } elseif ('read_topic' === $cap) {
            $status_obj = get_post_status_object(mb_get_topic_status($post_id));
        } elseif ('read_forum' === $cap) {
            $status_obj = get_post_status_object(mb_get_reply_status($post_id));
        }
        if (false === $status_obj->private && false === $status_obj->protected) {
            return true;
        }
    }
    return user_can($user_id, $cap, $post_id);
}
コード例 #2
0
/**
 * Generates the reply URL based on its position (`menu_order` field).
 *
 * @since  1.0.0
 * @access public
 * @param  int     $reply_id
 * @return string
 */
function mb_generate_reply_url($reply_id = 0)
{
    $reply_id = mb_get_reply_id($reply_id);
    /* If reply is not published, return empty string. */
    if (mb_get_publish_post_status() !== mb_get_reply_status($reply_id)) {
        return '';
    }
    $topic_id = mb_get_reply_topic_id($reply_id);
    /* If no topic ID, return empty string. */
    if (0 >= $topic_id) {
        return '';
    }
    /* Set up our variables. */
    $topic_url = get_permalink($topic_id);
    $per_page = mb_get_replies_per_page();
    $reply_position = mb_get_reply_position($reply_id);
    $reply_hash = "#post-{$reply_id}";
    $reply_page = ceil($reply_position / $per_page);
    /* If viewing page 1, just add the reply hash. */
    if (1 >= $reply_page) {
        $reply_url = user_trailingslashit($topic_url) . $reply_hash;
    } else {
        global $wp_rewrite;
        if ($wp_rewrite->using_permalinks()) {
            $reply_url = trailingslashit($topic_url) . trailingslashit($wp_rewrite->pagination_base) . user_trailingslashit($reply_page) . $reply_hash;
        } else {
            $reply_url = add_query_arg('paged', $reply_page, $topic_url) . $reply_hash;
        }
    }
    return $reply_url;
}
コード例 #3
0
/**
 * Conditional check to see whether a reply has the "orphan" post status.
 *
 * @since  1.0.0
 * @access public
 * @return bool
 */
function mb_is_reply_orphan($reply_id = 0)
{
    $reply_id = mb_get_reply_id($reply_id);
    $status = mb_get_reply_status($reply_id);
    return apply_filters('mb_is_reply_orphan', mb_get_orphan_post_status() === $status ? true : false, $reply_id);
}