Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/08/2012 08:55:34 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Admin:

  • Introduce bail() method to forum/topic/reply components.
  • Bail out of other methods if post_type doesn't match.
  • Fixes issue where meta-box and styling were not always available on all appropriate screens.
  • Also reverts some perfomance improvements implimented in r4053.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-replies.php

    r4054 r4070  
    3939     * @uses BBP_Replies_Admin::setup_actions() Setup the help text
    4040     */
    41     function __construct() {
     41    public function __construct() {
    4242        $this->setup_globals();
    4343        $this->setup_actions();
     
    5656     * @uses bbp_get_reply_post_type() To get the reply post type
    5757     */
    58     function setup_actions() {
     58    private function setup_actions() {
    5959
    6060        // Add some general styling to the admin area
     
    9393
    9494    /**
     95     * Should we bail out of this method?
     96     *
     97     * @since bbPress (r4067)
     98     * @return boolean
     99     */
     100    private function bail() {
     101        if ( $this->post_type != get_current_screen()->post_type )
     102            return true;
     103
     104        return false;
     105    }
     106       
     107    /**
    95108     * Admin globals
    96109     *
     
    98111     * @access private
    99112     */
    100     function setup_globals() {
    101 
    102         // Setup the post type for this admin component
     113    private function setup_globals() {
    103114        $this->post_type = bbp_get_reply_post_type();
    104115    }
     
    113124     */
    114125    public function edit_help() {
     126
     127        if ( $this->bail() ) return;
    115128
    116129        // Overview
     
    176189    public function new_help() {
    177190
     191        if ( $this->bail() ) return;
     192
    178193        $customize_display = '<p>' . __( 'The title field and the big reply editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>';
    179194
     
    243258     * @uses do_action() Calls 'bbp_reply_attributes_metabox'
    244259     */
    245     function reply_attributes_metabox() {
     260    public function reply_attributes_metabox() {
     261
     262        if ( $this->bail() ) return;
     263
    246264        add_meta_box (
    247265            'bbp_reply_attributes',
     
    268286     * @return int Parent id
    269287     */
    270     function reply_attributes_metabox_save( $reply_id ) {
     288    public function reply_attributes_metabox_save( $reply_id ) {
     289
     290        if ( $this->bail() ) return $reply_id;
    271291
    272292        // Bail if doing an autosave
     
    318338     *                    id
    319339     */
    320     function author_metabox() {
     340    public function author_metabox() {
     341
     342        if ( $this->bail() ) return;
    321343
    322344        // Bail if post_type is not a reply
     
    353375     * @return int Topic or reply id
    354376     */
    355     function author_metabox_save( $post_id ) {
     377    public function author_metabox_save( $post_id ) {
     378
     379        if ( $this->bail() ) return $post_id;
    356380
    357381        // Bail if no post_id
     
    393417     * @uses do_action() Calls 'bbp_admin_head'
    394418     */
    395     function admin_head() {
     419    public function admin_head() {
     420       
     421        if ( $this->bail() ) return;
     422
    396423        ?>
    397424
     
    464491     * @uses wp_safe_redirect() Redirect the page to custom url
    465492     */
    466     function toggle_reply() {
     493    public function toggle_reply() {
     494
     495        if ( $this->bail() ) return;
    467496
    468497        // Only proceed if GET is a reply toggle action
     
    524553     *                        message, reply id, notice and is it a failure
    525554     */
    526     function toggle_reply_notice() {
     555    public function toggle_reply_notice() {
     556
     557        if ( $this->bail() ) return;
    527558
    528559        // Only proceed if GET is a reply toggle action
     
    576607     * @return array $columns bbPress reply columns
    577608     */
    578     function replies_column_headers( $columns ) {
     609    public function replies_column_headers( $columns ) {
     610
     611        if ( $this->bail() ) return $columns;
     612
    579613        $columns = array(
    580614            'cb'                => '<input type="checkbox" />',
     
    617651     *                    column and reply id
    618652     */
    619     function replies_column_data( $column, $reply_id ) {
     653    public function replies_column_data( $column, $reply_id ) {
     654
     655        if ( $this->bail() ) return;
    620656
    621657        // Get topic ID
     
    727763     * @return array $actions Actions
    728764     */
    729     function replies_row_actions( $actions, $reply ) {
    730 
    731         if ( bbp_get_reply_post_type() == $reply->post_type ) {
    732             unset( $actions['inline hide-if-no-js'] );
    733 
    734             // Reply view links to topic
    735             $actions['view'] = '<a href="' . bbp_get_reply_url( $reply->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_reply_title( $reply->ID ) ) ) . '" rel="permalink">' . __( 'View', 'bbpress' ) . '</a>';
    736 
    737             // User cannot view replies in trash
    738             if ( ( bbp_get_trash_status_id() == $reply->post_status ) && !current_user_can( 'view_trash' ) )
    739                 unset( $actions['view'] );
    740 
    741             // Only show the actions if the user is capable of viewing them
    742             if ( current_user_can( 'moderate', $reply->ID ) ) {
    743                 if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_spam_status_id() ) ) ) {
    744                     $spam_uri  = esc_url( 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 ) );
    745                     if ( bbp_is_reply_spam( $reply->ID ) ) {
    746                         $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
    747                     } else {
    748                         $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this reply as spam',    'bbpress' ) . '">' . __( 'Spam',     'bbpress' ) . '</a>';
    749                     }
     765    public function replies_row_actions( $actions, $reply ) {
     766
     767        if ( $this->bail() ) return $actions;
     768
     769        unset( $actions['inline hide-if-no-js'] );
     770
     771        // Reply view links to topic
     772        $actions['view'] = '<a href="' . bbp_get_reply_url( $reply->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_reply_title( $reply->ID ) ) ) . '" rel="permalink">' . __( 'View', 'bbpress' ) . '</a>';
     773
     774        // User cannot view replies in trash
     775        if ( ( bbp_get_trash_status_id() == $reply->post_status ) && !current_user_can( 'view_trash' ) )
     776            unset( $actions['view'] );
     777
     778        // Only show the actions if the user is capable of viewing them
     779        if ( current_user_can( 'moderate', $reply->ID ) ) {
     780            if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_spam_status_id() ) ) ) {
     781                $spam_uri  = esc_url( 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 ) );
     782                if ( bbp_is_reply_spam( $reply->ID ) ) {
     783                    $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
     784                } else {
     785                    $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this reply as spam',    'bbpress' ) . '">' . __( 'Spam',     'bbpress' ) . '</a>';
    750786                }
    751787            }
    752 
    753             // Trash
    754             if ( current_user_can( 'delete_reply', $reply->ID ) ) {
    755                 if ( bbp_get_trash_status_id() == $reply->post_status ) {
    756                     $post_type_object = get_post_type_object( bbp_get_reply_post_type() );
    757                     $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
    758                 } elseif ( EMPTY_TRASH_DAYS ) {
    759                     $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID ) ) . "'>" . __( 'Trash', 'bbpress' ) . "</a>";
    760                 }
    761 
    762                 if ( bbp_get_trash_status_id() == $reply->post_status || !EMPTY_TRASH_DAYS ) {
    763                     $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID, '', true ) ) . "'>" . __( 'Delete Permanently', 'bbpress' ) . "</a>";
    764                 } elseif ( bbp_get_spam_status_id() == $reply->post_status ) {
    765                     unset( $actions['trash'] );
    766                 }
     788        }
     789
     790        // Trash
     791        if ( current_user_can( 'delete_reply', $reply->ID ) ) {
     792            if ( bbp_get_trash_status_id() == $reply->post_status ) {
     793                $post_type_object = get_post_type_object( bbp_get_reply_post_type() );
     794                $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
     795            } elseif ( EMPTY_TRASH_DAYS ) {
     796                $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID ) ) . "'>" . __( 'Trash', 'bbpress' ) . "</a>";
     797            }
     798
     799            if ( bbp_get_trash_status_id() == $reply->post_status || !EMPTY_TRASH_DAYS ) {
     800                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID, '', true ) ) . "'>" . __( 'Delete Permanently', 'bbpress' ) . "</a>";
     801            } elseif ( bbp_get_spam_status_id() == $reply->post_status ) {
     802                unset( $actions['trash'] );
    767803            }
    768804        }
     
    781817     * @return bool False. If post type is not topic or reply
    782818     */
    783     function filter_dropdown() {
     819    public function filter_dropdown() {
     820
     821        if ( $this->bail() ) return;
    784822
    785823        // Add Empty Spam button
     
    811849     * @return array Processed Query Vars
    812850     */
    813     function filter_post_rows( $query_vars ) {
    814         global $pagenow;
     851    public function filter_post_rows( $query_vars ) {
     852
     853        if ( $this->bail() ) return $query_vars;
    815854
    816855        // Add post_parent query_var if one is present
     
    839878     * @return array
    840879     */
    841     function updated_messages( $messages ) {
     880    public function updated_messages( $messages ) {
    842881        global $post_ID;
     882
     883        if ( $this->bail() ) return $messages;
    843884
    844885        // URL for the current topic
     
    906947 */
    907948function bbp_admin_replies() {
    908     global $typenow;
    909 
    910     if ( bbp_get_reply_post_type() != $typenow )
    911         return;
    912 
    913949    bbpress()->admin->replies = new BBP_Replies_Admin();
    914950}
Note: See TracChangeset for help on using the changeset viewer.