Skip to:
Content

BuddyPress.org

Ticket #8304: 8304-2.patch

File 8304-2.patch, 8.3 KB (added by oztaser, 5 years ago)
  • src/bp-activity/admin/css/admin-rtl.css

     
    9797        width: 12%;
    9898}
    9999
     100ul.bp-activity-delete-list {
     101        list-style-type: disc;
     102        margin: 4px 26px;
     103}
     104
    100105@media screen and (max-width: 782px) {
    101106
    102107        body.toplevel_page_bp-activity .wp-list-table tr:not(.inline-edit-row):not(.no-items) td:not(.check-column) {
  • src/bp-activity/admin/css/admin.css

     
    9797        width: 12%;
    9898}
    9999
     100ul.bp-activity-delete-list {
     101        list-style-type: disc;
     102        margin: 4px 26px;
     103}
     104
    100105@media screen and (max-width: 782px) {
    101106
    102107        body.toplevel_page_bp-activity .wp-list-table tr:not(.inline-edit-row):not(.no-items) td:not(.check-column) {
  • src/bp-activity/bp-activity-admin.php

     
    323323        do_action( 'bp_activity_admin_enqueue_scripts' );
    324324
    325325        // Handle spam/un-spam/delete of activities.
    326         if ( !empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', ) ) ) {
     326        if ( !empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', 'delete', 'bulk_delete' ) ) ) {
    327327
    328328                // Build redirection URL.
    329329                $redirect_to = remove_query_arg( array( 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), wp_get_referer() );
     
    330330                $redirect_to = add_query_arg( 'paged', $bp_activity_list_table->get_pagenum(), $redirect_to );
    331331
    332332                // Get activity IDs.
    333                 $activity_ids = array_map( 'absint', (array) $_REQUEST['aid'] );
     333                $activity_ids = wp_parse_id_list( $_REQUEST['aid'] );
    334334
    335335                /**
    336336                 * Filters list of IDs being spammed/un-spammed/deleted.
     
    348348
    349349                        // Trim 'bulk_' off the action name to avoid duplicating a ton of code.
    350350                        $doaction = substr( $doaction, 5 );
     351                // This is a request to delete single or multiple item
     352                } elseif ( 'do_delete'  == $doaction && ! empty( $_REQUEST['aid'] ) ) {
     353                        check_admin_referer( 'bp-activities-delete' );
    351354
    352                 // This is a request to delete, spam, or un-spam, a single item.
     355                // This is a request to spam, or un-spam, a single item.
    353356                } elseif ( !empty( $_REQUEST['aid'] ) ) {
    354357
    355358                        // Check this is a valid form submission.
     
    375378                        }
    376379
    377380                        switch ( $doaction ) {
    378                                 case 'delete' :
    379                                         if ( 'activity_comment' == $activity->type )
    380                                                 bp_activity_delete_comment( $activity->item_id, $activity->id );
    381                                         else
    382                                                 bp_activity_delete( array( 'id' => $activity->id ) );
     381                                case 'do_delete' :
     382                                        if ( 'activity_comment' == $activity->type ) {
     383                                                $delete_result = bp_activity_delete_comment( $activity->item_id, $activity->id );
     384                                        } else {
     385                                                $delete_result = bp_activity_delete( array( 'id' => $activity->id ) );
     386                                        }
    383387
    384                                         $deleted++;
     388                                        if ( ! $delete_result ) {
     389                                                $errors[] = $activity->id;
     390                                        } else {
     391                                                $deleted++;
     392                                        }
    385393                                        break;
    386394
    387395                                case 'ham' :
     
    396404                                        $result = $activity->save();
    397405
    398406                                        // Check for any error during activity save.
    399                                         if ( ! $result )
     407                                        if ( ! $result ) {
    400408                                                $errors[] = $activity->id;
    401                                         else
     409                                        } else {
    402410                                                $unspammed++;
     411                                        }
    403412                                        break;
    404413
    405414                                case 'spam' :
     
    407416                                        $result = $activity->save();
    408417
    409418                                        // Check for any error during activity save.
    410                                         if ( ! $result )
     419                                        if ( ! $result ) {
    411420                                                $errors[] = $activity->id;
    412                                         else
     421                                        } else {
    413422                                                $spammed++;
     423                                        }
    414424                                        break;
    415425
    416426                                default:
     
    435445                do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
    436446
    437447                // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
    438                 if ( $spammed )
     448                if ( $spammed ) {
    439449                        $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
     450                }
    440451
    441                 if ( $unspammed )
     452                if ( $unspammed ) {
    442453                        $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
     454                }
    443455
    444                 if ( $deleted )
     456                if ( $deleted ) {
    445457                        $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
     458                }
    446459
    447460                // If an error occurred, pass back the activity ID that failed.
    448                 if ( ! empty( $errors ) )
     461                if ( ! empty( $errors ) ) {
    449462                        $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to );
     463                }
    450464
    451465                /**
    452466                 * Filters redirect URL after activity spamming/un-spamming/deletion occurs.
     
    604618 */
    605619function bp_activity_admin() {
    606620        // Decide whether to load the index or edit screen.
    607         $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
     621        $doaction = bp_admin_list_table_current_bulk_action();
    608622
    609623        // Display the single activity edit screen.
    610         if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) )
     624        if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) {
    611625                bp_activity_admin_edit();
     626        }
    612627
     628        // Display the activty delete confirmation screen.
     629        elseif ( in_array( $doaction, array( 'bulk_delete', 'delete' ) ) && ! empty( $_GET['aid'] ) ) {
     630                bp_activity_admin_delete();
     631        }
     632
    613633        // Otherwise, display the Activity index screen.
    614         else
     634        else {
    615635                bp_activity_admin_index();
     636        }
    616637}
    617638
    618639/**
     640 * Display the Activity delete confirmation screen.
     641 *
     642 * @since 7.0.0
     643 */
     644function bp_activity_admin_delete() {
     645
     646        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     647                die( '-1' );
     648        }
     649
     650        $activity_ids = isset( $_REQUEST['aid'] ) ? $_REQUEST['aid'] : 0;
     651
     652        if ( ! is_array( $activity_ids ) ) {
     653                $activity_ids = explode( ',', $activity_ids );
     654        }
     655
     656        $activities = bp_activity_get( array(
     657                'in'               => $activity_ids,
     658                'show_hidden'      => true,
     659                'spam'             => 'all',
     660                'display_comments' => 0,
     661                'per_page'         => null
     662        ) );
     663
     664        // Create a new list of activity ids, based on those that actually exist.
     665        $aids = array();
     666        foreach ( $activities['activities'] as $activity ) {
     667                $aids[] = $activity->id;
     668        }
     669
     670        $base_url = remove_query_arg( array( 'action', 'action2', 'paged', 's', '_wpnonce', 'aid' ), $_SERVER['REQUEST_URI'] ); ?>
     671
     672        <div class="wrap">
     673                <h1><?php _e( 'Delete Activities', 'buddypress' ) ?></h1>
     674                <p><?php _e( 'You are about to delete the following activities:', 'buddypress' ) ?></p>
     675
     676                <ul class="bp-activity-delete-list">
     677                <?php foreach ( $activities['activities'] as $activity ) : ?>
     678                        <?php
     679                        if ( ! empty( $activity->content ) ) {
     680                                $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $activity->content, &$activity ) );
     681                        } else {
     682                                // Emulate bp_get_activity_action().
     683                                $r = array(
     684                                        'no_timestamp' => false,
     685                                );
     686                                $content = apply_filters_ref_array( 'bp_get_activity_action', array( $activity->action, &$activity, $r ) );
     687                        }
     688                        ?>
     689                        <li><?php echo $content; ?></li>
     690                <?php endforeach; ?>
     691                </ul>
     692
     693                <p><strong><?php _e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
     694
     695                <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'do_delete', 'aid' => implode( ',', $aids ) ), $base_url ), 'bp-activities-delete' ) ); ?>"><?php _e( 'Delete Permanently', 'buddypress' ) ?></a>
     696                <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php _e( 'Cancel', 'buddypress' ) ?></a>
     697        </div>
     698
     699        <?php
     700}
     701
     702
     703/**
    619704 * Display the single activity edit screen.
    620705 *
    621706 * @since 1.6.0
     
    741826 * @param object $item Activity item.
    742827 */
    743828function bp_activity_admin_edit_metabox_status( $item ) {
     829        $base_url = add_query_arg( array(
     830                'page' => 'bp-activity',
     831                'aid'  => $item->id
     832        ), bp_get_admin_url( 'admin.php' ) );
    744833?>
    745834
    746835        <div class="submitbox" id="submitcomment">
     
    783872                </div><!-- #minor-publishing -->
    784873
    785874                <div id="major-publishing-actions">
     875                        <div id="delete-action">
     876                                <a class="submitdelete deletion" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'action', 'delete', $base_url ), 'bp-activities-delete' ) ); ?>"><?php _e( 'Delete Permanently', 'buddypress' ) ?></a>
     877                        </div>
     878
    786879                        <div id="publishing-action">
    787880                                <?php submit_button( __( 'Update', 'buddypress' ), 'primary', 'save', false ); ?>
    788881                        </div>