Skip to:
Content

BuddyPress.org

Ticket #8304: 8304-3.patch

File 8304-3.patch, 9.5 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.
     
    349349                        // Trim 'bulk_' off the action name to avoid duplicating a ton of code.
    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
    355359                        // Check this is a valid form submission.
     
    375379                        }
    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 ) );
     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                                        }
    383388
    384                                         $deleted++;
     389                                        if ( ! $delete_result ) {
     390                                                $errors[] = $activity->id;
     391                                        } else {
     392                                                $deleted++;
     393                                        }
    385394                                        break;
    386395
    387396                                case 'ham' :
     
    396405                                        $result = $activity->save();
    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
    405415                                case 'spam' :
     
    407417                                        $result = $activity->save();
    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
    416427                                default:
     
    435446                do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
    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 );
     451                }
    440452
    441                 if ( $unspammed )
     453                if ( $unspammed ) {
    442454                        $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
     455                }
    443456
    444                 if ( $deleted )
     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                /**
    452467                 * Filters redirect URL after activity spamming/un-spamming/deletion occurs.
     
    604619 */
    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();
     635        }
    616636}
    617637
    618638/**
     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$s: activity type. %2$s: activity author. %3$s: activity date and time. */
     690                                __( '"%1$s" activity submitted by %2$s on %3$s', 'buddypress' ),
     691                                $activity_type,
     692                                bp_core_get_userlink( $activity->user_id ),
     693                                sprintf(
     694                                        '<a href="%1$s">%2$s</a>',
     695                                        bp_activity_get_permalink( $activity->id ),
     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
     713
     714/**
    619715 * Display the single activity edit screen.
    620716 *
    621717 * @since 1.6.0
     
    741837 * @param object $item Activity item.
    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
    746846        <div class="submitbox" id="submitcomment">
     
    783883                </div><!-- #minor-publishing -->
    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 ); ?>
    788892                        </div>
  • src/bp-activity/classes/class-bp-activity-list-table.php

     
    664664                        $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) );
    665665
    666666                // 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' ) );
     667                $actions['delete'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $delete_url ), __( 'Delete Permanently', 'buddypress' ) );
    668668
    669669                // Start timestamp.
    670670                echo '<div class="submitted-on">';