Index: bp-themes/bp-default/_inc/ajax.php
===================================================================
--- bp-themes/bp-default/_inc/ajax.php (revision 4326)
+++ bp-themes/bp-default/_inc/ajax.php (working copy)
@@ -53,8 +53,8 @@
if ( !empty( $_POST['page'] ) && '-1' != $_POST['page'] )
$qs[] = 'page=' . $_POST['page'];
- $object_search_text = bp_get_search_default_text( $object );
- if ( !empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
+ $object_search_text = bp_get_search_default_text( $object );
+ if ( !empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
$qs[] = 'search_terms=' . $_POST['search_terms'];
/* Now pass the querystring to override default values. */
@@ -246,21 +246,21 @@
if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) )
return false;
- $activity = new BP_Activity_Activity( $_POST['id'] );
+ $activity = new BP_Activity_Activity( (int) $_POST['id'] );
// Check access
- if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
+ if ( !is_super_admin() && ( $activity->user_id != bp_loggedin_user_id() ) )
return false;
// Call the action before the delete so plugins can still fetch information about it
- do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $activity->user_id );
+ do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );
- if ( !bp_activity_delete( array( 'id' => $_POST['id'], 'user_id' => $activity->user_id ) ) ) {
+ if ( !bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) ) {
echo '-1
' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '
';
return false;
}
- do_action( 'bp_activity_action_delete_activity', $_POST['id'], $activity->user_id );
+ do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
return true;
}
@@ -326,23 +326,23 @@
* @since 1.3
*/
function bp_dtheme_get_single_activity_content() {
- $activity_array = bp_activity_get_specific( array(
- 'activity_ids' => $_POST['activity_id'],
- 'display_comments' => 'stream'
+ $activity_array = bp_activity_get_specific( array(
+ 'activity_ids' => $_POST['activity_id'],
+ 'display_comments' => 'stream'
) );
-
+
$activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
-
+
if ( !$activity )
exit(); // todo: error?
-
+
// Activity content retrieved through AJAX should run through normal filters, but not be
// truncated
remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
$content = apply_filters( 'bp_get_activity_content_body', $activity->content );
-
+
echo $content;
-
+
exit();
}
add_action( 'wp_ajax_get_single_activity_content', 'bp_dtheme_get_single_activity_content' );
@@ -647,7 +647,7 @@
if ( !$ud )
continue;
- if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
+ if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
$username = $ud->user_login;
else
$username = $ud->user_nicename;
Index: bp-activity/bp-activity-actions.php
===================================================================
--- bp-activity/bp-activity-actions.php (revision 4326)
+++ bp-activity/bp-activity-actions.php (working copy)
@@ -63,26 +63,38 @@
}
add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
-function bp_activity_action_delete_activity() {
+/**
+ * bp_activity_action_delete_activity()
+ *
+ * Delete specific activity item and redirect to previous page.
+ *
+ * @global object $bp
+ * @since 1.1
+ * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted.
+ * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow actions to be taken before the activity is deleted.
+ */
+function bp_activity_action_delete_activity( $activity_id = 0 ) {
global $bp;
// Not viewing activity or action is not delete
- if ( ( $bp->activity->slug != bp_current_component() ) || !bp_is_current_action( 'delete' ) )
+ if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
return false;
+ if ( empty( $activity_id ) && !empty( $bp->action_variables[0] ) && is_numeric( $bp->action_variables[0] ) )
+ $activity_id = (int) $bp->action_variables[0];
+
// Not viewing a specific activity item
- if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
+ if ( empty( $activity_id ) )
return false;
// Check the nonce
check_admin_referer( 'bp_activity_delete_link' );
// Load up the activity item
- $activity_id = $bp->action_variables[0];
- $activity = new BP_Activity_Activity( $activity_id );
+ $activity = new BP_Activity_Activity( $activity_id );
// Check access
- if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
+ if ( empty( $activity->user_id ) || !is_super_admin() && $activity->user_id != bp_loggedin_user_id() )
return false;
// Call the action before the delete so plugins can still fetch information about it
@@ -90,14 +102,17 @@
// Delete the activity item and provide user feedback
if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
- bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
+ bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
else
bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
- // Redirect
- bp_core_redirect( wp_get_referer() );
+ // Check for the redirect query arg, otherwise let WP handle things
+ if ( !empty( $_GET['redirect_to'] ) )
+ bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
+ else
+ bp_core_redirect( wp_get_referer() );
}
add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
@@ -218,7 +233,7 @@
function bp_activity_action_sitewide_feed() {
global $bp, $wp_query;
-
+
if ( !bp_is_current_component( 'activity' ) || !bp_is_current_action( 'feed' ) || bp_is_user() || !empty( $bp->groups->current_group ) )
return false;
Index: bp-activity/bp-activity-template.php
===================================================================
--- bp-activity/bp-activity-template.php (revision 4326)
+++ bp-activity/bp-activity-template.php (working copy)
@@ -394,10 +394,10 @@
*/
function bp_activity_has_more_items() {
global $activities_template;
-
- $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
+
+ $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
$has_more_items = (int)$remaining_pages ? true : false;
-
+
return apply_filters( 'bp_activity_has_more_items', $has_more_items );
}
@@ -504,7 +504,7 @@
}
function bp_get_activity_user_link() {
global $activities_template;
-
+
if ( empty( $activities_template->activity->user_id ) )
$link = $activities_template->activity->primary_link;
else
@@ -722,13 +722,13 @@
if ( $bp->loggedin_user->is_super_admin )
$can_delete = true;
-
+
if ( $activities_template->activity->user_id == $bp->loggedin_user->id )
$can_delete = true;
-
+
if ( $bp->is_item_admin && $bp->is_single_item )
$can_delete = true;
-
+
return apply_filters( 'bp_activity_user_can_delete', $can_delete );
}
@@ -801,7 +801,7 @@
foreach ( (array)$comment->children as $comment_child ) {
// Put the comment into the global so it's available to filters
$activities_template->activity->current_comment = $comment_child;
-
+
if ( empty( $comment_child->user_fullname ) )
$comment_child->user_fullname = $comment_child->display_name;
@@ -853,7 +853,7 @@
$content .= bp_activity_recurse_comments( $comment_child );
$content .= '';
-
+
// Unset in the global in case of the last iteration
unset( $activities_template->activity->current_comment );
}
@@ -978,13 +978,42 @@
return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
}
+/**
+ * bp_activity_delete_link()
+ *
+ * Display the activity delete link.
+ *
+ * @since 1.1
+ * @uses bp_get_activity_delete_link()
+ */
function bp_activity_delete_link() {
echo bp_get_activity_delete_link();
}
+
+ /**
+ * bp_get_activity_delete_link()
+ *
+ * Return the activity delete link.
+ *
+ * @global object $activities_template BuddyPress Activities Template
+ * @global object $bp BuddyPress global settings
+ * @return string $link Activity delete link. Contains $redirect_to arg if on single activity page.
+ * @since 1.1
+ */
function bp_get_activity_delete_link() {
global $activities_template, $bp;
- return apply_filters( 'bp_get_activity_delete_link', '' . __( 'Delete', 'buddypress' ) . '' );
+ $url = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id;
+ $class = 'delete-activity';
+
+ // Determine if we're on a single activity page, and customize accordingly
+ if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
+ $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );
+ $class = 'delete-activity-single';
+ }
+
+ $link = '' . __( 'Delete', 'buddypress' ) . '';
+ return apply_filters( 'bp_get_activity_delete_link', $link );
}
function bp_activity_latest_update( $user_id = 0 ) {