Changeset 32755
- Timestamp:
- 06/13/2015 04:23:01 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-ms-sites-list-table.php
r32724 r32755 11 11 12 12 /** 13 * @since 4.3.0 14 * 15 * @var array 16 */ 17 public $status_list; 18 19 /** 13 20 * Constructor. 14 21 * … … 21 28 */ 22 29 public function __construct( $args = array() ) { 30 $this->status_list = array( 31 'archived' => array( 'site-archived', __( 'Archived' ) ), 32 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), 33 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), 34 'mature' => array( 'site-mature', __( 'Mature' ) ) 35 ); 36 23 37 parent::__construct( array( 24 38 'plural' => 'sites', … … 180 194 181 195 /** 182 *183 196 * @return array 184 197 */ … … 208 221 209 222 /** 210 *211 223 * @return array 212 224 */ … … 220 232 221 233 /** 234 * @since 4.3.0 235 * 236 * @param array $blog 237 */ 238 public function column_cb( $blog ) { 239 if ( ! is_main_site( $blog['blog_id'] ) ) : 240 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); 241 ?> 242 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php 243 printf( __( 'Select %s' ), $blogname ); 244 ?></label> 245 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" /> 246 <?php endif; 247 } 248 249 /** 250 * @since 4.3.0 222 251 * 223 252 * @global string $mode 224 */ 225 public function display_rows() { 253 * 254 * @param array $blog 255 */ 256 public function column_blogname( $blog ) { 226 257 global $mode; 227 258 228 $status_list = array( 229 'archived' => array( 'site-archived', __( 'Archived' ) ), 230 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), 231 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), 232 'mature' => array( 'site-mature', __( 'Mature' ) ) 233 ); 259 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); 260 $blog_states = array(); 261 reset( $this->status_list ); 262 263 foreach ( $this->status_list as $status => $col ) { 264 if ( $blog[ $status ] == 1 ) { 265 $blog_states[] = $col[1]; 266 } 267 } 268 $blog_state = ''; 269 if ( ! empty( $blog_states ) ) { 270 $state_count = count( $blog_states ); 271 $i = 0; 272 $blog_state .= ' - '; 273 foreach ( $blog_states as $state ) { 274 ++$i; 275 $sep = ( $i == $state_count ) ? '' : ', '; 276 $blog_state .= "<span class='post-state'>$state$sep</span>"; 277 } 278 } 279 280 ?> 281 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a> 282 <?php 283 if ( 'list' !== $mode ) { 284 switch_to_blog( $blog['blog_id'] ); 285 /* translators: 1: site name, 2: site tagline. */ 286 echo '<p>' . sprintf( __( '%1$s – <em>%2$s</em>' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>'; 287 restore_current_blog(); 288 } 289 } 290 291 /** 292 * @since 4.3.0 293 * 294 * @param array $blog 295 */ 296 public function column_lastupdated( $blog ) { 297 global $mode; 234 298 235 299 if ( 'list' == $mode ) { … … 239 303 } 240 304 305 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); 306 } 307 308 /** 309 * @since 4.3.0 310 * 311 * @param array $blog 312 */ 313 public function column_registered( $blog ) { 314 global $mode; 315 316 if ( 'list' == $mode ) { 317 $date = __( 'Y/m/d' ); 318 } else { 319 $date = __( 'Y/m/d g:i:s a' ); 320 } 321 322 if ( $blog['registered'] == '0000-00-00 00:00:00' ) { 323 echo '—'; 324 } else { 325 echo mysql2date( $date, $blog['registered'] ); 326 } 327 } 328 329 /** 330 * @since 4.3.0 331 * 332 * @param array $blog 333 */ 334 public function column_users( $blog ) { 335 $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' ); 336 if ( ! $user_count ) { 337 $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) ); 338 $user_count = count( $blog_users ); 339 unset( $blog_users ); 340 wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS ); 341 } 342 343 printf( 344 '<a href="%s">%s</a>', 345 esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ), 346 number_format_i18n( $user_count ) 347 ); 348 } 349 350 /** 351 * @since 4.3.0 352 * 353 * @param array $blog 354 */ 355 public function column_plugins( $blog ) { 356 if ( has_filter( 'wpmublogsaction' ) ) { 357 /** 358 * Fires inside the auxiliary 'Actions' column of the Sites list table. 359 * 360 * By default this column is hidden unless something is hooked to the action. 361 * 362 * @since MU 363 * 364 * @param int $blog_id The site ID. 365 */ 366 do_action( 'wpmublogsaction', $blog['blog_id'] ); 367 } 368 } 369 370 /** 371 * @since 4.3.0 372 * 373 * @param array $blog 374 * @param string $column_name 375 */ 376 public function column_default( $blog, $column_name ) { 377 /** 378 * Fires for each registered custom column in the Sites list table. 379 * 380 * @since 3.1.0 381 * 382 * @param string $column_name The name of the column to display. 383 * @param int $blog_id The site ID. 384 */ 385 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); 386 } 387 388 /** 389 * @since 4.3.0 390 * 391 * @param array $item 392 */ 393 public function single_row_columns( $item ) { 394 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); 395 396 foreach ( $columns as $column_name => $column_display_name ) { 397 $classes = "$column_name column-$column_name"; 398 if ( $primary === $column_name ) { 399 $classes .= ' has-row-actions column-primary'; 400 } 401 402 if ( in_array( $column_name, $hidden ) ) { 403 $classes .= ' hidden'; 404 } 405 406 $attributes = "class='$classes'"; 407 408 if ( 'cb' === $column_name ) { 409 echo '<th scope="row" class="check-column">'; 410 411 $this->column_cb( $item ); 412 413 echo '</th>'; 414 } elseif ( 'id' === $column_name ) { 415 ?> 416 <th scope="row"> 417 <?php echo $item['blog_id'] ?> 418 </th> 419 <?php 420 } elseif ( method_exists( $this, 'column_' . $column_name ) ) { 421 echo "<td $attributes>"; 422 423 echo call_user_func( array( $this, 'column_' . $column_name ), $item ); 424 425 echo $this->handle_row_actions( $item, $column_name, $primary ); 426 echo "</td>"; 427 } else { 428 echo "<td $attributes>"; 429 430 echo $this->column_default( $item, $column_name ); 431 432 echo $this->handle_row_actions( $item, $column_name, $primary ); 433 echo "</td>"; 434 } 435 } 436 } 437 438 /** 439 * 440 * @global string $mode 441 */ 442 public function display_rows() { 443 global $mode; 444 445 if ( 'list' == $mode ) { 446 $date = __( 'Y/m/d' ); 447 } else { 448 $date = __( 'Y/m/d g:i:s a' ); 449 } 450 241 451 foreach ( $this->items as $blog ) { 242 452 $class = ''; 243 reset( $status_list ); 244 245 $blog_states = array(); 246 foreach ( $status_list as $status => $col ) { 453 reset( $this->status_list ); 454 455 foreach ( $this->status_list as $status => $col ) { 247 456 if ( $blog[ $status ] == 1 ) { 248 457 $class = " class='{$col[0]}'"; 249 $blog_states[] = $col[1];250 458 } 251 459 } 252 $blog_state = ''; 253 if ( ! empty( $blog_states ) ) { 254 $state_count = count( $blog_states ); 255 $i = 0; 256 $blog_state .= ' - '; 257 foreach ( $blog_states as $state ) { 258 ++$i; 259 ( $i == $state_count ) ? $sep = '' : $sep = ', '; 260 $blog_state .= "<span class='post-state'>$state$sep</span>"; 261 } 262 } 460 263 461 echo "<tr{$class}>"; 264 462 265 $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); 266 267 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); 268 269 foreach ( $columns as $column_name => $column_display_name ) { 270 $classes = "$column_name column-$column_name"; 271 if ( $primary === $column_name ) { 272 $classes .= ' has-row-actions column-primary'; 273 } 274 275 if ( in_array( $column_name, $hidden ) ) { 276 $classes .= ' hidden'; 277 } 278 279 $attributes = "class='$classes'"; 280 281 if ( 'cb' === $column_name ) { 282 ?> 283 <th scope="row" class="check-column"> 284 <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?> 285 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label> 286 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" /> 287 <?php endif; ?> 288 </th> 289 <?php 290 } elseif ( 'id' === $column_name ) { 291 ?> 292 <th scope="row"> 293 <?php echo $blog['blog_id'] ?> 294 </th> 295 <?php 296 } else { 297 echo "<td $attributes>"; 298 299 switch ( $column_name ) { 300 case 'blogname': 301 ?> 302 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a> 303 <?php 304 if ( 'list' != $mode ) { 305 switch_to_blog( $blog['blog_id'] ); 306 /* translators: 1: site name, 2: site tagline. */ 307 echo '<p>' . sprintf( __( '%1$s – <em>%2$s</em>' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>'; 308 restore_current_blog(); 309 } 310 break; 311 312 case 'lastupdated': 313 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); 314 break; 315 316 case 'registered': 317 if ( $blog['registered'] == '0000-00-00 00:00:00' ) { 318 echo '—'; 319 } else { 320 echo mysql2date( $date, $blog['registered'] ); 321 } 322 break; 323 324 case 'users': 325 if ( ! $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' ) ) { 326 $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) ); 327 $user_count = count( $blog_users ); 328 unset( $blog_users ); 329 wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS ); 330 } 331 332 printf( 333 '<a href="%s">%s</a>', 334 esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ), 335 number_format_i18n( $user_count ) 336 ); 337 break; 338 339 case 'plugins': 340 if ( has_filter( 'wpmublogsaction' ) ) { 341 /** 342 * Fires inside the auxiliary 'Actions' column of the Sites list table. 343 * 344 * By default this column is hidden unless something is hooked to the action. 345 * 346 * @since MU 347 * 348 * @param int $blog_id The site ID. 349 */ 350 do_action( 'wpmublogsaction', $blog['blog_id'] ); 351 } 352 break; 353 354 default: 355 /** 356 * Fires for each registered custom column in the Sites list table. 357 * 358 * @since 3.1.0 359 * 360 * @param string $column_name The name of the column to display. 361 * @param int $blog_id The site ID. 362 */ 363 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); 364 break; 365 } 366 367 echo $this->handle_row_actions( $blog, $column_name, $primary ); 368 echo '</td>'; 369 } 370 } 371 ?> 372 </tr> 373 <?php 463 $this->single_row_columns( $blog ); 464 465 echo '</tr>'; 374 466 } 375 467 }
Note: See TracChangeset
for help on using the changeset viewer.