Changeset 4214 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
- Timestamp:
- 10/11/2016 08:27:15 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r4213 r4214 40 40 add_action( 'init', array( $this, 'register_shortcodes' ) ); 41 41 add_action( 'widgets_init', array( $this, 'register_widgets' ) ); 42 add_filter( 'post_type_link', array( $this, ' package_link' ), 10, 2 );43 add_filter( 'term_link', array( $this, ' term_link' ), 10, 2 );44 add_action( 'pre_get_posts', array( $this, ' use_plugins_in_query' ) );42 add_filter( 'post_type_link', array( $this, 'filter_post_type_link' ), 10, 2 ); 43 add_filter( 'term_link', array( $this, 'filter_term_link' ), 10, 2 ); 44 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) ); 45 45 add_filter( 'rest_api_allowed_post_types', array( $this, 'filter_allowed_post_types' ) ); 46 46 add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) ); … … 209 209 ) ); 210 210 211 register_taxonomy( 'plugin_committers', array( 'plugin', 'force-count-to-include-all-post_status' ), array( 212 'hierarchical' => false, 213 'query_var' => 'plugin_committer', 214 'rewrite' => false, 215 'labels' => array( 216 'name' => __( 'Committers', 'wporg-plugins' ), 217 'singular_name' => __( 'Committer', 'wporg-plugins' ), 218 ), 219 'public' => true, 220 'show_ui' => true, 221 'show_admin_column' => false, 222 'capabilities' => array( 223 'assign_terms' => 'do_not_allow', 224 ), 225 ) ); 226 211 227 register_taxonomy( 'plugin_tags', array( 'plugin', 'force-count-to-include-all-post_status' ), array( 212 228 'hierarchical' => false, … … 430 446 * @return string 431 447 */ 432 public function package_link( $link, $post ) {448 public function filter_post_type_link( $link, $post ) { 433 449 if ( 'plugin' !== $post->post_type ) { 434 450 return $link; … … 445 461 * @return string|false 446 462 */ 447 public function term_link( $term_link, $term ) {463 public function filter_term_link( $term_link, $term ) { 448 464 if ( 'plugin_business_model' == $term->taxonomy ) { 449 465 return false; … … 460 476 * @param \WP_Query $wp_query The WordPress Query object. 461 477 */ 462 public function use_plugins_in_query( $wp_query ) {478 public function pre_get_posts( $wp_query ) { 463 479 if ( is_admin() ) { 464 480 return; 465 481 } 466 482 483 // Unless otherwise specified, we start off by querying for publish'd plugins. 467 484 if ( empty( $wp_query->query_vars['pagename'] ) && ( empty( $wp_query->query_vars['post_type'] ) || 'post' == $wp_query->query_vars['post_type'] ) ) { 468 485 $wp_query->query_vars['post_type'] = array( 'plugin' ); … … 470 487 } 471 488 489 // By default, if no query is made, we're querying /browse/featured/ 472 490 if ( empty( $wp_query->query ) ) { 473 491 $wp_query->query_vars['browse'] = 'featured'; 474 492 } 475 493 494 // Set up custom queries for the /browse/ URLs 476 495 switch ( $wp_query->get( 'browse' ) ) { 477 496 case 'favorites': … … 502 521 } 503 522 523 // For /browse/ requests, we conditionally need to avoid querying the taxonomy for most views (as it's handled in code above) 504 524 if ( isset( $wp_query->query['browse'] ) && 'beta' != $wp_query->query['browse'] && 'featured' != $wp_query->query['browse'] ) { 505 525 unset( $wp_query->query_vars['browse'] ); … … 517 537 } 518 538 539 // Holds a truthful value when viewing an author archive for the current user, or a plugin reviewer viewing an author archive 540 $viewing_own_author_archive = false; 541 542 // Author Archives need to be created 519 543 if ( isset( $wp_query->query['author_name'] ) || isset( $wp_query->query['author'] ) ) { 520 544 $user = isset( $wp_query->query['author_name'] ) ? $wp_query->query['author_name'] : (get_user_by( 'id', $wp_query->query['author'])->user_nicename); 521 545 522 $wp_query->query_vars['plugin_contributor'] = $user; 546 $viewing_own_author_archive = is_user_logged_in() && ( current_user_can( 'plugin_review' ) || 0 === strcasecmp( $user, wp_get_current_user()->user_nicename ) ); 547 548 // Author archives by default list plugins you're a contributor on. 549 $wp_query->query_vars['tax_query'] = array( 550 'relation' => 'OR', 551 array( 552 'taxonomy' => 'plugin_contributors', 553 'field' => 'slug', 554 'terms' => $user 555 ) 556 ); 557 558 // Author archives for self include plugins you're a committer on, not just publically a contributor 559 // Plugin Reviewers also see plugins you're a committer on here. 560 if ( $viewing_own_author_archive ) { 561 $wp_query->query_vars['tax_query'][] = array( 562 'taxonomy' => 'plugin_committers', 563 'field' => 'slug', 564 'terms' => $user 565 ); 566 } 567 568 // TODO: Make plugins owned by `post_author = $current_user_id` show up here when they're not-publish? 569 523 570 $wp_query->query_vars['orderby'] = 'post_title'; 524 571 $wp_query->query_vars['order'] = 'ASC'; … … 532 579 533 580 // For singular requests, or self-author profile requests allow restricted post_status items to show on the front-end. 534 if ( is_user_logged_in() && ( 535 !empty( $wp_query->query_vars['name'] ) || 536 ( 537 !empty( $wp_query->query_vars['plugin_contributor'] ) && 538 ( 539 current_user_can( 'plugin_review' ) || 540 0 === strcasecmp( $wp_query->query_vars['plugin_contributor'], wp_get_current_user()->user_nicename ) 541 ) 542 ) ) 543 ) { 581 if ( $viewing_own_author_archive || ( is_user_logged_in() && !empty( $wp_query->query_vars['name'] ) ) ) { 582 544 583 $wp_query->query_vars['post_status'] = array( 'pending', 'approved', 'publish', 'closed', 'disabled' ); 545 584 … … 756 795 switch ( $term->taxonomy ) { 757 796 case 'plugin_contributors': 797 case 'plugin_committers': 758 798 $user = get_user_by( 'slug', $term->slug ); 759 799 $name = $user->display_name;
Note: See TracChangeset
for help on using the changeset viewer.