Changeset 2798
- Timestamp:
- 03/24/2016 10:38:23 PM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
r2792 r2798 31 31 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) ); 32 32 add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ), 10, 2 ); 33 add_filter( 'views_edit-plugin', array( $this, 'list_table_views' ) );34 33 35 34 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); … … 163 162 $where = preg_replace( "!\s(\S+\.post_name IN .+?)\s*AND\s*(\s\S+\.post_author.+?)AND!i", ' ( $1 OR $2 ) AND', $where ); 164 163 return $where; 165 }166 167 public function list_table_views( $views ) {168 global $wp_query;169 if ( current_user_can( 'plugin_edit_others' ) ) {170 return $views;171 }172 // The only view the user needs, is their own.173 return array(174 sprintf(175 '<a href="#" class="current">%s</a>',176 sprintf(177 _nx(178 'Mine <span class="count">(%s)</span>',179 'Mine <span class="count">(%s)</span>',180 $wp_query->found_posts,181 'posts',182 'wporg-posts'183 ),184 number_format_i18n( $wp_query->found_posts )185 )186 )187 );188 164 } 189 165 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php
r2793 r2798 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Admin\List_Table; 3 use \WordPressdotorg\Plugin_Directory\Tools; 3 4 4 5 _get_list_table( 'WP_Posts_List_Table' ); … … 265 266 return $this->row_actions( $actions ); 266 267 } 268 269 /** 270 * Prepares list view links, including plugins that the current user has commit access to. 271 * 272 * @global array $locked_post_status This seems to be deprecated. 273 * @global array $avail_post_stati 274 * @return array 275 */ 276 protected function get_views() { 277 global $locked_post_status, $avail_post_stati, $wpdb; 278 279 if ( ! empty( $locked_post_status ) ) { 280 return array(); 281 } 282 283 $post_type = $this->screen->post_type; 284 $status_links = array(); 285 $num_posts = wp_count_posts( $post_type, 'readable' ); 286 $total_posts = array_sum( (array) $num_posts ); 287 $class = ''; 288 289 $current_user_id = get_current_user_id(); 290 $all_args = array( 'post_type' => $post_type ); 291 $mine = ''; 292 293 $plugins = Tools::get_users_write_access_plugins( get_current_user_id() ); 294 $plugins = array_map( 'sanitize_title_for_query', $plugins ); 295 $exclude_states = get_post_stati( array( 296 'show_in_admin_all_list' => false, 297 ) ); 298 299 $user_post_count = intval( $wpdb->get_var( $wpdb->prepare( " 300 SELECT COUNT( 1 ) 301 FROM $wpdb->posts 302 WHERE post_type = %s 303 AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' ) 304 AND ( post_author = %d OR post_name IN ( '" . implode( "','", $plugins ) . "' ) ) 305 ", $post_type, $current_user_id ) ) ); 306 307 // Subtract post types that are not included in the admin all list. 308 foreach ( $exclude_states as $state ) { 309 $total_posts -= $num_posts->$state; 310 } 311 312 if ( $user_post_count && $user_post_count !== $total_posts ) { 313 if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) { 314 $class = 'current'; 315 } 316 317 $mine_args = array( 318 'post_type' => $post_type, 319 'author' => $current_user_id 320 ); 321 322 $mine_inner_html = sprintf( 323 _nx( 324 'Mine <span class="count">(%s)</span>', 325 'Mine <span class="count">(%s)</span>', 326 $user_post_count, 327 'posts', 328 'wporg-posts' 329 ), 330 number_format_i18n( $user_post_count ) 331 ); 332 333 if ( ! current_user_can( 'plugin_edit_others' ) ) { 334 $status_links['mine'] = $this->get_edit_link( $mine_args, $mine_inner_html, 'current' );; 335 return $status_links; 336 } else { 337 $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class ); 338 } 339 340 $all_args['all_posts'] = 1; 341 $class = ''; 342 } 343 344 if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) { 345 $class = 'current'; 346 } 347 348 $all_inner_html = sprintf( 349 _nx( 350 'All <span class="count">(%s)</span>', 351 'All <span class="count">(%s)</span>', 352 $total_posts, 353 'posts', 354 'wporg-posts' 355 ), 356 number_format_i18n( $total_posts ) 357 ); 358 359 $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class ); 360 if ( $mine ) { 361 $status_links['mine'] = $mine; 362 } 363 364 foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) { 365 $class = ''; 366 367 $status_name = $status->name; 368 369 if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) { 370 continue; 371 } 372 373 if ( isset($_REQUEST['post_status']) && $status_name === $_REQUEST['post_status'] ) { 374 $class = 'current'; 375 } 376 377 $status_args = array( 378 'post_status' => $status_name, 379 'post_type' => $post_type, 380 ); 381 382 $status_label = sprintf( 383 translate_nooped_plural( $status->label_count, $num_posts->$status_name ), 384 number_format_i18n( $num_posts->$status_name ) 385 ); 386 387 $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class ); 388 } 389 390 if ( ! empty( $this->sticky_posts_count ) ) { 391 $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : ''; 392 393 $sticky_args = array( 394 'post_type' => $post_type, 395 'show_sticky' => 1 396 ); 397 398 $sticky_inner_html = sprintf( 399 _nx( 400 'Sticky <span class="count">(%s)</span>', 401 'Sticky <span class="count">(%s)</span>', 402 $this->sticky_posts_count, 403 'posts', 404 'wporg-posts' 405 ), 406 number_format_i18n( $this->sticky_posts_count ) 407 ); 408 409 $sticky_link = array( 410 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ) 411 ); 412 413 // Sticky comes after Publish, or if not listed, after All. 414 $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) ); 415 $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) ); 416 } 417 418 return $status_links; 419 } 267 420 }
Note: See TracChangeset
for help on using the changeset viewer.