Skip to:
Content

bbPress.org


Ignore:
Timestamp:
01/23/2018 11:26:56 PM (9 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/topics.php

    r6771 r6772  
    777777
    778778        /**
     779         * Returns an array of keys used to sort row actions
     780         *
     781         * @since 2.6.0 bbPress (r6771)
     782         *
     783         * @return array
     784         */
     785        private function get_row_action_sort_order() {
     786
     787                // Filter & return
     788                return (array) apply_filters( 'bbp_admin_topics_row_action_sort_order', array(
     789                        'edit',
     790                        'stick',
     791                        'approved',
     792                        'unapproved',
     793                        'closed',
     794                        'spam',
     795                        'trash',
     796                        'untrash',
     797                        'delete',
     798                        'view'
     799                ) );
     800        }
     801
     802        /**
    779803         * Returns an array of notice toggles
    780804         *
    … …  
    930954         * @since 2.0.0 bbPress (r2485)
    931955         *
    932          * @param array $actions Actions
    933          * @param array $topic Topic object
     956         * @param array  $actions Actions
     957         * @param object $topic Topic object
     958         *
    934959         * @return array $actions Actions
    935960         */
    936         public function row_actions( $actions, $topic ) {
    937 
     961        public function row_actions( $actions = array(), $topic = false ) {
     962
     963                // Disable quick edit (too much to do here)
    938964                unset( $actions['inline hide-if-no-js'] );
    939965
    … …  
    10141040                }
    10151041
    1016                 return $actions;
     1042                // Sort & return
     1043                return $this->sort_row_actions( $actions );
     1044        }
     1045
     1046        /**
     1047         * Sort row actions by key
     1048         *
     1049         * @since 2.6.0
     1050         *
     1051         * @param array $actions
     1052         *
     1053         * @return array
     1054         */
     1055        private function sort_row_actions( $actions = array() ) {
     1056
     1057                // Return value
     1058                $retval = array();
     1059
     1060                // Known row actions, in sort order
     1061                $known_actions = $this->get_row_action_sort_order();
     1062
     1063                // Sort known actions, and keep any unknown ones
     1064                foreach ( $known_actions as $key ) {
     1065                        if ( isset( $actions[ $key ] ) ) {
     1066                                $retval[ $key ] = $actions[ $key ];
     1067                                unset( $actions[ $key ] );
     1068                        }
     1069                }
     1070
     1071                // Combine & return
     1072                return $retval + $actions;
    10171073        }
    10181074
Note: See TracChangeset for help on using the changeset viewer.