Skip to:
Content

bbPress.org


Ignore:
Timestamp:
10/13/2016 03:27:09 PM (10 years ago)
Author:
netweb
Message:

General - Administration: Introduce bulk actions to spam and unspam topics and replies in wp-admin

This Friday #yolo changeset comes care of the upcoming WordPress 4.7 release via ​#WP16031 / ​wp:changeset:38647

Props jmdodd.
See #2246.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/replies.php

    r6056 r6101  
    4848         *
    4949         * @since 2.0.0 bbPress (r2646)
     50         * @since 2.6.0 bbPress (r6101) Added bulk actions
    5051         *
    5152         * @access private
    … …  
    6465                // Messages
    6566                add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
     67
     68                // Reply bulk actions, added in WordPress 4.7, see #WP16031
     69                if ( bbp_get_major_wp_version() >= 4.7 ) {
     70                        add_filter( 'bulk_actions-edit-reply',        array( $this, 'bulk_actions' ) );
     71                        add_filter( 'handle_bulk_actions-edit-reply', array( $this, 'handle_bulk_actions' ), 10, 3 );
     72                        add_filter( 'bulk_post_updated_messages',     array( $this, 'bulk_post_updated_messages' ), 10, 2 );
     73                }
    6674
    6775                // Reply column headers.
    … …  
    175183                        'title'         => __( 'Bulk Actions', 'bbpress' ),
    176184                        'content'       =>
    177                                 '<p>' . __( 'You can also edit or move multiple replies to the trash at once. Select the replies you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.',           'bbpress' ) . '</p>' .
     185                                '<p>' . __( 'You can also edit, spam, or move multiple replies to the trash at once. Select the replies you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.',           'bbpress' ) . '</p>' .
    178186                                '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected replies at once. To remove a reply from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>'
    179187                ) );
    … …  
    245253                        '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
    246254                );
     255        }
     256
     257        /**
     258         * Add spam/unspam bulk actions to the bulk action dropdown.
     259         *
     260         * @since 2.6.0 bbPress (r6101)
     261         *
     262         * @param array $actions The list of bulk actions.
     263         * @return array The filtered list of bulk actions.
     264         */
     265        public function bulk_actions( $actions ) {
     266
     267                if ( $this->bail() ) {
     268                        return $actions;
     269                }
     270
     271                if ( current_user_can( 'moderate' ) ) {
     272                        if ( bbp_get_spam_status_id() === get_query_var( 'post_status' ) ) {
     273                                $actions['unspam'] = __( 'Unspam', 'bbpress' );
     274                        } else {
     275                                $actions['spam'] = __( 'Spam', 'bbpress' );
     276                        }
     277                }
     278
     279                return $actions;
     280        }
     281
     282        /**
     283         * Add custom bulk action updated messages for replies.
     284         *
     285         * @since 2.6.0 bbPress (r6101)
     286         *
     287         * @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type.
     288         * @param array $bulk_counts   Array of item counts for each message, used to build internationalized strings.
     289         */
     290        public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) {
     291
     292                if ( $this->bail() ) {
     293                        return $bulk_messages;
     294                }
     295
     296                $bulk_messages['reply']['updated'] = _n( '%s reply updated.', '%s replies updated.', $bulk_counts['updated'] );
     297                $bulk_messages['reply']['locked']  = ( 1 === $bulk_counts['locked'] ) ? __( '1 reply not updated, somebody is editing it.' ) :
     298                                                          _n( '%s reply not updated, somebody is editing it.', '%s replies not updated, somebody is editing them.', $bulk_counts['locked'] );
     299                return $bulk_messages;
     300        }
     301
     302        /**
     303         * Handle spam/unspam bulk actions.
     304         *
     305         * @since 2.6.0 bbPress (r6101)
     306         *
     307         * @param string $sendback The sendback URL.
     308         * @param string $doaction The action to be taken.
     309         * @param array  $post_ids The post IDS to take the action on.
     310         * @return string The sendback URL.
     311         */
     312        public function handle_bulk_actions( $sendback, $doaction, $post_ids ) {
     313
     314                if ( $this->bail() ) {
     315                        return $sendback;
     316                }
     317
     318                $sendback = remove_query_arg( array( 'spam', 'unspam' ), $sendback );
     319                $updated = $locked = 0;
     320
     321                if ( 'spam' === $doaction ) {
     322
     323                        foreach ( (array) $post_ids as $post_id ) {
     324                                if ( ! current_user_can( 'moderate', $post_id ) ) {
     325                                        wp_die( __( 'Sorry, you are not allowed to spam this item.', 'bbpress' ) );
     326                                }
     327
     328                                if ( wp_check_post_lock( $post_id ) ) {
     329                                        $locked++;
     330                                        continue;
     331                                }
     332
     333                                if ( ! bbp_spam_reply( $post_id ) ) {
     334                                        wp_die( __( 'Error in spamming reply.', 'bbpress' ) );
     335                                }
     336
     337                                $updated++;
     338                        }
     339
     340                        $sendback = add_query_arg( array( 'updated' => $updated, 'ids' => join( ',', $post_ids ), 'locked' => $locked ), $sendback );
     341
     342                } elseif ( 'unspam' === $doaction ) {
     343
     344                        foreach ( (array) $post_ids as $post_id ) {
     345                                if ( ! current_user_can( 'moderate', $post_id ) ) {
     346                                        wp_die( __( 'Sorry, you are not allowed to unspam this reply.', 'bbpress' ) );
     347                                }
     348
     349                                if ( wp_check_post_lock( $post_id ) ) {
     350                                        $locked++;
     351                                        continue;
     352                                }
     353
     354                                if ( ! bbp_unspam_reply( $post_id ) ) {
     355                                        wp_die( __( 'Error in unspamming reply.', 'bbpress' ) );
     356                                }
     357
     358                                $updated++;
     359                        }
     360
     361                        $sendback = add_query_arg( array( 'updated' => $updated, 'ids' => join( ',', $post_ids ), 'locked' => $locked ), $sendback );
     362                }
     363
     364                return $sendback;
    247365        }
    248366
Note: See TracChangeset for help on using the changeset viewer.