/**
  * Add filter to catch removal of a story from a group
  *
  * @since    1.0.0
  */
 public function remove_story_from_group()
 {
     // Fires on bp_init action, so this is a catch-action type of filter.
     // Bail out if this isn't the narrative component.
     if (!ccgn_is_component()) {
         return false;
     }
     // Set up an array of BP's action variables
     $action_variables = bp_action_variables();
     //Handle delete actions: Removing story from group
     if (bp_is_action_variable('remove-story', 0)) {
         // Is the nonce good?
         if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ccgn-remove-story-from-group')) {
             return false;
         }
         // Parse the URI to create our necessary variables
         $post_id = bp_action_variable(1);
         // Is this user allowed to remove this item?
         if (!ccgn_current_user_can_moderate($post_id)) {
             return false;
         }
         // Get this group's term and disassociate it from the post
         if ($group_term_id = ccgn_get_group_term_id()) {
             $success = wp_remove_object_terms($post_id, $group_term_id, 'ccgn_related_groups');
         }
         // On successful removal, we should delete related activity items.
         if ($success) {
             if ($group_id = bp_get_current_group_id()) {
                 bp_activity_delete(array('component' => buddypress()->groups->id, 'type' => 'group_story_created', 'item_id' => $group_id, 'secondary_item_id' => $post_id));
             }
         }
         if ($success && !is_wp_error($success)) {
             bp_core_add_message(__('Successfully removed the item.', $this->plugin_slug));
         } else {
             bp_core_add_message(__('Could not remove the item.', $this->plugin_slug), 'error');
         }
         // Redirect and exit
         bp_core_redirect(wp_get_referer());
         return false;
     }
 }
Exemplo n.º 2
0
function ccgn_moderate_post_link()
{
    $post_id = get_the_ID();
    if (ccgn_current_user_can_moderate($post_id)) {
        echo '<a href="' . wp_nonce_url(ccgn_get_home_permalink() . '/remove-story/' . $post_id, 'ccgn-remove-story-from-group') . '" class="button confirm">' . __('Remove from hub', 'ccgn-remove-story-from-group') . '</a>';
    }
}