Ticket #23421: 23421.3.diff
File 23421.3.diff, 8.6 KB (added by , 5 years ago) |
---|
-
src/wp-admin/includes/admin-filters.php
From 5231937c576b4d63a19e0e38f227c2c9e767ff24 Mon Sep 17 00:00:00 2001 From: Cory Hughart <cory@blackbird.digital> Date: Fri, 28 Feb 2020 14:08:30 -0500 Subject: [PATCH] initial implementation based off work by @jtsternberg --- src/wp-admin/includes/admin-filters.php | 3 + .../includes/class-wp-posts-list-table.php | 105 +++++++++++++++++- src/wp-includes/class-wp-taxonomy.php | 9 ++ src/wp-includes/taxonomy.php | 2 + 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php index 4e66b28bb8..cefc948ff0 100644
a b add_action( 'post_updated', array( 'WP_Privacy_Policy_Content', '_policy_page_up 148 148 149 149 // Append '(Draft)' to draft page titles in the privacy page dropdown. 150 150 add_filter( 'list_pages', '_wp_privacy_settings_filter_draft_page_titles', 10, 2 ); 151 152 // Sortable taxonomy columns 153 add_filter( 'posts_clauses', array( 'WP_Posts_List_Table', '_peform_sortable_taxonomy_columns_query' ), 10, 2 ); -
src/wp-admin/includes/class-wp-posts-list-table.php
diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index 3a8dd65936..6744a9c6e0 100644
a b class WP_Posts_List_Table extends WP_List_Table { 116 116 } 117 117 } 118 118 119 120 /** 121 * Performs column sorting for taxonomies registered with 'show_column_sortable'. 122 * 123 * @since 5.4.0 124 * 125 * @global wpdb $wpdb WordPress database abstraction object. 126 * 127 * @param array $clauses The list of clauses for the query. 128 * @param WP_Query $wp_query The WP_Query instance (passed by reference). 129 * @return string Modified clauses 130 */ 131 public static function _peform_sortable_taxonomy_columns_query( $clauses, $wp_query ) { 132 global $wpdb; 133 134 if ( ! isset( $wp_query->query['orderby'] ) ) { 135 return $clauses; 136 } 137 138 $taxonomies = self::get_sortable_taxonomy_columns( $wp_query->query['post_type'] ); 139 140 if ( empty( $taxonomies ) || ! is_array( $taxonomies ) ) { 141 return $clauses; 142 } 143 144 $sortable_taxonomies = array(); 145 foreach ( $taxonomies as $taxonomy ) { 146 if ( 'category' == $taxonomy ) 147 $column_key = 'categories'; 148 elseif ( 'post_tag' == $taxonomy ) 149 $column_key = 'tags'; 150 else 151 $column_key = 'taxonomy-' . $taxonomy; 152 153 $sortable_taxonomies[ $taxonomy ] = $column_key; 154 } 155 156 $key = array_search( $wp_query->query['orderby'], $sortable_taxonomies, true ); 157 158 if ( false === $key ) { 159 return $clauses; 160 } 161 162 $clauses['join'] .= " 163 LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id 164 LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id) 165 LEFT OUTER JOIN {$wpdb->terms} USING (term_id) 166 "; 167 $clauses['where'] = $wpdb->prepare( " AND taxonomy = '%s'", $key ); 168 $clauses['groupby'] = "object_id"; 169 $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) "; 170 $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC'; 171 172 return $clauses; 173 } 174 175 /** 176 * Get a list of all taxonomies registered as sortable. 177 * Passes through the "manage_taxonomies_for_{$post_type}_sortable_columns" filter. 178 * 179 * @since 5.4.0 180 * 181 * @param string $post_type Post type to retrieve Taxonomies 182 * @return array Array of sortable taxonomies 183 */ 184 public static function get_sortable_taxonomy_columns( $post_type ) { 185 $taxonomies = get_object_taxonomies( $post_type, 'objects' ); 186 $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true, 'show_column_sortable' => true ), 'and', 'name' ); 187 188 /** 189 * Filter the sortable taxonomy columns in the Posts list table. 190 * 191 * The dynamic portion of the hook name, `$post_type`, refers to the post 192 * type slug. 193 * 194 * @since 5.4.0 195 * 196 * @param array $taxonomies Array of taxonomies to enable sortable columns for. 197 * @param string $post_type The post type. 198 */ 199 $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_sortable_columns", $taxonomies ); 200 $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); 201 202 return $taxonomies; 203 } 204 119 205 /** 120 206 * Sets whether the table layout should be hierarchical or not. 121 207 * … … class WP_Posts_List_Table extends WP_List_Table { 689 775 * @return array 690 776 */ 691 777 protected function get_sortable_columns() { 692 returnarray(778 $sortables = array( 693 779 'title' => 'title', 694 780 'parent' => 'parent', 695 781 'comments' => 'comment_count', 696 782 'date' => array( 'date', true ), 697 783 ); 784 785 $taxonomies = self::get_sortable_taxonomy_columns( $this->screen->post_type ); 786 787 if ( ! empty( $taxonomies ) && is_array( $taxonomies ) ) { 788 foreach ( $taxonomies as $taxonomy ) { 789 if ( 'category' == $taxonomy ) 790 $column_key = 'categories'; 791 elseif ( 'post_tag' == $taxonomy ) 792 $column_key = 'tags'; 793 else 794 $column_key = 'taxonomy-' . $taxonomy; 795 796 $sortables[ $column_key ] = $column_key; 797 } 798 } 799 800 return $sortables; 698 801 } 699 802 700 803 /** -
src/wp-includes/class-wp-taxonomy.php
diff --git a/src/wp-includes/class-wp-taxonomy.php b/src/wp-includes/class-wp-taxonomy.php index 7cb35e9044..bdbfe21803 100644
a b final class WP_Taxonomy { 124 124 */ 125 125 public $show_admin_column = false; 126 126 127 /** 128 * Whether the admin column for the taxonomy on its post type listing screens is sortable. 129 * 130 * @since 5.4.0 131 * @var bool 132 */ 133 public $show_column_sortable = false; 134 127 135 /** 128 136 * The callback function for the meta box display. 129 137 * … … final class WP_Taxonomy { 269 277 'show_tagcloud' => null, 270 278 'show_in_quick_edit' => null, 271 279 'show_admin_column' => false, 280 'show_column_sortable' => false, 272 281 'meta_box_cb' => null, 273 282 'meta_box_sanitize_cb' => null, 274 283 'capabilities' => array(), -
src/wp-includes/taxonomy.php
diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 370cb46ad5..38851ab3ec 100644
a b function create_initial_taxonomies() { 67 67 'public' => true, 68 68 'show_ui' => true, 69 69 'show_admin_column' => true, 70 'show_column_sortable' => true, 70 71 '_builtin' => true, 71 72 'capabilities' => array( 72 73 'manage_terms' => 'manage_categories', … … function create_initial_taxonomies() { 90 91 'public' => true, 91 92 'show_ui' => true, 92 93 'show_admin_column' => true, 94 'show_column_sortable' => true, 93 95 '_builtin' => true, 94 96 'capabilities' => array( 95 97 'manage_terms' => 'manage_post_tags', -
src/wp-admin/includes/class-wp-posts-list-table.php
-- 2.23.0 From e7f9028de49328565e971805f902861b02bb8bed Mon Sep 17 00:00:00 2001 From: Cory Hughart <cory@blackbird.digital> Date: Fri, 28 Feb 2020 15:33:25 -0500 Subject: [PATCH] fix posts with no taxonomy assigned not appearing --- .../includes/class-wp-posts-list-table.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index 6744a9c6e0..dafe5ce7d2 100644
a b class WP_Posts_List_Table extends WP_List_Table { 159 159 return $clauses; 160 160 } 161 161 162 $clauses['join'] .= " 163 LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id 164 LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id) 165 LEFT OUTER JOIN {$wpdb->terms} USING (term_id) 166 "; 167 $clauses['where'] = $wpdb->prepare( " AND taxonomy = '%s'", $key ); 168 $clauses['groupby'] = "object_id"; 169 $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) "; 162 $clauses['join'] .= $wpdb->prepare( " 163 LEFT OUTER JOIN ( 164 SELECT object_id, taxonomy, name 165 FROM {$wpdb->term_relationships} 166 LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id) 167 LEFT OUTER JOIN {$wpdb->terms} USING (term_id) 168 WHERE taxonomy = '%s' 169 ) tax 170 ON {$wpdb->posts}.ID=tax.object_id 171 ", $key ); 172 $clauses['groupby'] = "{$wpdb->posts}.ID"; // term_taxonomy_id 173 $clauses['orderby'] = "GROUP_CONCAT(tax.name ORDER BY tax.name ASC) "; 170 174 $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC'; 175 $clauses['orderby'] .= ", post_title ASC"; 171 176 172 177 return $clauses; 173 178 }