Making WordPress.org

Changeset 13960


Ignore:
Timestamp:
08/09/2024 07:16:09 PM (2 years ago)
Author:
ryelle
Message:

Support HelpHub: Sync with Git WordPress/wporg-documentation-2022@bbe255c

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-helphub/inc/helphub-post-types/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-helphub/inc/helphub-post-types/classes/class-helphub-post-types-post-type.php

    r13934 r13960  
    128128                        add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
    129129
    130                         if ( 'edit.php' === $pagenow && isset( $_GET['post_type'] ) && $this->post_type === $_GET['post_type'] ) { // WPCS: input var ok; CSRF ok.
    131                                 add_filter(
    132                                         'manage_edit-' . $this->post_type . '_columns', array(
    133                                                 $this,
    134                                                 'register_custom_column_headings',
    135                                         ), 10, 1
    136                                 );
    137                                 add_action( 'manage_posts_custom_column', array( $this, 'register_custom_columns' ), 10, 2 );
     130                        if ( 'post' !== $this->post_type ) {
     131                                $screen_id = 'edit-' . $this->post_type;
     132                                add_filter( 'manage_' . $screen_id . '_columns', array( $this, 'register_custom_column_headings' ) );
     133                                add_filter( 'manage_' . $screen_id . '_sortable_columns', array( $this, 'register_custom_column_sorts' ) );
     134                                add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'register_custom_columns' ), 10, 2 );
    138135                        }
    139136                }
     
    234231                        case 'image':
    235232                                // Displays img tag.
     233                                // phpcs:ignore
    236234                                echo $this->get_image( $id, 40 );
    237                                 /* @codingStandardsIgnoreLine */
     235                                break;
     236                        case 'menu_order':
     237                                // Displays menu order value
     238                                // phpcs:ignore
     239                                echo get_post_field( 'menu_order', $id );
    238240                                break;
    239241                        default:
     
    253255         */
    254256        public function register_custom_column_headings( $defaults ) {
    255                 $new_columns = array();
     257                $new_columns = array(
     258                        'menu_order' => __( 'Order', 'wporg-forums' ),
     259                );
    256260
    257261                $last_item = array();
     
    277281                return $defaults;
    278282        } // End register_custom_column_headings()
     283
     284        /**
     285         * Enable sorting on columns.
     286         *
     287         * @param array $cols An array of sortable columns.
     288         * @return array Updated list of columns.
     289         */
     290        public function register_custom_column_sorts( $cols ) {
     291                $cols['menu_order'] = array(
     292                        'menu_order',
     293                        true,
     294                        __( 'Order', 'wporg-forums' ),
     295                        __( 'Table ordered by order.', 'wporg-forums' ),
     296                );
     297
     298                return $cols;
     299        } // End register_custom_column_sorts()
    279300
    280301        /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-helphub/inc/helphub-post-types/classes/class-helphub-post-types-taxonomy.php

    r8401 r13960  
    7373         * @access  public
    7474         * @since   1.3.0
    75          * @param   array $post_type The post type key.
     75         * @param   array  $post_type The post type key.
    7676         * @param   string $token     The taxonomy key.
    7777         * @param   string $singular  Singular name.
     
    9595
    9696                add_action( 'init', array( $this, 'register' ) );
     97
     98                if ( 'category' === $this->token ) {
     99                        add_action(
     100                                'load-edit-tags.php',
     101                                function() {
     102                                        $screen_id = 'edit-' . $this->token;
     103                                        add_filter( 'manage_' . $screen_id . '_columns', array( $this, 'register_custom_column_headings' ) );
     104                                        add_filter( 'manage_' . $screen_id . '_sortable_columns', array( $this, 'register_custom_column_sorts' ) );
     105                                        add_filter( 'manage_' . $this->token . '_custom_column', array( $this, 'register_custom_columns' ), 10, 3 );
     106
     107                                        add_action( 'pre_get_terms', array( $this, 'list_table_do_custom_sort' ) );
     108                                        add_action(
     109                                                'admin_head',
     110                                                function() {
     111                                                        echo '<style>table .column-sort_order{width: 5rem;}</style>';
     112                                                }
     113                                        );
     114                                }
     115                        );
     116                }
    97117        } // End __construct()
    98118
     
    162182                register_taxonomy( esc_attr( $this->token ), (array) $this->post_type, (array) $this->args );
    163183        } // End register()
     184
     185        /**
     186         * Add custom column headings for the "manage" screen of this post type.
     187         *
     188         * @param array $columns The default value.
     189         *
     190         * @return array
     191         */
     192        public function register_custom_column_headings( $columns ) {
     193                $new_columns = array(
     194                        'sort_order' => __( 'Order', 'wporg-forums' ),
     195                );
     196                $columns = array_merge( array_slice( $columns, 0, 1 ), $new_columns, array_slice( $columns, 1 ) );
     197                return $columns;
     198        }
     199
     200        /**
     201         * Enable sorting on columns.
     202         *
     203         * @param array $cols An array of sortable columns.
     204         * @return array Updated list of columns.
     205         */
     206        public function register_custom_column_sorts( $cols ) {
     207                $cols['sort_order'] = array(
     208                        'sort_order',
     209                        true,
     210                        __( 'Order', 'wporg-forums' ),
     211                        __( 'Table ordered by order.', 'wporg-forums' ),
     212                );
     213
     214                return $cols;
     215        } // End register_custom_column_sorts()
     216
     217        /**
     218         * Add custom columns for the "manage" screen of this post type.
     219         *
     220         * @access public
     221         *
     222         * @param string $value Filter content (value of column).
     223         * @param string $column_name The name of the column.
     224         * @param int    $id The ID.
     225         *
     226         * @since  1.0.0
     227         * @return void
     228         */
     229        public function register_custom_columns( $value, $column_name, $id ) {
     230                switch ( $column_name ) {
     231                        case 'sort_order':
     232                                // phpcs:ignore
     233                                echo get_term_meta( $id, 'sort_order', true );
     234                                break;
     235                        default:
     236                                break;
     237                }
     238        } // End register_custom_columns()
     239
     240        /**
     241         * Filter the term query if our custom sort is used.
     242         *
     243         * @param WP_Term_Query $term_query Current instance of WP_Term_Query (passed by reference).
     244         */
     245        public function list_table_do_custom_sort( $term_query ) {
     246                if ( isset( $term_query->query_vars['orderby'] ) && 'sort_order' === $term_query->query_vars['orderby'] ) {
     247                        $term_query->query_vars['orderby'] = 'meta_value_num';
     248                        $term_query->query_vars['meta_key'] = 'sort_order';
     249                }
     250        }
    164251} // End Class
Note: See TracChangeset for help on using the changeset viewer.