/** * Catches an activity to delete if js is enabled * * @package BP Reshare * @since 1.0 * * @uses check_ajax_referer() for security reasons * @uses bp_activity_get_specific() to fetch the activity to delete * @uses buddyreshare_reset_metas() to reset some metas for the parent activity * @uses bp_activity_delete() to delete the reshare */ function buddyreshare_ajax_delete_reshare() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('buddyreshare_delete', 'nonce'); $response = array('result' => 'error', 'message' => __('OOps, error while trying to delete your reshare..', 'bp-reshare')); $reshare_id = intval($_POST['activity']); if (empty($reshare_id)) { $response['message'] = __('The reshare was not found.', 'bp-reshare'); exit(json_encode($response)); } $reshare_to_delete = bp_activity_get_specific(array('activity_ids' => $reshare_id)); if (empty($reshare_to_delete)) { $response['message'] = __('The reshare was not found.', 'bp-reshare'); exit(json_encode($response)); } $reshare = $reshare_to_delete['activities'][0]; $reset = buddyreshare_reset_metas($reshare->secondary_item_id, $reshare->user_id); if (empty($reset)) { $response['message'] = __('Unable to reset the properties of the reshared activity', 'bp-reshare'); exit(json_encode($response)); } $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if (!empty($deleted_reshare)) { do_action('buddyreshare_reshare_deleted', $reshare_id); $response['result'] = 'success'; $response['message'] = __('Reshare successfully deleted.', 'bp-reshare'); } else { do_action('buddyreshare_reshare_deleted_error', $reshare_id); } exit(json_encode($response)); }
function bp_wire_delete_activity($args = true) { if (function_exists('bp_activity_delete')) { extract($args); bp_activity_delete($item_id, $component_name, $component_action, $user_id, $secondary_item_id); } }
/** * On deactivation, clear the cron and delete all group RSS activity. */ function bp_groupblogs_deactivate() { wp_clear_scheduled_hook('bp_groupblogs_cron'); /* Remove all external blog activity */ if (function_exists('bp_activity_delete')) { bp_activity_delete(array('type' => 'exb')); } }
function delete_pic_cover_group($activity_id) { global $bp; $group_id = $bp->groups->current_group->id; $activity_id = $_POST['activity_id']; $attachment_id = bp_activity_get_meta($activity_id, 'all_bp_cover_group', true); wp_delete_attachment($attachment_id, true); groups_delete_groupmeta($group_id, 'bp_cover_group'); groups_delete_groupmeta($group_id, 'bp_cover_group_position'); bp_activity_delete(array('id' => $activity_id, 'item_id' => $group_id)); BP_Activity_Activity::delete_activity_meta_entries($activity_id); }
function bp_reshare_ajax_delete_reshare() { check_ajax_referer('_reshare_delete', 'nonce'); $reshare_id = intval($_POST['activity']); $reshare_to_delete = bp_activity_get_specific('activity_ids=' . $reshare_id); $reshare = $reshare_to_delete['activities'][0]; bp_reshare_delete($reshare->secondary_item_id, $reshare->user_id); $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if ($deleted_reshare) { echo '1'; } else { _e('OOps, error while trying to delete your reshare..', 'bp-reshare'); } die; }
/** * let's delete reshare update if js is disabled */ function bp_reshare_delete_reshare() { if (!empty($_GET['delete_reshare']) && is_numeric($_GET['delete_reshare'])) { check_admin_referer('_reshare_delete'); $redirect = remove_query_arg(array('delete_reshare', '_wpnonce'), wp_get_referer()); $reshare_id = intval($_GET['delete_reshare']); $reshare_to_delete = bp_activity_get_specific('activity_ids=' . $reshare_id); $reshare = $reshare_to_delete['activities'][0]; bp_reshare_delete($reshare->secondary_item_id, $reshare->user_id); $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if (!empty($deleted_reshare)) { do_action('bp_reshare_handle_nojs_deleted', $reshare_id); bp_core_add_message(__('Reshare deleted !', 'bp-reshare')); bp_core_redirect($redirect); } else { do_action('bp_reshare_handle_nojs_missed', $reshare_id); bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } } }
/** * Remove all hidden friendship activities. * * @since 2.2.0 * * @uses bp_activity_delete() to delete the corresponding friendship activities. */ function bp_cleanup_friendship_activities() { bp_activity_delete(array('component' => buddypress()->friends->id, 'type' => 'friendship_created', 'hide_sitewide' => true)); }
/** * Remove a blog comment activity item from the activity stream. * * @param int $comment_id ID of the comment to be removed. */ function bp_blogs_remove_comment($comment_id) { global $wpdb; // activity comments are disabled for blog posts // which means that individual activity items exist for blog comments if (bp_disable_blogforum_comments()) { // Delete the individual activity stream item bp_blogs_delete_activity(array('item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment')); // activity comments are enabled for blog posts // remove the associated activity item } else { // get associated activity ID from comment meta $activity_id = get_comment_meta($comment_id, 'bp_activity_comment_id', true); // delete the associated activity comment // // also removes child post comments and associated activity comments if (!empty($activity_id) && bp_is_active('activity')) { // fetch the activity comments for the activity item $activity = bp_activity_get(array('in' => $activity_id, 'display_comments' => 'stream')); // get all activity comment IDs for the pending deleted item if (!empty($activity['activities'])) { $activity_ids = bp_activity_recurse_comments_activity_ids($activity); $activity_ids[] = $activity_id; // delete activity items foreach ($activity_ids as $activity_id) { bp_activity_delete(array('id' => $activity_id)); } // remove associated blog comments bp_blogs_remove_associated_blog_comments($activity_ids); // rebuild activity comment tree BP_Activity_Activity::rebuild_activity_comment_tree($activity['activities'][0]->item_id); } } } /** * Fires after a blog comment activity item was removed from activity stream. * * @since BuddyPress (1.0.0) * * @param int $blogid Item ID for the blog associated with the removed comment. * @param int $comment_id ID of the comment being removed. * @param int $value ID of the current logged in user. */ do_action('bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id()); }
/** * Delete an activity comment's children. * * @since BuddyPress (1.2.0) * * @uses BP_Activity_Activity::get_child_comments() {@link BP_Activity_Activity} * @uses bp_activity_delete_children() * @uses bp_activity_delete() * * @param int $activity_id The ID of the "root" activity, ie the * comment's oldest ancestor. * @param int $comment_id The ID of the comment to be deleted. */ function bp_activity_delete_children($activity_id, $comment_id) { // Get activity children to delete $children = BP_Activity_Activity::get_child_comments($comment_id); // Recursively delete all children of this comment. if (!empty($children)) { foreach ((array) $children as $child) { bp_activity_delete_children($activity_id, $child->id); } } // Delete the comment itself bp_activity_delete(array('secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id)); }
/** * Delete comment by activity id or media id */ function rtmedia_api_process_remove_comment_request() { global $wpdb; $this->rtmediajsonapifunction->rtmedia_api_verfiy_token(); $this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing(); //Errors Deleting comment $ec_comment_not_found = 800007; $msg_comment_not_found = __('invalid comment/media id', 'rtmedia'); $ec_no_comment_id = 800008; $msg_no_comment_id = __('no comment id', 'rtmedia'); $ec_comment_deleted = 800009; $msg_comment_deleted = __('comment deleted', 'rtmedia'); extract($_POST); if (empty($comment_id)) { echo $this->rtmedia_api_response_object('FALSE', $ec_no_comment_id, $msg_no_comment_id); exit; } $id = rtmedia_media_id($media_id); $sql = "SELECT * FROM {$wpdb->comments} WHERE comment_ID = " . $comment_id . " AND comment_post_ID = " . $id . " AND user_id = " . $this->user_id; $comments = $wpdb->get_results($sql, ARRAY_A); //Delete Comment if (!empty($comments)) { $comment = new RTMediaComment(); $activity_id = get_comment_meta($comment_id, 'activity_id', true); if (!empty($activity_id)) { $activity_deleted = bp_activity_delete_comment($activity_id, $comment_id); $delete = bp_activity_delete(array('id' => $activity_id, 'type' => 'activity_comment')); } $comment_deleted = $comment->rtmedia_comment_model->delete($comment_id); if ($comment_deleted) { echo $this->rtmedia_api_response_object('TRUE', $ec_comment_deleted, $msg_comment_deleted); exit; } else { echo $this->rtmedia_api_response_object('FALSE', $this->ec_server_error, $this->msg_server_error); exit; } } else { echo $this->rtmedia_api_response_object('FALSE', $ec_comment_not_found, $msg_comment_not_found); exit; } }
function bebop_manage_oers() { if (bp_is_current_component('bebop') && bp_is_current_action('bebop-manager')) { if (isset($_POST['action'])) { global $wpdb; global $bp; $oer_count = 0; $success = false; //Add OER's to the activity stream. if ($_POST['action'] == 'verify') { foreach (array_keys($_POST) as $oer) { if ($oer != 'action') { $data = bebop_tables::fetch_individual_oer_data($oer); //go and fetch data from the activity buffer table. if (!empty($data->id)) { $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $data->type . '_content_user_verification'); if ($should_users_verify_content != 'no') { global $wpdb; if (!bp_has_activities('action=bebop_oer_plugin&item_id=' . $data->id)) { $new_activity_item = array('user_id' => $data->user_id, 'component' => 'bebop_oer_plugin', 'type' => $data->type, 'action' => $data->action, 'content' => $data->content, 'item_id' => $data->id, 'date_recorded' => $data->date_recorded, 'hide_sitewide' => $data->hide_sitewide); if (bp_activity_add($new_activity_item)) { bebop_tables::update_oer_data($data->id, 'status', 'verified'); bebop_tables::update_oer_data($data->id, 'activity_stream_id', $wpdb->insert_id); $oer_count++; } else { bebop_tables::log_error(__('Activity Stream', 'bebop'), __('Could not update the content status.', 'bebop')); } } else { bebop_tables::log_error(__('Activity Stream', 'bebop'), __('This content already exists in the activity stream.', 'bebop')); } } //End if ( $should_users_verify_content != 'no' ) { } } } //End foreach ( array_keys($_POST) as $oer ) { if ($oer_count > 1) { $success = true; $message = __('Resources verified.', 'bebop'); } else { $success = true; $message = __('Resource verified.', 'bebop'); } } else { if ($_POST['action'] == 'delete') { foreach (array_keys($_POST) as $oer) { if ($oer != 'action') { $data = bebop_tables::fetch_individual_oer_data($oer); //go and fetch data from the activity buffer table. if (!empty($data->id)) { //delete the activity, let the filter update the tables. if (!empty($data->activity_stream_id)) { $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $data->type . '_content_user_verification'); if ($should_users_verify_content != 'no') { bp_activity_delete(array('id' => $data->activity_stream_id)); } } bebop_tables::update_oer_data($data->id, 'status', 'deleted'); $oer_count++; } } } //End foreach ( array_keys( $_POST ) as $oer ) { if ($oer_count > 1) { $success = true; $message = __('Resources deleted.', 'bebop'); } else { $success = true; $message = __('Resource deleted.', 'bebop'); } } else { if ($_POST['action'] == 'undelete') { foreach (array_keys($_POST) as $oer) { $exclude_array = array('action', 'submit'); if (!in_array($oer, $exclude_array)) { $data = bebop_tables::fetch_individual_oer_data($oer); //go and fetch data from the activity buffer table. $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $data->type . '_content_user_verification'); if ($should_users_verify_content != 'no') { bebop_tables::update_oer_data($data->id, 'status', 'unverified'); $oer_count++; } } } if ($oer_count > 1) { $success = true; $message = __('Resources undeleted.', 'bebop'); } else { $success = true; $message = __('Resource undeleted.', 'bebop'); } } } } if ($success) { bp_core_add_message($message); } else { bp_core_add_message(__('We couldnt do that for you. Please try again.', 'bebop'), __('error', 'bebop')); } bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action()); } //End if ( isset( $_POST['action'] ) ) { } //End if ( bp_is_current_component( 'bebop' ) && bp_is_current_action('bebop-manager' ) ) { add_action('wp_enqueue_scripts', 'bebop_oer_js'); //enqueue selectall/none script }
/** * Set up the Activity admin page. * * Does the following: * - Register contextual help and screen options for this admin page. * - Enqueues scripts and styles. * - Catches POST and GET requests related to Activity. * * @since BuddyPress (1.6.0) * * @global object $bp BuddyPress global settings. * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table. */ function bp_activity_admin_load() { global $bp_activity_list_table; $bp = buddypress(); // Decide whether to load the dev version of the CSS and JavaScript $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : 'min.'; $doaction = bp_admin_list_table_current_bulk_action(); /** * Fires at top of Activity admin page. * * @since BuddyPress (1.6.0) * * @param string $doaction Current $_GET action being performed in admin screen. */ do_action('bp_activity_admin_load', $doaction); // Edit screen if ('edit' == $doaction && !empty($_GET['aid'])) { // columns screen option add_screen_option('layout_columns', array('default' => 2, 'max' => 2)); get_current_screen()->add_help_tab(array('id' => 'bp-activity-edit-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You edit activities made on your site similar to the way you edit a comment. This is useful if you need to change which page the activity links to, or when you notice that the author has made a typographical error.', 'buddypress') . '</p>' . '<p>' . __('The two big editing areas for the activity title and content are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Primary Item/Secondary Item, Link, Type, Author ID) or to choose a 1- or 2-column layout for this screen.', 'buddypress') . '</p>' . '<p>' . __('You can also moderate the activity from this screen using the Status box, where you can also change the timestamp of the activity.', 'buddypress') . '</p>')); get_current_screen()->add_help_tab(array('id' => 'bp-activity-edit-advanced', 'title' => __('Item, Link, Type', 'buddypress'), 'content' => '<p>' . __('<strong>Primary Item/Secondary Item</strong> - These identify the object that created the activity. For example, the fields could reference a comment left on a specific site. Some types of activity may only use one, or none, of these fields.', 'buddypress') . '</p>' . '<p>' . __('<strong>Link</strong> - Used by some types of activity (e.g blog posts and comments, and forum topics and replies) to store a link back to the original content.', 'buddypress') . '</p>' . '<p>' . __('<strong>Type</strong> - Each distinct kind of activity has its own type. For example, <code>created_group</code> is used when a group is created and <code>joined_group</code> is used when a user joins a group.', 'buddypress') . '</p>' . '<p>' . __('For information about when and how BuddyPress uses all of these settings, see the Managing Activity link in the panel to the side.', 'buddypress') . '</p>')); // Help panel - sidebar links get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://codex.buddypress.org/administrator-guide/activity-stream-management-panels/">Managing Activity</a>', 'buddypress') . '</p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>'); // Register metaboxes for the edit screen. add_meta_box('submitdiv', _x('Status', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_status', get_current_screen()->id, 'side', 'core'); add_meta_box('bp_activity_itemids', _x('Primary Item/Secondary Item', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_itemids', get_current_screen()->id, 'normal', 'core'); add_meta_box('bp_activity_link', _x('Link', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_link', get_current_screen()->id, 'normal', 'core'); add_meta_box('bp_activity_type', _x('Type', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_type', get_current_screen()->id, 'normal', 'core'); add_meta_box('bp_activity_userid', _x('Author ID', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_userid', get_current_screen()->id, 'normal', 'core'); // Enqueue JavaScript files wp_enqueue_script('postbox'); wp_enqueue_script('dashboard'); wp_enqueue_script('comment'); // Index screen } else { // Create the Activity screen list table $bp_activity_list_table = new BP_Activity_List_Table(); // per_page screen option add_screen_option('per_page', array('label' => _x('Activity', 'Activity items per page (screen options)', 'buddypress'))); // Help panel - overview text get_current_screen()->add_help_tab(array('id' => 'bp-activity-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You can manage activities made on your site similar to the way you manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on activities using the on-hover action links or the Bulk Actions.', 'buddypress') . '</p>' . '<p>' . __('There are many different types of activities. Some are generated automatically by BuddyPress and other plugins, and some are entered directly by a user in the form of status update. To help manage the different activity types, use the filter dropdown box to switch between them.', 'buddypress') . '</p>')); // Help panel - moderation text get_current_screen()->add_help_tab(array('id' => 'bp-activity-moderating', 'title' => __('Moderating Activity', 'buddypress'), 'content' => '<p>' . __('In the <strong>Activity</strong> column, above each activity it says “Submitted on,” followed by the date and time the activity item was generated on your site. Clicking on the date/time link will take you to that activity on your live site. Hovering over any activity gives you options to reply, edit, spam mark, or delete that activity.', 'buddypress') . '</p>' . '<p>' . __("In the <strong>In Response To</strong> column, if the activity was in reply to another activity, it shows that activity's author's picture and name, and a link to that activity on your live site. If there is a small bubble, the number in it shows how many other activities are related to this one; these are usually comments. Clicking the bubble will filter the activity screen to show only related activity items.", 'buddypress') . '</p>')); // Help panel - sidebar links get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>'); } // Enqueue CSS and JavaScript wp_enqueue_script('bp_activity_admin_js', $bp->plugin_url . "bp-activity/admin/js/admin.{$min}js", array('jquery', 'wp-ajax-response'), bp_get_version(), true); wp_localize_script('bp_activity_admin_js', 'bp_activity_admin_vars', array('page' => get_current_screen()->id)); wp_enqueue_style('bp_activity_admin_css', $bp->plugin_url . "bp-activity/admin/css/admin.{$min}css", array(), bp_get_version()); wp_style_add_data('bp_activity_admin_css', 'rtl', true); if ($min) { wp_style_add_data('bp_activity_admin_css', 'suffix', $min); } // Handle spam/un-spam/delete of activities if (!empty($doaction) && !in_array($doaction, array('-1', 'edit', 'save'))) { // Build redirection URL $redirect_to = remove_query_arg(array('aid', 'deleted', 'error', 'spammed', 'unspammed'), wp_get_referer()); $redirect_to = add_query_arg('paged', $bp_activity_list_table->get_pagenum(), $redirect_to); // Get activity IDs $activity_ids = array_map('absint', (array) $_REQUEST['aid']); /** * Filters list of IDs being spammed/un-spammed/deleted. * * @since BuddyPress (1.6.0) * * @param array $activity_ids Activity IDs to spam/un-spam/delete. */ $activity_ids = apply_filters('bp_activity_admin_action_activity_ids', $activity_ids); // Is this a bulk request? if ('bulk_' == substr($doaction, 0, 5) && !empty($_REQUEST['aid'])) { // Check this is a valid form submission check_admin_referer('bulk-activities'); // Trim 'bulk_' off the action name to avoid duplicating a ton of code $doaction = substr($doaction, 5); // This is a request to delete, spam, or un-spam, a single item. } elseif (!empty($_REQUEST['aid'])) { // Check this is a valid form submission check_admin_referer('spam-activity_' . $activity_ids[0]); } // Initialise counters for how many of each type of item we perform an action on $deleted = $spammed = $unspammed = 0; // Store any errors that occurs when updating the database items $errors = array(); // "We'd like to shoot the monster, could you move, please?" foreach ($activity_ids as $activity_id) { // @todo: Check the permissions on each //if ( ! current_user_can( 'bp_edit_activity', $activity_id ) ) // continue; // Get the activity from the database $activity = new BP_Activity_Activity($activity_id); if (empty($activity->component)) { $errors[] = $activity_id; continue; } switch ($doaction) { case 'delete': if ('activity_comment' == $activity->type) { bp_activity_delete_comment($activity->item_id, $activity->id); } else { bp_activity_delete(array('id' => $activity->id)); } $deleted++; break; case 'ham': /** * Remove moderation and blacklist checks in case we want to ham an activity * which contains one of these listed keys. */ remove_action('bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1); remove_action('bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1); bp_activity_mark_as_ham($activity); $result = $activity->save(); // Check for any error during activity save if (!$result) { $errors[] = $activity->id; } else { $unspammed++; } break; case 'spam': bp_activity_mark_as_spam($activity); $result = $activity->save(); // Check for any error during activity save if (!$result) { $errors[] = $activity->id; } else { $spammed++; } break; default: break; } // Release memory unset($activity); } /** * Fires before redirect for plugins to do something with activity. * * Passes an activity array counts how many were spam, not spam, deleted, and IDs that were errors. * * @since BuddyPress (1.6.0) * * @param array $value Array holding spam, not spam, deleted counts, error IDs. * @param string $redirect_to URL to redirect to. * @param array $activity_ids Original array of activity IDs. */ do_action('bp_activity_admin_action_after', array($spammed, $unspammed, $deleted, $errors), $redirect_to, $activity_ids); // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done. if ($spammed) { $redirect_to = add_query_arg('spammed', $spammed, $redirect_to); } if ($unspammed) { $redirect_to = add_query_arg('unspammed', $unspammed, $redirect_to); } if ($deleted) { $redirect_to = add_query_arg('deleted', $deleted, $redirect_to); } // If an error occurred, pass back the activity ID that failed if (!empty($errors)) { $redirect_to = add_query_arg('error', implode(',', array_map('absint', $errors)), $redirect_to); } /** * Filters redirect URL after activity spamming/un-spamming/deletion occurs. * * @since BuddyPress (1.6.0) * * @param string $redirect_to URL to redirect to. */ wp_redirect(apply_filters('bp_activity_admin_action_redirect', $redirect_to)); exit; // Save the edit } elseif ($doaction && 'save' == $doaction) { // Build redirection URL $redirect_to = remove_query_arg(array('action', 'aid', 'deleted', 'error', 'spammed', 'unspammed'), $_SERVER['REQUEST_URI']); // Get activity ID $activity_id = (int) $_REQUEST['aid']; // Check this is a valid form submission check_admin_referer('edit-activity_' . $activity_id); // Get the activity from the database $activity = new BP_Activity_Activity($activity_id); // If the activity doesn't exist, just redirect back to the index if (empty($activity->component)) { wp_redirect($redirect_to); exit; } // Check the form for the updated properties // Store any error that occurs when updating the database item $error = 0; // Activity spam status $prev_spam_status = $new_spam_status = false; if (!empty($_POST['activity_status'])) { $prev_spam_status = $activity->is_spam; $new_spam_status = 'spam' == $_POST['activity_status'] ? true : false; } // Activity action if (isset($_POST['bp-activities-action'])) { $activity->action = $_POST['bp-activities-action']; } // Activity content if (isset($_POST['bp-activities-content'])) { $activity->content = $_POST['bp-activities-content']; } // Activity primary link if (!empty($_POST['bp-activities-link'])) { $activity->primary_link = $_POST['bp-activities-link']; } // Activity user ID if (!empty($_POST['bp-activities-userid'])) { $activity->user_id = (int) $_POST['bp-activities-userid']; } // Activity item primary ID if (isset($_POST['bp-activities-primaryid'])) { $activity->item_id = (int) $_POST['bp-activities-primaryid']; } // Activity item secondary ID if (isset($_POST['bp-activities-secondaryid'])) { $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid']; } // Activity type if (!empty($_POST['bp-activities-type'])) { $actions = bp_activity_admin_get_activity_actions(); // Check that the new type is a registered activity type if (in_array($_POST['bp-activities-type'], $actions)) { $activity->type = $_POST['bp-activities-type']; } } // Activity timestamp if (!empty($_POST['aa']) && !empty($_POST['mm']) && !empty($_POST['jj']) && !empty($_POST['hh']) && !empty($_POST['mn']) && !empty($_POST['ss'])) { $aa = $_POST['aa']; $mm = $_POST['mm']; $jj = $_POST['jj']; $hh = $_POST['hh']; $mn = $_POST['mn']; $ss = $_POST['ss']; $aa = $aa <= 0 ? date('Y') : $aa; $mm = $mm <= 0 ? date('n') : $mm; $jj = $jj > 31 ? 31 : $jj; $jj = $jj <= 0 ? date('j') : $jj; $hh = $hh > 23 ? $hh - 24 : $hh; $mn = $mn > 59 ? $mn - 60 : $mn; $ss = $ss > 59 ? $ss - 60 : $ss; // Reconstruct the date into a timestamp $gmt_date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss); $activity->date_recorded = $gmt_date; } // Has the spam status has changed? if ($new_spam_status != $prev_spam_status) { if ($new_spam_status) { bp_activity_mark_as_spam($activity); } else { bp_activity_mark_as_ham($activity); } } // Save $result = $activity->save(); // Clear the activity stream first page cache, in case this activity's timestamp was changed wp_cache_delete('bp_activity_sitewide_front', 'bp'); // Check for any error during activity save if (false === $result) { $error = $activity->id; } /** * Fires before redirect so plugins can do something first on save action. * * @since BuddyPress (1.6.0) * * @param array Array holding activity object and ID that holds error. */ do_action_ref_array('bp_activity_admin_edit_after', array(&$activity, $error)); // If an error occurred, pass back the activity ID that failed if ($error) { $redirect_to = add_query_arg('error', (int) $error, $redirect_to); } else { $redirect_to = add_query_arg('updated', (int) $activity->id, $redirect_to); } /** * Filters URL to redirect to after saving. * * @since BuddyPress (1.6.0) * * @param string $redirect_to URL to redirect to. */ wp_redirect(apply_filters('bp_activity_admin_edit_redirect', $redirect_to)); exit; // If a referrer and a nonce is supplied, but no action, redirect back. } elseif (!empty($_GET['_wp_http_referer'])) { wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']))); exit; } }
/** * @group bp_notifications_delete_all_notifications_by_type * @group bp_activity_at_mention_delete_notification */ public function test_bp_activity_at_mention_delete_notification() { $this->create_notifications(); $notifications = BP_Notifications_Notification::get(array('item_id' => $this->a1)); // Double check it's there $this->assertEquals(array($this->a1), wp_list_pluck($notifications, 'item_id')); bp_activity_delete(array('id' => $this->a1)); $notifications = BP_Notifications_Notification::get(array('item_id' => $this->a1)); $this->assertEmpty($notifications); }
/** * Deletes friendship activity items when a user is deleted. * * @since 2.5.0 * * @param int $user_id The ID of the user being deleted. */ function bp_friends_delete_activity_on_user_delete($user_id = 0) { if (!bp_is_active('activity')) { return; } bp_activity_delete(array('component' => buddypress()->friends->id, 'type' => 'friendship_created', 'secondary_item_id' => $user_id)); }
/** * Deletes an Activity item received via a POST request. * * @return mixed String on error, void on success * @since BuddyPress (1.2) */ function bp_legacy_theme_delete_activity() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } // Check the nonce check_admin_referer('bp_activity_delete_link'); if (!is_user_logged_in()) { exit('-1'); } if (empty($_POST['id']) || !is_numeric($_POST['id'])) { exit('-1'); } $activity = new BP_Activity_Activity((int) $_POST['id']); // Check access if (!bp_activity_user_can_delete($activity)) { exit('-1'); } /** This action is documented in bp-activity/bp-activity-actions.php */ do_action('bp_activity_before_action_delete_activity', $activity->id, $activity->user_id); if (!bp_activity_delete(array('id' => $activity->id, 'user_id' => $activity->user_id))) { exit('-1<div id="message" class="error bp-ajax-message"><p>' . __('There was a problem when deleting. Please try again.', 'buddypress') . '</p></div>'); } /** This action is documented in bp-activity/bp-activity-actions.php */ do_action('bp_activity_action_delete_activity', $activity->id, $activity->user_id); exit; }
/** * Delete a group forum post and its corresponding activity item. * * Uses the bundled version of bbPress packaged with BuddyPress. * * @since BuddyPress (1.1.0) * * @param int $post_id The ID of the post you want to delete. * @param int $topic_id Optional. The topic to which the post belongs. This * value isn't used in the function but is passed along to do_action() * hooks. * @return bool True on success. */ function groups_delete_group_forum_post($post_id, $topic_id = false) { $action = bp_forums_delete_post(array('post_id' => $post_id)); if (!empty($action)) { do_action('groups_before_delete_group_forum_post', $post_id, $topic_id); // Delete the corresponding activity stream item if (bp_is_active('activity')) { bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id, 'component' => buddypress()->groups->id, 'type' => 'new_forum_post')); } do_action('groups_delete_group_forum_post', $post_id, $topic_id); } return (bool) $action; }
/** * Delete specific activity item and redirect to previous page. * * @since 1.1.0 * * @uses bp_is_activity_component() * @uses bp_is_current_action() * @uses bp_action_variable() * @uses check_admin_referer() * @uses bp_activity_user_can_delete() * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow actions to be taken before the activity is deleted. * @uses bp_activity_delete() * @uses bp_core_add_message() * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted. * @uses bp_core_redirect() * * @param int $activity_id Activity id to be deleted. Defaults to 0. * @return bool False on failure. */ function bp_activity_action_delete_activity($activity_id = 0) { // Not viewing activity or action is not delete. if (!bp_is_activity_component() || !bp_is_current_action('delete')) { return false; } if (empty($activity_id) && bp_action_variable(0)) { $activity_id = (int) bp_action_variable(0); } // Not viewing a specific activity item. if (empty($activity_id)) { return false; } // Check the nonce. check_admin_referer('bp_activity_delete_link'); // Load up the activity item. $activity = new BP_Activity_Activity($activity_id); // Check access. if (!bp_activity_user_can_delete($activity)) { return false; } /** * Fires before the deletion so plugins can still fetch information about it. * * @since 1.5.0 * * @param int $activity_id The activity ID. * @param int $user_id The user associated with the activity. */ do_action('bp_activity_before_action_delete_activity', $activity_id, $activity->user_id); // 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 successfully', 'buddypress')); } else { bp_core_add_message(__('There was an error when deleting that activity', 'buddypress'), 'error'); } /** * Fires after the deletion so plugins can act afterwards based on the activity. * * @since 1.1.0 * * @param int $activity_id The activity ID. * @param int $user_id The user associated with the activity. */ do_action('bp_activity_action_delete_activity', $activity_id, $activity->user_id); // 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()); } }
/** * bp_like_remove_user_like() * * Registers that the user has unliked a given item. * */ function bp_like_remove_user_like($item_id = '', $type = 'activity') { global $bp; if (!$item_id) { return false; } if (!isset($user_id)) { $user_id = $bp->loggedin_user->id; } if ($user_id == 0) { echo bp_like_get_text('must_be_logged_in'); return false; } if ($type == 'activity') { /* Remove this from the users liked activities. */ $user_likes = get_user_meta($user_id, 'bp_liked_activities', true); unset($user_likes[$item_id]); update_user_meta($user_id, 'bp_liked_activities', $user_likes); /* Update the total number of users who have liked this activity. */ $users_who_like = bp_activity_get_meta($item_id, 'liked_count', true); unset($users_who_like[$user_id]); /* If nobody likes the activity, delete the meta for it to save space, otherwise, update the meta */ if (empty($users_who_like)) { bp_activity_delete_meta($item_id, 'liked_count'); } else { bp_activity_update_meta($item_id, 'liked_count', $users_who_like); } $liked_count = count($users_who_like); /* Remove the update on the users profile from when they liked the activity. */ $update_id = bp_activity_get_activity_id(array('item_id' => $item_id, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id)); bp_activity_delete(array('id' => $update_id, 'item_id' => $item_id, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id)); } elseif ($type == 'blogpost') { /* Remove this from the users liked activities. */ $user_likes = get_user_meta($user_id, 'bp_liked_blogposts', true); unset($user_likes[$item_id]); update_user_meta($user_id, 'bp_liked_blogposts', $user_likes); /* Update the total number of users who have liked this blog post. */ $users_who_like = get_post_meta($item_id, 'liked_count', true); unset($users_who_like[$user_id]); /* If nobody likes the blog post, delete the meta for it to save space, otherwise, update the meta */ if (empty($users_who_like)) { delete_post_meta($item_id, 'liked_count'); } else { update_post_meta($item_id, 'liked_count', $users_who_like); } $liked_count = count($users_who_like); /* Remove the update on the users profile from when they liked the activity. */ $update_id = bp_activity_get_activity_id(array('item_id' => $item_id, 'component' => 'bp-like', 'type' => 'blogpost_liked', 'user_id' => $user_id)); bp_activity_delete(array('id' => $update_id, 'item_id' => $item_id, 'component' => 'bp-like', 'type' => 'blogpost_liked', 'user_id' => $user_id)); } echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } }
/** * bp_zoneideas_delete_activity() * * If the activity stream component is installed, this function will delete activity items for your * component. * * You should use this when items are deleted, to keep the activity stream in sync. For zoneideas if a user * publishes a new blog post, it would record it in the activity stream. However, if they then make it private * or they delete it. You'll want to remove it from the activity stream, otherwise you will get out of sync and * bad links. */ function bp_zoneideas_delete_activity($args) { if (function_exists('bp_activity_delete')) { extract((array) $args); bp_activity_delete($item_id, $component_name, $component_action, $user_id, $secondary_item_id); } }
/** * Delete specific activity item and redirect to previous page. * * @since BuddyPress (1.1) * * @param int $activity_id Activity id to be deleted. Defaults to 0. * * @uses bp_is_activity_component() * @uses bp_is_current_action() * @uses bp_action_variable() * @uses check_admin_referer() * @uses bp_activity_user_can_delete() * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow actions to be taken before the activity is deleted. * @uses bp_activity_delete() * @uses bp_core_add_message() * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted. * @uses bp_core_redirect() * * @return bool False on failure. */ function bp_activity_action_delete_activity($activity_id = 0) { // Not viewing activity or action is not delete if (!bp_is_activity_component() || !bp_is_current_action('delete')) { return false; } if (empty($activity_id) && bp_action_variable(0)) { $activity_id = (int) bp_action_variable(0); } // Not viewing a specific activity item if (empty($activity_id)) { return false; } // Check the nonce check_admin_referer('bp_activity_delete_link'); // Load up the activity item $activity = new BP_Activity_Activity($activity_id); // Check access if (!bp_activity_user_can_delete($activity)) { return false; } // Call the action before the delete so plugins can still fetch information about it do_action('bp_activity_before_action_delete_activity', $activity_id, $activity->user_id); // 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 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); // 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()); } }
/** * Deletes an Activity item received via a POST request. * * @return mixed String on error, void on success * @since BuddyPress (1.2) */ function bp_dtheme_delete_activity() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } // Check the nonce check_admin_referer('bp_activity_delete_link'); if (!is_user_logged_in()) { exit('-1'); } if (empty($_POST['id']) || !is_numeric($_POST['id'])) { exit('-1'); } $activity = new BP_Activity_Activity((int) $_POST['id']); // Check access if (empty($activity->user_id) || !bp_activity_user_can_delete($activity)) { exit('-1'); } // Call the action before the delete so plugins can still fetch information about it do_action('bp_activity_before_action_delete_activity', $activity->id, $activity->user_id); if (!bp_activity_delete(array('id' => $activity->id, 'user_id' => $activity->user_id))) { exit('-1<div id="message" class="error"><p>' . __('There was a problem when deleting. Please try again.', 'logicalboneshug') . '</p></div>'); } do_action('bp_activity_action_delete_activity', $activity->id, $activity->user_id); exit; }
function groups_leave_group($group_id, $user_id = 0) { global $bp; if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } // Don't let single admins leave the group. if (count(groups_get_group_admins($group_id)) < 2) { if (groups_is_user_admin($user_id, $group_id)) { bp_core_add_message(__('As the only Admin, you cannot leave the group.', 'buddypress'), 'error'); return false; } } $membership = new BP_Groups_Member($user_id, $group_id); // This is exactly the same as deleting an invite, just is_confirmed = 1 NOT 0. if (!groups_uninvite_user($user_id, $group_id)) { return false; } /** * If the user joined this group less than five minutes ago, remove the * joined_group activity so users cannot flood the activity stream by * joining/leaving the group in quick succession. */ if (bp_is_active('activity') && gmmktime() <= strtotime('+5 minutes', (int) strtotime($membership->date_modified))) { bp_activity_delete(array('component' => $bp->groups->id, 'type' => 'joined_group', 'user_id' => $user_id, 'item_id' => $group_id)); } bp_core_add_message(__('You successfully left the group.', 'buddypress')); do_action('groups_leave_group', $group_id, $user_id); return true; }
function bp_checkins_delete_all_checkins_activities() { bp_activity_delete(array('component' => 'groups', 'type' => 'new_place')); bp_activity_delete(array('component' => 'groups', 'type' => 'place_comment')); bp_activity_delete(array('component' => 'groups', 'type' => 'place_checkin')); bp_activity_delete(array('component' => 'groups', 'type' => 'activity_checkin')); bp_activity_delete(array('component' => 'places')); bp_activity_delete(array('component' => 'checkins')); }
/** * Save method for our extension during edits. * * @param int $group_id The group ID. */ public function edit_screen_save($group_id = null) { if (!isset($_POST['save'])) { return false; } check_admin_referer('groups_edit_save_' . $this->slug); $existing_feeds = (array) groups_get_groupmeta(bp_get_current_group_id(), 'blogfeeds'); $unfiltered_feeds = explode(',', $_POST['blogfeeds']); $blog_feeds = array(); foreach ((array) $unfiltered_feeds as $blog_feed) { if (!empty($blog_feed)) { $blog_feeds[] = esc_url_raw(trim($blog_feed)); } } /* Loop and find any feeds that have been removed, so we can delete activity stream items */ if (!empty($existing_feeds)) { foreach ((array) $existing_feeds as $feed) { if (!in_array($feed, (array) $blog_feeds)) { $removed[] = $feed; } } } if ($removed) { foreach ((array) $removed as $feed) { $existing = bp_activity_get(array('user_id' => false, 'component' => 'groups', 'type' => 'exb', 'item_id' => bp_get_current_group_id(), 'update_meta_cache' => false, 'display_comments' => false, 'meta_query' => array(array('key' => 'exb_feedurl', 'value' => trim($feed))))); // only delete items matching the feed if (!empty($existing['activities'])) { $aids = wp_list_pluck($existing['activities'], 'id'); foreach ($aids as $aid) { bp_activity_delete(array('id' => $aid)); } // old way - delete all feed items matching the group } else { bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'component' => 'groups', 'type' => 'exb')); } } } groups_update_groupmeta(bp_get_current_group_id(), 'fetchtime', $_POST['fetch-time']); groups_update_groupmeta(bp_get_current_group_id(), 'blogfeeds', $blog_feeds); groups_update_groupmeta(bp_get_current_group_id(), 'bp_groupblogs_lastupdate', gmdate("Y-m-d H:i:s")); /* Re-fetch */ bp_groupblogs_fetch_group_feeds(bp_get_current_group_id()); bp_core_add_message(__('External blog feeds updated successfully!', 'bp-groups-externalblogs')); bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . '/admin/' . $this->slug); }
function check_delete_comments() { global $rtmedia_query; if ($rtmedia_query->action_query->action != 'delete-comment') { return; } if (count($_POST)) { /** * /media/id/delete-comment [POST] * Delete Comment by Comment ID */ if (empty($_POST['comment_id'])) { return false; } $comment = new RTMediaComment(); $id = $_POST['comment_id']; $activity_id = get_comment_meta($id, 'activity_id', true); if (!empty($activity_id)) { if (function_exists('bp_activity_delete_comment')) { //if buddypress is active $activity_deleted = bp_activity_delete_comment($activity_id, $id); $delete = bp_activity_delete(array('id' => $activity_id, 'type' => 'activity_comment')); } } $comment_deleted = $comment->remove($id); echo $comment_deleted; exit; } }
/** * Delete a group forum post and its corresponding activity item. * * Uses the bundled version of bbPress packaged with BuddyPress. * * @since BuddyPress (1.1.0) * * @param int $post_id The ID of the post you want to delete. * @param int|bool $topic_id Optional. The topic to which the post belongs. This * value isn't used in the function but is passed along * to do_action() hooks. * * @return bool True on success. */ function groups_delete_group_forum_post($post_id, $topic_id = false) { $action = bp_forums_delete_post(array('post_id' => $post_id)); if (!empty($action)) { /** * Fires before the deletion of a group forum post. * * @since BuddyPress (1.5.0) * * @param int $post_id ID of the post to be deleted. * @param int $topic_id ID of the associated topic. */ do_action('groups_before_delete_group_forum_post', $post_id, $topic_id); // Delete the corresponding activity stream item if (bp_is_active('activity')) { bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id, 'component' => buddypress()->groups->id, 'type' => 'new_forum_post')); } /** * Fires after the deletion of a group forum post. * * @since BuddyPress (1.1.0) * * @param int $post_id ID of the post that was deleted. * @param int $topic_id ID of the associated topic. */ do_action('groups_delete_group_forum_post', $post_id, $topic_id); } return (bool) $action; }
/** * Delete activity associated with a Doc * * Run on transition_post_status, to catch deletes from all locations * * @since 1.3 * * @param string $new_status * @param string $old_status * @param obj WP_Post object */ function bp_docs_delete_doc_activity($new_status, $old_status, $post) { if (!bp_is_active('activity')) { return; } if (bp_docs_get_post_type_name() != $post->post_type) { return; } if ('trash' != $new_status) { return; } $activities = bp_activity_get(array('filter' => array('secondary_id' => $post->ID, 'component' => 'docs'))); foreach ((array) $activities['activities'] as $activity) { bp_activity_delete(array('id' => $activity->id)); } }
function check_delete_comments() { global $rtmedia_query; if ('delete-comment' !== $rtmedia_query->action_query->action) { return; } if (count($_POST)) { // @codingStandardsIgnoreLine /** * /media/id/delete-comment [POST] * Delete Comment by Comment ID */ $_comment_id = filter_input(INPUT_POST, 'comment_id', FILTER_SANITIZE_NUMBER_INT); if (empty($_comment_id)) { return false; } $comment = new RTMediaComment(); $id = $_comment_id; $activity_id = get_comment_meta($id, 'activity_id', true); if (!empty($activity_id)) { if (function_exists('bp_activity_delete_comment')) { //if buddypress is active $activity_deleted = bp_activity_delete_comment($activity_id, $id); $delete = bp_activity_delete(array('id' => $activity_id, 'type' => 'activity_comment')); } } $comment_deleted = $comment->remove($id); echo $comment_deleted; // @codingStandardsIgnoreLine exit; } }
function bp_dtheme_delete_activity() { global $bp; // Check the nonce check_admin_referer('bp_activity_delete_link'); if (!is_user_logged_in() || empty($_POST['id']) || !is_numeric($_POST['id'])) { echo '-1'; return false; } $activity = new BP_Activity_Activity((int) $_POST['id']); // Check access if (empty($activity->user_id) || !bp_activity_user_can_delete($activity)) { echo '-1'; return false; } // Call the action before the delete so plugins can still fetch information about it do_action('bp_activity_before_action_delete_activity', $activity->id, $activity->user_id); if (!bp_activity_delete(array('id' => $activity->id, 'user_id' => $activity->user_id))) { echo '-1<div id="message" class="error"><p>' . __('There was a problem when deleting. Please try again.', 'buddypress') . '</p></div>'; return false; } do_action('bp_activity_action_delete_activity', $activity->id, $activity->user_id); return true; }
/** * Delete the activity stream entry when a reply is spammed, trashed, or deleted * * @param int $reply_id * @uses get_post_meta() * @uses bp_activity_delete() */ public function reply_delete($reply_id) { // Get activity ID, bail if it doesn't exist if ($activity_id = $this->get_activity_id($reply_id)) { return bp_activity_delete(array('id' => $activity_id)); } return false; }