Changeset 13960 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-helphub/inc/helphub-post-types/classes/class-helphub-post-types-taxonomy.php
- Timestamp:
- 08/09/2024 07:16:09 PM (2 years ago)
- File:
-
- 1 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-taxonomy.php
r8401 r13960 73 73 * @access public 74 74 * @since 1.3.0 75 * @param array $post_type The post type key.75 * @param array $post_type The post type key. 76 76 * @param string $token The taxonomy key. 77 77 * @param string $singular Singular name. … … 95 95 96 96 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 } 97 117 } // End __construct() 98 118 … … 162 182 register_taxonomy( esc_attr( $this->token ), (array) $this->post_type, (array) $this->args ); 163 183 } // 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 } 164 251 } // End Class
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)