Example #1
0
/**
 * Generate pagination links
 * 
 * @global type $wp_query
 */
function buddyblog_paginate()
{
    /// get total number of pages
    global $wp_query;
    $total = $wp_query->max_num_pages;
    // only bother with the rest if we have more than 1 page!
    if ($total > 1) {
        // get the current page
        if (!($current_page = get_query_var('paged'))) {
            $current_page = 1;
        }
        // structure of “format” depends on whether we’re using pretty permalinks
        $perma_struct = get_option('permalink_structure');
        $format = empty($perma_struct) ? '&page=%#%' : 'page/%#%/';
        $base = trailingslashit(buddyblog_get_home_url() . BUDDYBLOG_ARCHIVE_SLUG);
        // echo $base;
        if (bp_is_buddyblog_component()) {
            //$base = $base.'/';
        }
        echo paginate_links(array('base' => $base . '%_%', 'format' => $format, 'current' => $current_page, 'total' => $total, 'mid_size' => 4, 'type' => 'list'));
    }
}
Example #2
0
/**
 * Get the url for publishing/unpublishing the post
 * @param type $post_id
 * @return string 
 */
function buddyblog_get_post_publish_unpublish_url($post_id = false)
{
    if (!$post_id) {
        return;
    }
    $post = get_post($post_id);
    $url = '';
    if (buddyblog_user_can_publish(get_current_user_id(), $post_id)) {
        //check if post is published
        $url = buddyblog_get_home_url($post->post_author);
        if (buddyblog_is_post_published($post_id)) {
            $url = $url . 'unpublish/' . $post_id . '/';
        } else {
            $url = $url . 'publish/' . $post_id . '/';
        }
    }
    return $url;
}
Example #3
0
 /**
  * Unpublish a post
  */
 public function unpublish()
 {
     if (!(bp_is_buddyblog_component() && bp_is_current_action('unpublish'))) {
         return;
     }
     $id = bp_action_variable(0);
     if (!$id) {
         return;
     }
     if (buddyblog_user_can_unpublish(get_current_user_id(), $id)) {
         $post = get_post($id, ARRAY_A);
         $post['post_status'] = 'draft';
         wp_update_post($post);
         //unpublish
         bp_core_add_message(__('Post unpublished', 'buddyblog'));
     }
     bp_core_redirect(buddyblog_get_home_url());
 }