Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/27/2016 10:45:16 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Admin: Implement new loading sequence for major admin components.

  • Introduce new bbp_current_screen sub-action
  • Hook forums/topics/replies into bbp_current_screen
  • Remove various bail() methods, which were fragile and terrible anyways
  • Revert r6178, thanks to order-of-operation issues with get_current_screen()
  • Remove Comments & Discussion metaboxes if comments is not explicitly supported

See #2959.

File:
1 edited

Legend:

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

    r6178 r6186  
    2828    private $post_type = '';
    2929
    30     /**
    31      * @var WP_Screen The current screen object
    32      */
    33     private $screen;
    34 
    3530    /** Functions *************************************************************/
    3631
     
    8075        add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
    8176        add_action( 'add_meta_boxes', array( $this, 'moderators_metabox' ) );
     77        add_action( 'add_meta_boxes', array( $this, 'comments_metabox'   ) );
    8278        add_action( 'save_post',      array( $this, 'save_meta_boxes'    ) );
    8379
     
    9389
    9490    /**
    95      * Should we bail out of this method?
    96      *
    97      * @since 2.1.0 bbPress (r4067)
    98      *
    99      * @return boolean
    100      */
    101     private function bail() {
    102 
    103         // Not for a post type
    104         if ( empty( $this->screen->post_type ) ) {
    105             return true;
    106         }
    107 
    108         // Not this post type
    109         if ( $this->post_type != $this->screen->post_type ) {
    110             return true;
    111         }
    112 
    113         return false;
    114     }
    115 
    116     /**
    11791     * Admin globals
    11892     *
     
    12397    private function setup_globals() {
    12498        $this->post_type = bbp_get_forum_post_type();
    125         $this->screen    = get_current_screen();
    12699    }
    127100
     
    137110    public function edit_help() {
    138111
    139         if ( $this->bail() ) {
    140             return;
    141         }
    142 
    143112        // Overview
    144         $this->screen->add_help_tab( array(
     113        get_current_screen()->add_help_tab( array(
    145114            'id'        => 'overview',
    146115            'title'     => __( 'Overview', 'bbpress' ),
     
    150119
    151120        // Screen Content
    152         $this->screen->add_help_tab( array(
     121        get_current_screen()->add_help_tab( array(
    153122            'id'        => 'screen-content',
    154123            'title'     => __( 'Screen Content', 'bbpress' ),
     
    163132
    164133        // Available Actions
    165         $this->screen->add_help_tab( array(
     134        get_current_screen()->add_help_tab( array(
    166135            'id'        => 'action-links',
    167136            'title'     => __( 'Available Actions', 'bbpress' ),
     
    176145
    177146        // Bulk Actions
    178         $this->screen->add_help_tab( array(
     147        get_current_screen()->add_help_tab( array(
    179148            'id'        => 'bulk-actions',
    180149            'title'     => __( 'Bulk Actions', 'bbpress' ),
     
    185154
    186155        // Help Sidebar
    187         $this->screen->set_help_sidebar(
     156        get_current_screen()->set_help_sidebar(
    188157            '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
    189158            '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>',    'bbpress' ) . '</p>' .
     
    197166     * @since 2.0.0 bbPress (r3119)
    198167     *
    199      * @uses $this->screen
     168     * @uses get_current_screen()
    200169     */
    201170    public function new_help() {
    202171
    203         if ( $this->bail() ) {
    204             return;
    205         }
    206 
    207172        $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>';
    208173
    209         $this->screen->add_help_tab( array(
     174        get_current_screen()->add_help_tab( array(
    210175            'id'      => 'customize-display',
    211176            'title'   => __( 'Customizing This Display', 'bbpress' ),
     
    213178        ) );
    214179
    215         $this->screen->add_help_tab( array(
     180        get_current_screen()->add_help_tab( array(
    216181            'id'      => 'title-forum-editor',
    217182            'title'   => __( 'Title and Forum Editor', 'bbpress' ),
     
    227192        }
    228193
    229         $this->screen->add_help_tab( array(
     194        get_current_screen()->add_help_tab( array(
    230195            'id'      => 'forum-attributes',
    231196            'title'   => __( 'Forum Attributes', 'bbpress' ),
     
    241206        ) );
    242207
    243         $this->screen->add_help_tab( array(
     208        get_current_screen()->add_help_tab( array(
    244209            'id'      => 'publish-box',
    245210            'title'   => __( 'Publish Box', 'bbpress' ),
     
    247212        ) );
    248213
    249         $this->screen->set_help_sidebar(
     214        get_current_screen()->set_help_sidebar(
    250215            '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
    251216            '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>',    'bbpress' ) . '</p>' .
     
    264229     */
    265230    public function attributes_metabox() {
    266 
    267         if ( $this->bail() ) {
    268             return;
    269         }
    270231
    271232        // Meta data
     
    293254    public function moderators_metabox() {
    294255
    295         if ( $this->bail() ) {
    296             return;
    297         }
    298 
    299256        // Bail if feature not active or user cannot assign moderators
    300257        if ( ! bbp_allow_forum_mods() || ! current_user_can( 'assign_moderators' ) ) {
     
    313270
    314271        do_action( 'bbp_forum_moderators_metabox' );
     272    }
     273
     274    /**
     275     * Remove comments & discussion metaboxes if comments are not supported
     276     *
     277     * @since 2.6.0 bbPress
     278     */
     279    public function comments_metabox() {
     280        if ( ! post_type_supports( $this->post_type, 'comments' ) ) {
     281            remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' );
     282            remove_meta_box( 'commentsdiv',      $this->post_type, 'normal' );
     283        }
    315284    }
    316285
     
    339308    public function save_meta_boxes( $forum_id ) {
    340309
    341         if ( $this->bail() ) {
    342             return $forum_id;
    343         }
    344 
    345310        // Bail if doing an autosave
    346311        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
     
    396361     */
    397362    public function admin_head() {
    398 
    399         if ( $this->bail() ) {
    400             return;
    401         } ?>
     363        ?>
    402364
    403365        <style type="text/css" media="screen">
     
    492454    public function toggle_forum() {
    493455
    494         if ( $this->bail() ) {
    495             return;
    496         }
    497 
    498456        // Only proceed if GET is a forum toggle action
    499457        if ( bbp_is_get_request() && ! empty( $_GET['forum_id'] ) && ! empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_forum_close' ) ) ) {
     
    560518    public function toggle_forum_notice() {
    561519
    562         if ( $this->bail() ) {
    563             return;
    564         }
    565 
    566520        // Only proceed if GET is a forum toggle action
    567521        if ( bbp_is_get_request() && ! empty( $_GET['bbp_forum_toggle_notice'] ) && in_array( $_GET['bbp_forum_toggle_notice'], array( 'opened', 'closed' ) ) && ! empty( $_GET['forum_id'] ) ) {
     
    621575     */
    622576    public function column_headers( $columns ) {
    623 
    624         if ( $this->bail() ) {
    625             return $columns;
    626         }
    627577
    628578        // Set list table column headers
     
    665615    public function column_data( $column, $forum_id ) {
    666616
    667         if ( $this->bail() ) {
    668             return;
    669         }
    670 
    671617        switch ( $column ) {
    672618            case 'bbp_forum_topic_count' :
     
    731677    public function row_actions( $actions, $forum ) {
    732678
    733         if ( $this->bail() ) {
    734             return $actions;
    735         }
    736 
    737679        unset( $actions['inline hide-if-no-js'] );
    738680
     
    774716    public function updated_messages( $messages ) {
    775717        global $post_ID;
    776 
    777         if ( $this->bail() ) {
    778             return $messages;
    779         }
    780718
    781719        // URL for the current forum
     
    867805 * @uses BBP_Forums_Admin
    868806 */
    869 function bbp_admin_forums() {
     807function bbp_admin_forums( $current_screen ) {
     808
     809    // Bail if not a forum screen
     810    if ( empty( $current_screen->post_type ) || ( bbp_get_forum_post_type() !== $current_screen->post_type ) ) {
     811        return;
     812    }
     813
     814    // Init the forums admin
    870815    bbpress()->admin->forums = new BBP_Forums_Admin();
    871816}
Note: See TracChangeset for help on using the changeset viewer.