Changeset 4214
- Timestamp:
- 10/11/2016 08:27:15 AM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 3 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; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
r3830 r4214 122 122 123 123 /** 124 * Syncs the list of committers from the svn_access table to a taxonomy. 125 * 126 * @static 127 * @param string $plugin_slug The Plugin Slug to sync. 128 */ 129 public static function sync_plugin_committers_with_taxonomy( $plugin_slug ) { 130 $post = Plugin_Directory::get_plugin_post( $plugin_slug ); 131 if ( ! $post ) { 132 return false; 133 } 134 135 $committer_slugs = array(); 136 foreach ( Tools::get_plugin_committers( $plugin_slug ) as $committer ) { 137 $user = get_user_by( 'login', $committer ); 138 if ( $user ) { 139 $committer_slugs[] = $user->user_nicename; 140 } 141 } 142 143 wp_set_post_terms( $post->ID, $committer_slugs, 'plugin_committers' ); 144 } 145 146 /** 124 147 * Grant a user RW access to a plugin. 125 148 * … … 149 172 } 150 173 151 wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' ); 152 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 153 154 return (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array( 174 $result = (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array( 155 175 'path' => "/{$plugin_slug}", 156 176 'user' => $user->user_login, 157 177 'access' => 'rw', 158 178 ) ); 179 180 wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' ); 181 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 182 Tools::sync_plugin_committers_with_taxonomy( $plugin_slug ); 183 184 return $result; 159 185 } 160 186 … … 180 206 } 181 207 182 wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' ); 183 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 184 185 return $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array( 208 $result = (bool) $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array( 186 209 'path' => "/{$plugin_slug}", 187 210 'user' => $user->user_login, 188 211 ) ); 212 213 wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' ); 214 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 215 Tools::sync_plugin_committers_with_taxonomy( $plugin_slug ); 216 217 return $result; 189 218 } 190 219 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r4212 r4214 149 149 // Update the contributors list 150 150 wp_set_post_terms( $plugin->ID, $readme->contributors, 'plugin_contributors' ); 151 152 // Update the committers list 153 Tools::sync_plugin_committers_with_taxonomy( $plugin->post_name ); 151 154 152 155 if ( in_array( 'adopt-me', $readme->tags ) ) {
Note: See TracChangeset
for help on using the changeset viewer.