Skip to:
Content

BuddyPress.org

Changeset 12659


Ignore:
Timestamp:
05/24/2020 08:32:03 PM (6 years ago)
Author:
imath
Message:

Activity Admin: improve the delete activity actions

  • Add a new delete link to the activity edit screen.
  • Add a confirmation screen before deleting activity to be consistent with how items are deleted into the Groups Admin screen and the Signups Admin screen.
  • Update the existing delete links so that they use the confirmation screen link.
  • Improve code formatting/output escaping.

Props oztaser

Fixes #8304

Location:
trunk/src/bp-activity
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/admin/css/admin-rtl.css

    r11587 r12659  
    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
  • trunk/src/bp-activity/admin/css/admin.css

    r11587 r12659  
    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
  • trunk/src/bp-activity/bp-activity-admin.php

    r12657 r12659  
    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.
     
    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                /**
     
    350350                        $doaction = substr( $doaction, 5 );
    351351
    352                 // This is a request to delete, spam, or un-spam, a single item.
     352                        // This is a request to delete single or multiple item.
     353                } elseif ( 'do_delete'  === $doaction && ! empty( $_REQUEST['aid'] ) ) {
     354                        check_admin_referer( 'bp-activities-delete' );
     355
     356                // This is a request to spam, or un-spam, a single item.
    353357                } elseif ( !empty( $_REQUEST['aid'] ) ) {
    354358
     
    376380
    377381                        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 ) );
    383 
    384                                         $deleted++;
     382                                case 'do_delete' :
     383                                        if ( 'activity_comment' === $activity->type ) {
     384                                                $delete_result = bp_activity_delete_comment( $activity->item_id, $activity->id );
     385                                        } else {
     386                                                $delete_result = bp_activity_delete( array( 'id' => $activity->id ) );
     387                                        }
     388
     389                                        if ( ! $delete_result ) {
     390                                                $errors[] = $activity->id;
     391                                        } else {
     392                                                $deleted++;
     393                                        }
    385394                                        break;
    386395
     
    397406
    398407                                        // Check for any error during activity save.
    399                                         if ( ! $result )
     408                                        if ( ! $result ) {
    400409                                                $errors[] = $activity->id;
    401                                         else
     410                                        } else {
    402411                                                $unspammed++;
     412                                        }
    403413                                        break;
    404414
     
    408418
    409419                                        // Check for any error during activity save.
    410                                         if ( ! $result )
     420                                        if ( ! $result ) {
    411421                                                $errors[] = $activity->id;
    412                                         else
     422                                        } else {
    413423                                                $spammed++;
     424                                        }
    414425                                        break;
    415426
     
    436447
    437448                // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
    438                 if ( $spammed )
     449                if ( $spammed ) {
    439450                        $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
    440 
    441                 if ( $unspammed )
     451                }
     452
     453                if ( $unspammed ) {
    442454                        $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
    443 
    444                 if ( $deleted )
     455                }
     456
     457                if ( $deleted ) {
    445458                        $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
     459                }
    446460
    447461                // If an error occurred, pass back the activity ID that failed.
    448                 if ( ! empty( $errors ) )
     462                if ( ! empty( $errors ) ) {
    449463                        $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to );
     464                }
    450465
    451466                /**
     
    605620function bp_activity_admin() {
    606621        // Decide whether to load the index or edit screen.
    607         $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
     622        $doaction = bp_admin_list_table_current_bulk_action();
    608623
    609624        // Display the single activity edit screen.
    610         if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) )
     625        if ( 'edit' === $doaction && ! empty( $_GET['aid'] ) ) {
    611626                bp_activity_admin_edit();
    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
    613632        // Otherwise, display the Activity index screen.
    614         else
     633        } else {
    615634                bp_activity_admin_index();
    616 }
     635        }
     636}
     637
     638/**
     639 * Display the Activity delete confirmation screen.
     640 *
     641 * @since 7.0.0
     642 */
     643function bp_activity_admin_delete() {
     644
     645        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     646                die( '-1' );
     647        }
     648
     649        $activity_ids = isset( $_REQUEST['aid'] ) ? $_REQUEST['aid'] : 0;
     650
     651        if ( ! is_array( $activity_ids ) ) {
     652                $activity_ids = explode( ',', $activity_ids );
     653        }
     654
     655        $activities = bp_activity_get( array(
     656                'in'               => $activity_ids,
     657                'show_hidden'      => true,
     658                'spam'             => 'all',
     659                'display_comments' => 0,
     660                'per_page'         => null
     661        ) );
     662
     663        // Create a new list of activity ids, based on those that actually exist.
     664        $aids = array();
     665        foreach ( $activities['activities'] as $activity ) {
     666                $aids[] = $activity->id;
     667        }
     668
     669        $base_url = remove_query_arg( array( 'action', 'action2', 'paged', 's', '_wpnonce', 'aid' ), $_SERVER['REQUEST_URI'] ); ?>
     670
     671        <div class="wrap">
     672                <h1><?php esc_html_e( 'Delete Activities', 'buddypress' ) ?></h1>
     673                <p><?php esc_html_e( 'You are about to delete the following activities:', 'buddypress' ) ?></p>
     674
     675                <ul class="bp-activity-delete-list">
     676                <?php foreach ( $activities['activities'] as $activity ) : ?>
     677                        <li>
     678                        <?php
     679                        $actions = bp_activity_admin_get_activity_actions();
     680
     681                        if ( isset( $actions[ $activity->type ] ) ) {
     682                                $activity_type =  $actions[ $activity->type ];
     683                        } else {
     684                                /* translators: %s: the name of the activity type */
     685                                $activity_type = sprintf( __( 'Unregistered action - %s', 'buddypress' ), $activity->type );
     686                        }
     687
     688                        printf(
     689                                /* translators: 1: activity type. 2: activity author. 3: activity date and time. */
     690                                __( '"%1$s" activity submitted by %2$s on %3$s', 'buddypress' ),
     691                                esc_html( $activity_type ),
     692                                bp_core_get_userlink( $activity->user_id ),
     693                                sprintf(
     694                                        '<a href="%1$s">%2$s</a>',
     695                                        esc_url( bp_activity_get_permalink( $activity->id, $activity ) ),
     696                                        date_i18n( bp_get_option( 'date_format' ), strtotime( $activity->date_recorded ) )
     697                                )
     698                        );
     699                        ?>
     700                        </li>
     701                <?php endforeach; ?>
     702                </ul>
     703
     704                <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
     705
     706                <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 esc_html_e( 'Delete Permanently', 'buddypress' ) ?></a>
     707                <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a>
     708        </div>
     709
     710        <?php
     711}
     712
    617713
    618714/**
     
    742838 */
    743839function bp_activity_admin_edit_metabox_status( $item ) {
     840        $base_url = add_query_arg( array(
     841                'page' => 'bp-activity',
     842                'aid'  => $item->id
     843        ), bp_get_admin_url( 'admin.php' ) );
    744844?>
    745845
     
    784884
    785885                <div id="major-publishing-actions">
     886                        <div id="delete-action">
     887                                <a class="submitdelete deletion" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'action', 'delete', $base_url ), 'bp-activities-delete' ) ); ?>"><?php esc_html_e( 'Delete Permanently', 'buddypress' ) ?></a>
     888                        </div>
     889
    786890                        <div id="publishing-action">
    787891                                <?php submit_button( __( 'Update', 'buddypress' ), 'primary', 'save', false ); ?>
  • trunk/src/bp-activity/classes/class-bp-activity-list-table.php

    r12586 r12659  
    649649                if ( 'spam' != $item_status ) {
    650650                        if ( $this->can_comment( $item ) ) {
    651                                 $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
     651                                $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', esc_html__( 'Reply', 'buddypress' ) );
    652652                        } else {
    653                                 $actions['reply'] = sprintf( '<span class="form-input-tip">%s</span>', __( 'Replies disabled', 'buddypress' ) );
     653                                $actions['reply'] = sprintf( '<span class="form-input-tip">%s</span>', esc_html__( 'Replies disabled', 'buddypress' ) );
    654654                        }
    655655
    656656                        // Edit.
    657                         $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) );
     657                        $actions['edit'] = sprintf( '<a href="%s">%s</a>', esc_url( $edit_url ), esc_html__( 'Edit', 'buddypress' ) );
    658658                }
    659659
    660660                // Spam/unspam.
    661                 if ( 'spam' == $item_status )
    662                         $actions['unspam'] = sprintf( '<a href="%s">%s</a>', $ham_url, __( 'Not Spam', 'buddypress' ) );
    663                 else
    664                         $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) );
     661                if ( 'spam' == $item_status ) {
     662                        $actions['unspam'] = sprintf( '<a href="%s">%s</a>', esc_url( $ham_url ), esc_html__( 'Not Spam', 'buddypress' ) );
     663                } else {
     664                        $actions['spam'] = sprintf( '<a href="%s">%s</a>', esc_url( $spam_url ), esc_html__( 'Spam', 'buddypress' ) );
     665                }
    665666
    666667                // Delete.
    667                 $actions['delete'] = sprintf( '<a href="%s" onclick="%s">%s</a>', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) );
     668                $actions['delete'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $delete_url ), esc_html__( 'Delete Permanently', 'buddypress' ) );
    668669
    669670                // Start timestamp.
Note: See TracChangeset for help on using the changeset viewer.