function bcg_get_query() { $bp = buddypress(); $cats = bcg_get_categories($bp->groups->current_group->id); $qs = array('post_type' => bcg_get_post_type(), 'post_status' => 'publish'); if (empty($cats)) { $qs['name'] = -1; //we know it will not find anything } if (bcg_is_single_post()) { $slug = $bp->action_variables[0]; $qs['name'] = $slug; //tax query $qs['tax_query'] = array(array('taxonomy' => bcg_get_taxonomy(), 'terms' => $cats, 'field' => 'id', 'operator' => 'IN')); } $paged = get_query_var('paged') ? get_query_var('paged') : 1; if (bcg_is_category()) { $qs['tax_query'] = array(array('taxonomy' => bcg_get_taxonomy(), 'terms' => (int) bp_action_variable(1), 'field' => 'id', 'operator' => 'IN')); } else { $qs['tax_query'] = array(array('taxonomy' => bcg_get_taxonomy(), 'terms' => $cats, 'field' => 'id', 'operator' => 'IN')); } $qs['paged'] = $paged; return apply_filters("bcg_get_query", $qs); }
function bcg_show_post_form($group_id) { $bp = buddypress(); $cat_selected = bcg_get_categories($group_id); //selected cats if (empty($cat_selected)) { _e('This group has no associated categories. To post to Group blog, you need to associate some categoris to it.', 'bcg'); return; } $all_cats = (array) bcg_get_all_terms(); $all_cats = wp_list_pluck($all_cats, 'term_id'); $cats = array_diff($all_cats, $cat_selected); //for form $url = bp_get_group_permalink(new BP_Groups_Group($group_id)) . BCG_SLUG . "/create/"; if (function_exists('bp_get_simple_blog_post_form')) { $form = bp_get_simple_blog_post_form('bcg_form'); if ($form) { $form->show(); } } do_action('bcg_post_form', $cats, $url); //pass the categories as array and the url of the current page }
/** * register post form for Posting/editing * @return type */ public function register_form() { //make sure the Front end simple post plugin is active if (!function_exists('bp_new_simple_blog_post_form')) { return; } $post_status = 'draft'; $user_id = get_current_user_id(); $group_id = bp_get_current_group_id(); $settings = array('post_type' => bcg_get_post_type(), 'post_author' => $user_id, 'post_status' => $post_status, 'comment_status' => 'open', 'show_comment_option' => false, 'custom_field_title' => '', 'custom_fields' => array('_is_bcg_post' => array('type' => 'hidden', 'label' => '', 'default' => 1)), 'tax' => array(bcg_get_taxonomy() => array('include' => bcg_get_categories($group_id))), 'upload_count' => 3, 'has_post_thumbnail' => 1, 'current_user_can_post' => bcg_current_user_can_post(), 'update_callback' => array($this, 'on_save')); //use it to add extra fields or filter the post type etc $settings = apply_filters('bcg_form_args', $settings); $form = bp_new_simple_blog_post_form('bcg_form', $settings); }