Skip to:
Content

bbPress.org

Changeset 4070


Ignore:
Timestamp:
07/08/2012 08:55:34 AM (14 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.
Location:
branches/plugin/bbp-admin
Files:
3 edited

Legend:

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

    r4053 r4070  
    3939     * @uses BBP_Forums_Admin::setup_help() 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
     
    8181
    8282    /**
     83     * Should we bail out of this method?
     84     *
     85     * @since bbPress (r4067)
     86     * @return boolean
     87     */
     88    private function bail() {
     89        if ( $this->post_type != get_current_screen()->post_type )
     90            return true;
     91
     92        return false;
     93    }
     94       
     95    /**
    8396     * Admin globals
    8497     *
     
    8699     * @access private
    87100     */
    88     function setup_globals() {
    89 
    90         // Setup the post type for this admin component
     101    private function setup_globals() {
    91102        $this->post_type = bbp_get_forum_post_type();
    92103    }
     
    101112     */
    102113    public function edit_help() {
     114
     115        if ( $this->bail() ) return;
    103116
    104117        // Overview
     
    164177    public function new_help() {
    165178
     179        if ( $this->bail() ) return;
     180
    166181        $customize_display = '<p>' . __( 'The title field and the big forum 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>';
    167182
     
    234249     * @uses do_action() Calls 'bbp_forum_attributes_metabox'
    235250     */
    236     function attributes_metabox() {
     251    public function attributes_metabox() {
     252       
     253        if ( $this->bail() ) return;
     254
    237255        add_meta_box (
    238256            'bbp_forum_attributes',
     
    269287     * @return int Forum id
    270288     */
    271     function attributes_metabox_save( $forum_id ) {
     289    public function attributes_metabox_save( $forum_id ) {
     290
     291        if ( $this->bail() ) return $forum_id;
    272292
    273293        // Bail if doing an autosave
     
    312332     * @uses do_action() Calls 'bbp_admin_head'
    313333     */
    314     function admin_head() {
     334    public function admin_head() {
     335       
     336        if ( $this->bail() ) return;
     337
    315338        ?>
    316339
     
    388411     * @return array $columns bbPress forum columns
    389412     */
    390     function column_headers( $columns ) {
     413    public function column_headers( $columns ) {
     414       
     415        if ( $this->bail() ) return $columns;
     416
    391417        $columns = array (
    392418            'cb'                    => '<input type="checkbox" />',
     
    419445     *                    column and forum id
    420446     */
    421     function column_data( $column, $forum_id ) {
     447    public function column_data( $column, $forum_id ) {
     448       
     449        if ( $this->bail() ) return;
     450
    422451        switch ( $column ) {
    423452            case 'bbp_forum_topic_count' :
     
    465494     * @return array $actions Actions
    466495     */
    467     function row_actions( $actions, $forum ) {
     496    public function row_actions( $actions, $forum ) {
     497       
     498        if ( $this->bail() ) return $actions;
     499
    468500        unset( $actions['inline hide-if-no-js'] );
    469501
     
    489521     * @return array
    490522     */
    491     function updated_messages( $messages ) {
     523    public function updated_messages( $messages ) {
    492524        global $post_ID;
     525
     526        if ( $this->bail() ) return $messages;
    493527
    494528        // URL for the current forum
     
    556590 */
    557591function bbp_admin_forums() {
    558     global $typenow;
    559 
    560     if ( bbp_get_forum_post_type() != $typenow )
    561         return;
    562 
    563592    bbpress()->admin->forums = new BBP_Forums_Admin();
    564593}
  • 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}
  • branches/plugin/bbp-admin/bbp-topics.php

    r4053 r4070  
    3939     * @uses BBP_Topics_Admin::setup_help() 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_topic_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 topic 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_topic_attributes_metabox'
    244259     */
    245     function attributes_metabox() {
     260    public function attributes_metabox() {
     261
     262        if ( $this->bail() ) return;
     263
    246264        add_meta_box (
    247265            'bbp_topic_attributes',
     
    268286     * @return int Parent id
    269287     */
    270     function attributes_metabox_save( $topic_id ) {
     288    public function attributes_metabox_save( $topic_id ) {
    271289       
     290        if ( $this->bail() ) return $topic_id;
     291
    272292        // Bail if doing an autosave
    273293        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
     
    335355     *                    id
    336356     */
    337     function author_metabox() {
     357    public function author_metabox() {
     358
     359        if ( $this->bail() ) return;
    338360
    339361        // Bail if post_type is not a topic
     
    370392     * @return int Topic or reply id
    371393     */
    372     function author_metabox_save( $post_id ) {
     394    public function author_metabox_save( $post_id ) {
     395
     396        if ( $this->bail() ) return $post_id;
    373397
    374398        // Bail if no post_id
     
    410434     * @uses do_action() Calls 'bbp_admin_head'
    411435     */
    412     function admin_head() {
     436    public function admin_head() {
     437
     438        if ( $this->bail() ) return;
     439
    413440        ?>
    414441
     
    489516     * @uses wp_safe_redirect() Redirect the page to custom url
    490517     */
    491     function toggle_topic() {
     518    public function toggle_topic() {
     519
     520        if ( $this->bail() ) return;
    492521
    493522        // Only proceed if GET is a topic toggle action
     
    568597     *                        message, topic id, notice and is it a failure
    569598     */
    570     function toggle_topic_notice() {
     599    public function toggle_topic_notice() {
     600
     601        if ( $this->bail() ) return;
    571602
    572603        // Only proceed if GET is a topic toggle action
     
    640671     * @return array $columns bbPress topic columns
    641672     */
    642     function topics_column_headers( $columns ) {
     673    public function topics_column_headers( $columns ) {
     674
     675        if ( $this->bail() ) return $columns;
     676
    643677        $columns = array(
    644678            'cb'                    => '<input type="checkbox" />',
     
    682716    function topics_column_data( $column, $topic_id ) {
    683717
     718        if ( $this->bail() ) return;
     719
    684720        // Get topic forum ID
    685721        $forum_id = bbp_get_topic_forum_id( $topic_id );
     
    778814     * @return array $actions Actions
    779815     */
    780     function topics_row_actions( $actions, $topic ) {
     816    public function topics_row_actions( $actions, $topic ) {
     817
     818        if ( $this->bail() ) return $actions;
    781819
    782820        unset( $actions['inline hide-if-no-js'] );
     
    850888     * @return bool False. If post type is not topic or reply
    851889     */
    852     function filter_dropdown() {
     890    public function filter_dropdown() {
     891
     892        if ( $this->bail() ) return;
    853893
    854894        // Add Empty Spam button
     
    882922    function filter_post_rows( $query_vars ) {
    883923
     924        if ( $this->bail() ) return $query_vars;
     925
    884926        // Add post_parent query_var if one is present
    885927        if ( !empty( $_GET['bbp_forum_id'] ) ) {
     
    907949     * @return array
    908950     */
    909     function updated_messages( $messages ) {
     951    public function updated_messages( $messages ) {
    910952        global $post_ID;
     953
     954        if ( $this->bail() ) return $messages;
    911955
    912956        // URL for the current topic
     
    9741018 */
    9751019function bbp_admin_topics() {
    976     global $typenow;
    977 
    978     if ( bbp_get_topic_post_type() != $typenow )
    979         return;
    980 
    9811020    bbpress()->admin->topics = new BBP_Topics_Admin();
    9821021}
Note: See TracChangeset for help on using the changeset viewer.