Skip to:
Content

bbPress.org


Ignore:
Timestamp:
01/23/2018 11:26:56 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Admin: enforce row-action order for forums, topics, and replies.

This change introduces a known (and filterable) sort-order to row-action keys, allowing for a more logical flow to better match Posts, Pages, and other WordPress core objects.

With slight variations, the flow is: Edit, Stick(to front), Un/approve, Open/Close, Delete/Trash, Spam, View.

Previous to this change, these row_actions() filters were only appending or overwriting keys, which introduced an unnecessary administration variation with no real benefit.

File:
1 edited

Legend:

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

    r6771 r6772  
    596596
    597597    /**
     598     * Returns an array of keys used to sort row actions
     599     *
     600     * @since 2.6.0 bbPress (r6771)
     601     *
     602     * @return array
     603     */
     604    private function get_row_action_sort_order() {
     605
     606        // Filter & return
     607        return (array) apply_filters( 'bbp_admin_reply_row_action_sort_order', array(
     608            'edit',
     609            'approved',
     610            'unapproved',
     611            'spam',
     612            'trash',
     613            'untrash',
     614            'delete',
     615            'view'
     616        ) );
     617    }
     618
     619    /**
    598620     * Returns an array of notice toggles
    599621     *
     
    754776     * @since 2.0.0 bbPress (r2577)
    755777     *
    756      * @param array $actions Actions
    757      * @param array $reply Reply object
     778     * @param array  $actions Actions
     779     * @param object $reply Topic object
    758780     *
    759781     * @return array $actions Actions
    760782     */
    761     public function row_actions( $actions, $reply ) {
    762 
     783    public function row_actions( $actions = array(), $reply = false ) {
     784
     785        // Disable quick edit (too much to do here)
    763786        unset( $actions['inline hide-if-no-js'] );
    764787
     
    819842        }
    820843
    821         return $actions;
     844        // Sort & return
     845        return $this->sort_row_actions( $actions );
     846    }
     847
     848    /**
     849     * Sort row actions by key
     850     *
     851     * @since 2.6.0
     852     *
     853     * @param array $actions
     854     *
     855     * @return array
     856     */
     857    private function sort_row_actions( $actions = array() ) {
     858
     859        // Return value
     860        $retval = array();
     861
     862        // Known row actions, in sort order
     863        $known_actions = $this->get_row_action_sort_order();
     864
     865        // Sort known actions, and keep any unknown ones
     866        foreach ( $known_actions as $key ) {
     867            if ( isset( $actions[ $key ] ) ) {
     868                $retval[ $key ] = $actions[ $key ];
     869                unset( $actions[ $key ] );
     870            }
     871        }
     872
     873        // Combine & return
     874        return $retval + $actions;
    822875    }
    823876
Note: See TracChangeset for help on using the changeset viewer.