/** * Creates the rewrites necessary so that the group is really where this stuff lives. * * @since 1.0.0 */ function narrative_permalink_filter($permalink, $post) { if ('group_story' == get_post_type($post)) { $group_id = ccgn_get_origin_group($post->ID); $permalink = ccgn_get_base_permalink($group_id) . $post->post_name; } return $permalink; }
function ccgn_create_activity_items($post_id) { $bp = buddypress(); // We want to fetch the saved post, because WP has done some filtering on save. $post_object = get_post($post_id); $author_id = (int) $post_object->post_author; $user_link = bp_core_get_userlink($author_id); $post_type_object = get_post_type_object($post_object->post_type); $post_type_label = strtolower($post_type_object->labels->singular_name); // A single narrative may be associated with more than one group $origin_group_id = ccgn_get_origin_group($post_id); $associated_groups = ccgn_get_associated_group_ids($post_id); $type = $post_object->post_type . '_created'; foreach ($associated_groups as $group_id) { // Does an activity item already exist? $exists = bp_activity_get_activity_id(array('component' => $bp->groups->id, 'type' => $type, 'item_id' => $group_id, 'secondary_item_id' => $post_id)); if (!empty($exists)) { continue; } // Create a post url that is relative to this group. $post_url = trailingslashit(ccgn_get_home_permalink($group_id)) . $post_object->post_name; $post_link = sprintf('<a href="%s">%s</a>', $post_url, $post_object->post_title); $group = groups_get_group(array('group_id' => $group_id)); $group_url = bp_get_group_permalink($group); $group_link = '<a href="' . $group_url . '">' . $group->name . '</a>'; // Only set hide_sitewide to false if this is the origin group and it is a public group. if ($group_id == $origin_group_id && 'public' == bp_get_group_status($group)) { $hide_sitewide = false; } else { $hide_sitewide = true; } $action = sprintf(__('%1$s published the %2$s %3$s in the Hub %4$s', 'cc-group-narratives'), $user_link, $post_type_label, $post_link, $group_link); $args = array('user_id' => $author_id, 'action' => $action, 'primary_link' => $post_link, 'component' => $bp->groups->id, 'type' => $type, 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post_object->post_date, 'hide_sitewide' => $hide_sitewide, 'content' => bp_create_excerpt($post_object->post_content, 358)); do_action($post_object->post_type . '_before_activity_save', $args); $activity_id = bp_activity_add(apply_filters($post_object->post_type . '_activity_args', $args, $post_id)); } }
function ccgn_edit_post_link() { //TODO: I think that the narrative should only be editable from within the group where it originated, so should only be editable by users who are "can_post" for that group. $post_id = get_the_ID(); if (ccgn_current_user_can_post($post_id)) { // Get the origin group $origin_group = ccgn_get_origin_group($post_id); // var_dump($post); echo '<a href="' . ccgn_get_home_permalink($origin_group) . '/edit/' . $post_id . '" class="button">Edit</a>'; } }