Ticket #2847: 2847.diff
File 2847.diff, 6.6 KB (added by , 7 years ago) |
---|
-
functions.php
diff --git a/functions.php b/functions.php index 7b0b2ed..d05660a 100644
a b if ( ! isset( $content_width ) ) { 96 96 add_action( 'init', __NAMESPACE__ . '\\init' ); 97 97 add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' ); 98 98 99 /** 100 * @since 1.x.y Setup to filter wp-parser-since archives by change_type 101 */ 99 102 function init() { 100 103 101 104 register_nav_menus(); … … function init() { 118 121 add_filter( 'document_title_separator', __NAMESPACE__ . '\\theme_title_separator', 10, 2 ); 119 122 120 123 add_filter( 'syntaxhighlighter_htmlresult', __NAMESPACE__ . '\\syntaxhighlighter_htmlresult' ); 124 125 add_filter( 'query_vars', __NAMESPACE__ . '\\add_change_type_query_var' ); 126 add_filter( 'posts_pre_query', __NAMESPACE__ . '\\since_change_type_filter', 10, 2 ); 127 121 128 } 122 129 123 130 /** … … function widgets_init() { 199 206 200 207 /** 201 208 * @param \WP_Query $query 209 * 210 * @since 1.x.y wp-parser-since archive is now sorted by post_type then title; 211 * support for filtering wp-parser-since archives by whether a change was newly 212 * newly introduced or a modification from previous version(s) 202 213 */ 203 214 function pre_get_posts( $query ) { 204 215 … … function pre_get_posts( $query ) { 211 222 $query->set( 'wp-parser-source-file', str_replace( array( '.php', '/' ), array( '-php', '_' ), $query->query['wp-parser-source-file'] ) ); 212 223 } 213 224 225 if ( $query->is_main_query() && $query->is_tax() && $query->get( 'wp-parser-since' ) ) { 226 $query->set( 'orderby', 'type title' ); 227 $query->set( 'order', 'ASC' ); 228 $query->set( 'change_type', empty( $_REQUEST['change_type'] ) ? 'any' : $_REQUEST['change_type'] ); 229 } 230 214 231 // For search query modifications see DevHub_Search. 215 232 } 216 233 234 /** 235 * Add change_type to the public_query_vars 236 * 237 * @since 1.x.y 238 * 239 * @param array $public_query_vars The array of whitelisted query variables. 240 * @return array $public_query_vars with 'change_type' added 241 */ 242 function add_change_type_query_var( $public_query_vars ) 243 { 244 $public_query_vars['change_type'] = 'any'; 245 246 return $public_query_vars; 247 } 248 249 /** 250 * Filter wp-parser-since archive by the type of change 251 * 252 * @since 1.x.y 253 * 254 * @param array $posts 255 * @param WP_Query $query WP_Query object. 256 * @return array Posts which a specific type of change 257 */ 258 function since_change_type_filter( $posts, &$query ) { 259 global $wpdb; 260 261 $version = $query->get( 'wp-parser-since' ); 262 $change_type = $query->get( 'change_type' ); 263 264 if ( ! ( $query->is_archive() && $query->is_tax() && ! empty( $version ) ) || 265 ( empty( $change_type ) || 'any' === $change_type ) ) { 266 // bail, no need to filter 267 return $posts; 268 } 269 270 $posts = array(); 271 272 // strip the $limits so we get all changes for the specified version 273 $sql = preg_replace( '/\s+LIMIT.*$/', '', $query->request ); 274 275 // get all the posts that changed in the specified version 276 $_posts = $wpdb->get_results( $sql ); 277 278 foreach ( $_posts as $post ) { 279 $changelog_data = get_changelog_data( $post->ID ); 280 if ( empty( $changelog_data[$version] ) ) { 281 // should never happen... 282 continue; 283 } 284 285 // keep the post if fits the $change_type 286 if ( 'introduced' === $change_type && empty( $changelog_data[$version]['description'] ) ) { 287 $posts[] = $post; 288 } 289 elseif ( 'modified' === $change_type && ! empty( $changelog_data[$version]['description'] ) ) { 290 $posts[] = $post; 291 } 292 } 293 294 // grab only those changed posts for the current page 295 $paged = $query->get( 'paged' ); 296 $posts_per_page = $query->get( 'posts_per_page' ); 297 $offset = $posts_per_page * ( 0 === $paged ? 0 : $paged - 1 ); 298 $query->posts = array_slice( $posts, $offset, $posts_per_page ); 299 300 // set the pagination properties 301 // @todo unfortunately we can't call WP_Query::set_found_posts() 302 $query->post_count = count( $query->posts ); 303 $query->found_posts = count( $posts ); 304 $query->max_num_pages = ceil( $query->found_posts / $query->get( 'posts_per_page' ) ); 305 306 return $query->posts; 307 } 308 217 309 function register_nav_menus() { 218 310 219 311 \register_nav_menus( array( -
inc/template-tags.php
diff --git a/inc/template-tags.php b/inc/template-tags.php index 22272a6..26d4cb9 100644
a b namespace DevHub { 1449 1449 } 1450 1450 1451 1451 /** 1452 * Displays a post type filter dropdown on taxonomy pages. 1453 * 1454 * @return string HTML filter form. 1455 */ 1452 * Displays filter dropdowns for post type and change type on taxonomy pages. 1453 * 1454 * @since 1.x.y Added dropdown to filter by type of change when 'wp-parser-since' == $taxonomy 1455 * 1456 * @return string HTML filter form. 1457 */ 1456 1458 function taxonomy_archive_filter() { 1457 1459 global $wp_rewrite; 1458 1460 … … namespace DevHub { 1483 1485 $form .= "<input type='hidden' name='" . esc_attr( $taxonomy ) . "' value='" . esc_attr( $term ) . "'>"; 1484 1486 } 1485 1487 1486 $form .= "<label for=' archive-filter'>";1487 $form .= __( 'Filter by type:', 'wporg' ) . ' ';1488 $form .= "<label for='post-type-archive-filter'>"; 1489 $form .= __( 'Filter by post type:', 'wporg' ) . ' '; 1488 1490 $form .= '<select name="post_type[]" id="archive-filter">'; 1489 1491 $form .= $options . '</select></label>'; 1492 1493 if ( 'wp-parser-since' === $taxonomy ) { 1494 $change_types = array( 1495 'any' => __( 'Any change', 'wporg' ), 1496 'introduced' => __( 'Introduced', 'wporg' ), 1497 'modified' => __( 'Modified', 'wporg' ), 1498 ); 1499 $options = ''; 1500 $current_change_type = get_query_var( 'change_type' ); 1501 foreach ( $change_types as $change_type => $label ) { 1502 $selected = selected( $change_type, $current_change_type, false); 1503 $options .= "<option value='$change_type'$selected>$label</option>"; 1504 } 1505 1506 $form .= "<label for='change-type-archive-filter'>"; 1507 $form .= __( 'Filter by type of change:', 'wporg' ) . ' '; 1508 $form .= '<select name="change_type" id="change-type-archive-filter">'; 1509 $form .= $options . '</select></label>'; 1510 } 1511 1490 1512 $form .= "<input class='shiny-blue' type='submit' value='Filter' /></form>"; 1491 1513 1492 1514 echo $form; -
style.css
diff --git a/style.css b/style.css index 4143461..2af9201 100644
a b Theme URI: http://underscores.me/ 4 4 Author: Underscores.me 5 5 Author URI: http://underscores.me/ 6 6 Description: Description 7 Version: 1. 07 Version: 1.x.y 8 8 License: GNU General Public License 9 9 License URI: license.txt 10 10 Text Domain: wporg-developer -
stylesheets/main.css
diff --git a/stylesheets/main.css b/stylesheets/main.css index 9339d04..7765db2 100644
a b input { 1108 1108 font-size: 1.5rem; 1109 1109 } 1110 1110 1111 /* @since 1.x.y */ 1112 .devhub-wrap .archive-filter-form select { 1113 margin-right: 6px; 1114 } 1115 1111 1116 .devhub-wrap .archive-filter-form input[type="submit"] { 1112 1117 margin-left: .5em; 1113 1118 padding: 0.2em 0.5em;