Skip to:
Content

bbPress.org

Changeset 6791


Ignore:
Timestamp:
03/29/2018 06:03:12 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Admin: improve topic/reply row-action UX.

This change includes more improvements to how topics and replies are toggled from an admin area list-table:

  • Move "Empty Spam" buttons to their own actions div
  • Allow spam/trash/approve/unapprove from any other status, so topics/replies can be more freely moved around
  • Add public/non-public functions for replies to match topics

See #1799.

Location:
trunk/src/includes
Files:
7 edited

Legend:

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

    r6790 r6791  
    8080        add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown'  ) );
    8181        add_filter( 'bbp_request',           array( $this, 'filter_post_rows' ) );
     82
     83        // Empty spam
     84        add_filter( 'manage_posts_extra_tablenav', array( $this, 'filter_empty_spam' ) );
    8285
    8386        // Contextual Help
     
    471474                check_admin_referer( 'approve-reply_' . $reply_id );
    472475
    473                 $is_approve = bbp_is_reply_published( $reply_id );
     476                $is_approve = bbp_is_reply_public( $reply_id );
    474477                $message    = ( true === $is_approve )
    475478                    ? 'unpproved'
    476479                    : 'approved';
    477480                $success    = ( true === $is_approve )
    478                     ? bbp_approve_reply( $reply_id )
    479                     : bbp_unapprove_reply( $reply_id );
     481                    ? bbp_unapprove_reply( $reply_id )
     482                    : bbp_approve_reply( $reply_id );
    480483
    481484                break;
     
    801804        if ( current_user_can( 'moderate', $reply->ID ) ) {
    802805
    803             // Show the 'approve' link on pending posts only and 'unapprove' on published posts only
     806            // Show the 'approve' link on non-published posts only and 'unapprove' on published posts only
    804807            $approve_uri = wp_nonce_url( add_query_arg( array( 'reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_approve' ), remove_query_arg( array( 'bbp_reply_toggle_notice', 'reply_id', 'failed', 'super' ) ) ), 'approve-reply_' . $reply->ID );
    805             if ( bbp_is_reply_published( $reply->ID ) ) {
     808            if ( bbp_is_reply_public( $reply->ID ) ) {
    806809                $actions['unapproved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Unapprove this reply', 'bbpress' ) . '">' . _x( 'Unapprove', 'Unapprove reply', 'bbpress' ) . '</a>';
    807             } elseif ( ! bbp_is_reply_private( $reply->ID ) ) {
     810            } else {
    808811                $actions['approved']   = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Approve this reply',   'bbpress' ) . '">' . _x( 'Approve',   'Approve reply',   'bbpress' ) . '</a>';
    809812            }
    810813
    811814            // Show the 'spam' link on published and pending replies and 'not spam' on spammed replies
    812             if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_pending_status_id(), bbp_get_spam_status_id() ), true ) ) {
     815            if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id(), bbp_get_spam_status_id() ), true ) ) {
    813816                $spam_uri  = wp_nonce_url( add_query_arg( array( 'reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_spam' ), remove_query_arg( array( 'bbp_reply_toggle_notice', 'reply_id', 'failed', 'super' ) ) ), 'spam-reply_'  . $reply->ID );
    814                 if ( bbp_is_reply_spam( $reply->ID ) ) {
     817                if ( ! bbp_is_reply_spam( $reply->ID ) ) {
     818                    $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this reply as spam',    'bbpress' ) . '">' . esc_html__( 'Spam',     'bbpress' ) . '</a>';
     819                } else {
    815820                    $actions['unspam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . esc_html__( 'Not Spam', 'bbpress' ) . '</a>';
    816                 } else {
    817                     $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this reply as spam',    'bbpress' ) . '">' . esc_html__( 'Spam',     'bbpress' ) . '</a>';
    818821                }
    819822            }
     
    833836            if ( ( bbp_get_trash_status_id() === $reply->post_status ) || empty( $trash_days ) ) {
    834837                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $reply->ID, '', true ) ) . "'>" . esc_html__( 'Delete Permanently', 'bbpress' ) . "</a>";
    835             } elseif ( bbp_get_spam_status_id() === $reply->post_status ) {
    836                 unset( $actions['trash'] );
    837838            }
    838839        }
     
    880881    public function filter_dropdown() {
    881882
    882         // Add "Empty Spam" button for moderators
    883         if ( ! empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() === $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
     883        // Get which forum is selected
     884        $selected = ! empty( $_GET['bbp_forum_id'] )
     885            ? (int) $_GET['bbp_forum_id']
     886            : 0;
     887
     888        // Show the forums dropdown
     889        bbp_dropdown( array(
     890            'selected'  => $selected,
     891            'show_none' => esc_html__( 'In all forums', 'bbpress' )
     892        ) );
     893    }
     894
     895    /**
     896     * Add "Empty Spam" button for moderators
     897     *
     898     * @since 2.6.0 bbPress (r6791)
     899     */
     900    public function filter_empty_spam() {
     901
     902        // Bail if not viewing spam
     903        if ( empty( $_GET['post_status'] ) || ( bbp_get_spam_status_id() !== $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
     904            return;
     905        }
     906
     907        ?>
     908
     909        <div class="alignleft actions"><?php
     910
     911            // Output the nonce & button
    884912            wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
    885913            submit_button(
     
    889917                false
    890918            );
    891         }
    892 
    893         // Get which forum is selected
    894         $selected = ! empty( $_GET['bbp_forum_id'] )
    895             ? (int) $_GET['bbp_forum_id']
    896             : 0;
    897 
    898         // Show the forums dropdown
    899         bbp_dropdown( array(
    900             'selected'  => $selected,
    901             'show_none' => esc_html__( 'In all forums', 'bbpress' )
    902         ) );
     919
     920        ?></div><?php
    903921    }
    904922
  • trunk/src/includes/admin/topics.php

    r6790 r6791  
    8484        add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown'  ) );
    8585        add_filter( 'bbp_request',           array( $this, 'filter_post_rows' ) );
     86
     87        // Empty spam
     88        add_filter( 'manage_posts_extra_tablenav', array( $this, 'filter_empty_spam' ) );
    8689
    8790        // Contextual Help
     
    589592                check_admin_referer( 'approve-topic_' . $topic_id );
    590593
    591                 $is_approve = bbp_is_topic_published( $topic_id );
    592                 $message    = ( false === $is_approve )
     594                $is_approve = bbp_is_topic_public( $topic_id );
     595                $message    = ( true === $is_approve )
    593596                    ? 'unapproved'
    594597                    : 'approved';
    595                 $success    = ( false === $is_approve )
    596                     ? bbp_approve_topic( $topic_id )
    597                     : bbp_unapprove_topic( $topic_id );
     598                $success    = ( true === $is_approve )
     599                    ? bbp_unapprove_topic( $topic_id )
     600                    : bbp_approve_topic( $topic_id );
    598601
    599602                break;
     
    979982            // Show the 'approve' and 'view' link on pending posts only and 'unapprove' on published posts only
    980983            $approve_uri = wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_approve' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'approve-topic_' . $topic->ID );
    981             if ( bbp_is_topic_published( $topic->ID ) ) {
     984            if ( bbp_is_topic_public( $topic->ID ) ) {
    982985                $actions['unapproved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Unapprove this topic', 'bbpress' ) . '">' . _x( 'Unapprove', 'Unapprove Topic', 'bbpress' ) . '</a>';
    983             } elseif ( ! bbp_is_topic_private( $topic->ID ) ) {
    984                 $actions['approved']   = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Approve this topic',   'bbpress' ) . '">' . _x( 'Approve',   'Approve Topic',   'bbpress' ) . '</a>';
    985                 $actions['view']       = '<a href="' . esc_url( $view_link   ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>';
     986            } else {
     987
     988                // Do not show 'approve' if already public
     989                if ( ! bbp_is_topic_public( $topic->ID ) ) {
     990                    $actions['approved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Approve this topic',   'bbpress' ) . '">' . _x( 'Approve',   'Approve Topic',   'bbpress' ) . '</a>';
     991                }
     992
     993                // Modify the view link
     994                $actions['view'] = '<a href="' . esc_url( $view_link   ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>';
    986995            }
    987996
     
    9981007
    9991008            // Sticky
    1000             // Dont show sticky if topic links is spam, trash or pending
     1009            // Dont show sticky if topic is spam, trash or pending
    10011010            if ( ! bbp_is_topic_spam( $topic->ID ) && ! bbp_is_topic_trash( $topic->ID ) && ! bbp_is_topic_pending( $topic->ID ) ) {
    10021011                $stick_uri = wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_'  . $topic->ID );
     
    10111020            // Spam
    10121021            $spam_uri = wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'spam-topic_'  . $topic->ID );
    1013             if ( bbp_is_topic_spam( $topic->ID ) ) {
     1022            if ( ! bbp_is_topic_spam( $topic->ID ) ) {
     1023                $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this topic as spam',    'bbpress' ) . '">' . esc_html__( 'Spam',     'bbpress' ) . '</a>';
     1024            } else {
    10141025                $actions['unspam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . esc_html__( 'Not Spam', 'bbpress' ) . '</a>';
    1015             } else {
    1016                 $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this topic as spam',    'bbpress' ) . '">' . esc_html__( 'Spam',     'bbpress' ) . '</a>';
    10171026            }
    10181027        }
     
    10311040            if ( ( bbp_get_trash_status_id() === $topic->post_status ) || empty( $trash_days ) ) {
    10321041                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $topic->ID, '', true ) ) . "'>" . esc_html__( 'Delete Permanently', 'bbpress' ) . "</a>";
    1033             } elseif ( bbp_get_spam_status_id() === $topic->post_status ) {
    1034                 unset( $actions['trash'] );
    10351042            }
    10361043        }
     
    10781085    public function filter_dropdown() {
    10791086
    1080         // Add "Empty Spam" button for moderators
    1081         if ( ! empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() === $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
     1087        // Get which forum is selected
     1088        $selected = ! empty( $_GET['bbp_forum_id'] )
     1089            ? (int) $_GET['bbp_forum_id']
     1090            : 0;
     1091
     1092        // Show the forums dropdown
     1093        bbp_dropdown( array(
     1094            'selected'  => $selected,
     1095            'show_none' => esc_html__( 'In all forums', 'bbpress' )
     1096        ) );
     1097    }
     1098
     1099    /**
     1100     * Add "Empty Spam" button for moderators
     1101     *
     1102     * @since 2.6.0 bbPress (r6791)
     1103     */
     1104    public function filter_empty_spam() {
     1105
     1106        // Bail if not viewing spam
     1107        if ( empty( $_GET['post_status'] ) || ( bbp_get_spam_status_id() !== $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
     1108            return;
     1109        }
     1110
     1111        ?>
     1112
     1113        <div class="alignleft actions"><?php
     1114
     1115            // Output the nonce & button
    10821116            wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
    10831117            submit_button(
     
    10871121                false
    10881122            );
    1089         }
    1090 
    1091         // Get which forum is selected
    1092         $selected = ! empty( $_GET['bbp_forum_id'] )
    1093             ? (int) $_GET['bbp_forum_id']
    1094             : 0;
    1095 
    1096         // Show the forums dropdown
    1097         bbp_dropdown( array(
    1098             'selected'  => $selected,
    1099             'show_none' => esc_html__( 'In all forums', 'bbpress' )
    1100         ) );
     1123
     1124        ?></div><?php
    11011125    }
    11021126
  • trunk/src/includes/common/shortcodes.php

    r6573 r6791  
    443443            $bbp = bbpress();
    444444
    445             // Reset necessary forum_query attributes for replys loop to function
     445            // Reset necessary forum_query attributes for reply loop to function
    446446            $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
    447447            $bbp->forum_query->in_the_loop             = true;
    448448            $bbp->forum_query->post                    = get_post( $forum_id );
    449449
    450             // Reset necessary reply_query attributes for replys loop to function
     450            // Reset necessary reply_query attributes for reply loop to function
    451451            $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
    452452            $bbp->reply_query->in_the_loop             = true;
  • trunk/src/includes/extend/buddypress/groups.php

    r6777 r6791  
    117117        add_filter( 'bbp_new_reply_redirect_to', array( $this, 'new_reply_redirect_to'        ), 10, 3 );
    118118
    119         // Map forum/topic/replys permalinks to their groups
     119        // Map forum/topic/reply permalinks to their groups
    120120        add_filter( 'bbp_get_forum_permalink',   array( $this, 'map_forum_permalink_to_group' ), 10, 2 );
    121121        add_filter( 'bbp_get_topic_permalink',   array( $this, 'map_topic_permalink_to_group' ), 10, 2 );
  • trunk/src/includes/replies/functions.php

    r6784 r6791  
    16281628        bbp_get_spam_status_id()    => _x( 'Spam',    'Spam the reply',        'bbpress' ),
    16291629        bbp_get_trash_status_id()   => _x( 'Trash',   'Trash the reply',       'bbpress' ),
    1630         bbp_get_pending_status_id() => _x( 'Pending', 'Mark reply as pending', 'bbpress' ),
     1630        bbp_get_pending_status_id() => _x( 'Pending', 'Mark reply as pending', 'bbpress' )
    16311631    ), $reply_id );
    1632 }
    1633 
    1634 /**
    1635  * Return array of public reply statuses.
    1636  *
    1637  * @since 2.6.0 bbPress (r6705)
    1638  *
    1639  * @return array
    1640  */
    1641 function bbp_get_public_reply_statuses() {
    1642     $statuses = array(
    1643         bbp_get_public_status_id()
    1644     );
    1645 
    1646     // Filter & return
    1647     return (array) apply_filters( 'bbp_get_public_reply_statuses', $statuses );
    16481632}
    16491633
     
    17761760    }
    17771761
     1762    // Get new status
     1763    $status = bbp_get_public_status_id();
     1764
    17781765    // Bail if already approved
    1779     if ( bbp_get_pending_status_id() !== $reply->post_status ) {
     1766    if ( $status === $reply->post_status ) {
    17801767        return false;
    17811768    }
     
    17851772
    17861773    // Set publish status
    1787     $reply->post_status = bbp_get_public_status_id();
     1774    $reply->post_status = $status;
    17881775
    17891776    // No revisions
     
    18161803    }
    18171804
     1805    // Get new status
     1806    $status = bbp_get_pending_status_id();
     1807
    18181808    // Bail if already pending
    1819     if ( bbp_get_pending_status_id() === $reply->post_status ) {
     1809    if ( $status === $reply->post_status ) {
    18201810        return false;
    18211811    }
     
    18251815
    18261816    // Set pending status
    1827     $reply->post_status = bbp_get_pending_status_id();
     1817    $reply->post_status = $status;
    18281818
    18291819    // No revisions
  • trunk/src/includes/replies/template.php

    r6777 r6791  
    828828
    829829/**
     830 * Return array of public reply statuses.
     831 *
     832 * @since 2.6.0 bbPress (r6705)
     833 *
     834 * @return array
     835 */
     836function bbp_get_public_reply_statuses() {
     837    $statuses = array(
     838        bbp_get_public_status_id()
     839    );
     840
     841    // Filter & return
     842    return (array) apply_filters( 'bbp_get_public_reply_statuses', $statuses );
     843}
     844
     845/**
     846 * Return array of non-public reply statuses.
     847 *
     848 * @since 2.6.0 bbPress (r6791)
     849 *
     850 * @return array
     851 */
     852function bbp_get_non_public_reply_statuses() {
     853    $statuses = array(
     854        bbp_get_trash_status_id(),
     855        bbp_get_spam_status_id(),
     856        bbp_get_pending_status_id()
     857    );
     858
     859    // Filter & return
     860    return (array) apply_filters( 'bbp_get_non_public_reply_statuses', $statuses );
     861}
     862
     863/**
     864 * Is the reply publicly viewable?
     865 *
     866 * See bbp_get_public_reply_statuses() for public statuses.
     867 *
     868 * @since 2.6.0 bbPress (r6391)
     869 *
     870 * @param int $reply_id Optional. Reply id
     871 * @return bool True if public, false if not.
     872 */
     873function bbp_is_reply_public( $reply_id = 0 ) {
     874    $reply_id  = bbp_get_reply_id( $reply_id );
     875    $status    = bbp_get_reply_status( $reply_id );
     876    $public    = bbp_get_public_reply_statuses();
     877    $is_public = in_array( $status, $public, true );
     878
     879    // Filter & return
     880    return (bool) apply_filters( 'bbp_is_reply_public', $is_public, $reply_id );
     881}
     882
     883/**
    830884 * Is the reply not spam or deleted?
    831885 *
  • trunk/src/includes/topics/functions.php

    r6790 r6791  
    27362736
    27372737    // Get previous topic status meta
     2738    $status       = bbp_get_closed_status_id();
    27382739    $topic_status = get_post_meta( $topic_id, '_bbp_status', true );
    27392740
    27402741    // Bail if already closed and topic status meta exists
    2741     if ( bbp_get_closed_status_id() === $topic->post_status && ! empty( $topic_status ) ) {
     2742    if ( $status === $topic->post_status && ! empty( $topic_status ) ) {
    27422743        return false;
    27432744    }
    27442745
    27452746    // Set status meta public
    2746     $topic_status = bbp_get_public_status_id();
     2747    $topic_status = $topic->post_status;
    27472748
    27482749    // Execute pre close code
     
    27532754
    27542755    // Set closed status
    2755     $topic->post_status = bbp_get_closed_status_id();
     2756    $topic->post_status = $status;
    27562757
    27572758    // Toggle revisions off as we are not altering content
     
    31713172
    31723173    // Set publish status
    3173     $topic->post_status = bbp_get_public_status_id();
     3174    $topic->post_status = $status;
    31743175
    31753176    // No revisions
     
    32053206    $status = bbp_get_pending_status_id();
    32063207
    3207     // Bail if already pending
    3208     if ( $status === $topic->post_status ) {
     3208    // Bail if already unapproved
     3209    if ( ! bbp_is_topic_public( $topic_id ) ) {
    32093210        return false;
    32103211    }
Note: See TracChangeset for help on using the changeset viewer.