- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php
r41683 r42343 38 38 global $status, $page; 39 39 40 parent::__construct( array( 41 'plural' => 'themes', 42 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 43 ) ); 40 parent::__construct( 41 array( 42 'plural' => 'themes', 43 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 44 ) 45 ); 44 46 45 47 $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all'; 46 if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) )48 if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) ) { 47 49 $status = 'all'; 50 } 48 51 49 52 $page = $this->get_pagenum(); … … 51 54 $this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false; 52 55 53 if ( $this->is_site_themes ) 56 if ( $this->is_site_themes ) { 54 57 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; 55 }56 57 /** 58 *58 } 59 } 60 61 /** 59 62 * @return array 60 63 */ … … 65 68 66 69 /** 67 *68 70 * @return bool 69 71 */ 70 72 public function ajax_user_can() { 71 if ( $this->is_site_themes ) 73 if ( $this->is_site_themes ) { 72 74 return current_user_can( 'manage_sites' ); 73 else75 } else { 74 76 return current_user_can( 'manage_network_themes' ); 75 }76 77 /** 78 *77 } 78 } 79 80 /** 79 81 * @global string $status 80 82 * @global array $totals … … 98 100 * @param array $all An array of WP_Theme objects to display in the list table. 99 101 */ 100 'all' => apply_filters( 'all_themes', wp_get_themes() ),101 'search' => array(),102 'enabled' => array(),102 'all' => apply_filters( 'all_themes', wp_get_themes() ), 103 'search' => array(), 104 'enabled' => array(), 103 105 'disabled' => array(), 104 'upgrade' => array(),105 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),106 'upgrade' => array(), 107 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ), 106 108 ); 107 109 108 110 if ( $this->is_site_themes ) { 109 111 $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' ); 110 $allowed_where = 'site';112 $allowed_where = 'site'; 111 113 } else { 112 114 $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' ); 113 $allowed_where = 'network';115 $allowed_where = 'network'; 114 116 } 115 117 … … 124 126 if ( $maybe_update && isset( $current->response[ $key ] ) ) { 125 127 $themes['all'][ $key ]->update = true; 126 $themes['upgrade'][ $key ] = $themes['all'][ $key ];127 } 128 129 $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';128 $themes['upgrade'][ $key ] = $themes['all'][ $key ]; 129 } 130 131 $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled'; 130 132 $themes[ $filter ][ $key ] = $themes['all'][ $key ]; 131 133 } 132 134 133 135 if ( $s ) { 134 $status = 'search';136 $status = 'search'; 135 137 $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) ); 136 138 } 137 139 138 140 $totals = array(); 139 foreach ( $themes as $type => $list ) 141 foreach ( $themes as $type => $list ) { 140 142 $totals[ $type ] = count( $list ); 141 142 if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) ) 143 } 144 145 if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) { 143 146 $status = 'all'; 147 } 144 148 145 149 $this->items = $themes[ $status ]; … … 149 153 $total_this_page = $totals[ $status ]; 150 154 151 wp_localize_script( 'updates', '_wpUpdatesItemCounts', array( 152 'themes' => $totals, 153 'totals' => wp_get_update_data(), 154 ) ); 155 wp_localize_script( 156 'updates', '_wpUpdatesItemCounts', array( 157 'themes' => $totals, 158 'totals' => wp_get_update_data(), 159 ) 160 ); 155 161 156 162 if ( $orderby ) { 157 163 $orderby = ucfirst( $orderby ); 158 $order = strtoupper( $order );164 $order = strtoupper( $order ); 159 165 160 166 if ( $orderby === 'Name' ) { … … 169 175 $start = ( $page - 1 ) * $themes_per_page; 170 176 171 if ( $total_this_page > $themes_per_page ) 177 if ( $total_this_page > $themes_per_page ) { 172 178 $this->items = array_slice( $this->items, $start, $themes_per_page, true ); 173 174 $this->set_pagination_args( array( 175 'total_items' => $total_this_page, 176 'per_page' => $themes_per_page, 177 ) ); 179 } 180 181 $this->set_pagination_args( 182 array( 183 'total_items' => $total_this_page, 184 'per_page' => $themes_per_page, 185 ) 186 ); 178 187 } 179 188 … … 185 194 public function _search_callback( $theme ) { 186 195 static $term = null; 187 if ( is_null( $term ) ) 196 if ( is_null( $term ) ) { 188 197 $term = wp_unslash( $_REQUEST['s'] ); 198 } 189 199 190 200 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) { 191 201 // Don't mark up; Do translate. 192 if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) 202 if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) { 193 203 return true; 194 } 195 196 if ( false !== stripos( $theme->get_stylesheet(), $term ) ) 204 } 205 } 206 207 if ( false !== stripos( $theme->get_stylesheet(), $term ) ) { 197 208 return true; 198 199 if ( false !== stripos( $theme->get_template(), $term ) ) 209 } 210 211 if ( false !== stripos( $theme->get_template(), $term ) ) { 200 212 return true; 213 } 201 214 202 215 return false; … … 217 230 $b = $theme_b[ $orderby ]; 218 231 219 if ( $a == $b ) 232 if ( $a == $b ) { 220 233 return 0; 221 222 if ( 'DESC' === $order ) 234 } 235 236 if ( 'DESC' === $order ) { 223 237 return ( $a < $b ) ? 1 : -1; 224 else238 } else { 225 239 return ( $a < $b ) ? -1 : 1; 240 } 226 241 } 227 242 … … 237 252 238 253 /** 239 *240 254 * @return array 241 255 */ … … 249 263 250 264 /** 251 *252 265 * @return array 253 266 */ 254 267 protected function get_sortable_columns() { 255 268 return array( 256 'name' => 'name',269 'name' => 'name', 257 270 ); 258 271 } … … 270 283 271 284 /** 272 *273 285 * @global array $totals 274 286 * @global string $status … … 280 292 $status_links = array(); 281 293 foreach ( $totals as $type => $count ) { 282 if ( ! $count )294 if ( ! $count ) { 283 295 continue; 296 } 284 297 285 298 switch ( $type ) { … … 296 309 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); 297 310 break; 298 case 'broken' :311 case 'broken': 299 312 $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count ); 300 313 break; 301 314 } 302 315 303 if ( $this->is_site_themes ) 316 if ( $this->is_site_themes ) { 304 317 $url = 'site-themes.php?id=' . $this->site_id; 305 else318 } else { 306 319 $url = 'themes.php'; 320 } 307 321 308 322 if ( 'search' != $type ) { 309 $status_links[$type] = sprintf( "<a href='%s'%s>%s</a>", 310 esc_url( add_query_arg('theme_status', $type, $url) ), 323 $status_links[ $type ] = sprintf( 324 "<a href='%s'%s>%s</a>", 325 esc_url( add_query_arg( 'theme_status', $type, $url ) ), 311 326 ( $type === $status ) ? ' class="current" aria-current="page"' : '', 312 327 sprintf( $text, number_format_i18n( $count ) ) … … 327 342 328 343 $actions = array(); 329 if ( 'enabled' != $status ) 344 if ( 'enabled' != $status ) { 330 345 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ); 331 if ( 'disabled' != $status ) 346 } 347 if ( 'disabled' != $status ) { 332 348 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ); 349 } 333 350 if ( ! $this->is_site_themes ) { 334 if ( current_user_can( 'update_themes' ) ) 351 if ( current_user_can( 'update_themes' ) ) { 335 352 $actions['update-selected'] = __( 'Update' ); 336 if ( current_user_can( 'delete_themes' ) ) 353 } 354 if ( current_user_can( 'delete_themes' ) ) { 337 355 $actions['delete-selected'] = __( 'Delete' ); 356 } 338 357 } 339 358 return $actions; … … 343 362 */ 344 363 public function display_rows() { 345 foreach ( $this->items as $theme ) 364 foreach ( $this->items as $theme ) { 346 365 $this->single_row( $theme ); 366 } 347 367 } 348 368 … … 355 375 */ 356 376 public function column_cb( $theme ) { 357 $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name') );377 $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) ); 358 378 ?> 359 <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ) ?>" id="<?php echo $checkbox_id?>" />360 <label class="screen-reader-text" for="<?php echo $checkbox_id ?>" ><?php _e( 'Select' ) ?> <?php echo $theme->display( 'Name' )?></label>379 <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" /> 380 <label class="screen-reader-text" for="<?php echo $checkbox_id; ?>" ><?php _e( 'Select' ); ?> <?php echo $theme->display( 'Name' ); ?></label> 361 381 <?php 362 382 } … … 379 399 380 400 if ( $this->is_site_themes ) { 381 $url = "site-themes.php?id={$this->site_id}&";401 $url = "site-themes.php?id={$this->site_id}&"; 382 402 $allowed = $theme->is_allowed( 'site', $this->site_id ); 383 403 } else { 384 $url = 'themes.php?';404 $url = 'themes.php?'; 385 405 $allowed = $theme->is_allowed( 'network' ); 386 406 } … … 388 408 // Pre-order. 389 409 $actions = array( 390 'enable' => '',410 'enable' => '', 391 411 'disable' => '', 392 'delete' => ''412 'delete' => '', 393 413 ); 394 414 395 415 $stylesheet = $theme->get_stylesheet(); 396 $theme_key = urlencode( $stylesheet );416 $theme_key = urlencode( $stylesheet ); 397 417 398 418 if ( ! $allowed ) { 399 419 if ( ! $theme->errors() ) { 400 $url = add_query_arg( array( 401 'action' => 'enable', 402 'theme' => $theme_key, 403 'paged' => $page, 404 's' => $s, 405 ), $url ); 420 $url = add_query_arg( 421 array( 422 'action' => 'enable', 423 'theme' => $theme_key, 424 'paged' => $page, 425 's' => $s, 426 ), $url 427 ); 406 428 407 429 if ( $this->is_site_themes ) { … … 413 435 } 414 436 415 $actions['enable'] = sprintf( '<a href="%s" class="edit" aria-label="%s">%s</a>', 437 $actions['enable'] = sprintf( 438 '<a href="%s" class="edit" aria-label="%s">%s</a>', 416 439 esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ), 417 440 esc_attr( $aria_label ), … … 420 443 } 421 444 } else { 422 $url = add_query_arg( array( 423 'action' => 'disable', 424 'theme' => $theme_key, 425 'paged' => $page, 426 's' => $s, 427 ), $url ); 445 $url = add_query_arg( 446 array( 447 'action' => 'disable', 448 'theme' => $theme_key, 449 'paged' => $page, 450 's' => $s, 451 ), $url 452 ); 428 453 429 454 if ( $this->is_site_themes ) { … … 435 460 } 436 461 437 $actions['disable'] = sprintf( '<a href="%s" aria-label="%s">%s</a>', 462 $actions['disable'] = sprintf( 463 '<a href="%s" aria-label="%s">%s</a>', 438 464 esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ), 439 465 esc_attr( $aria_label ), … … 443 469 444 470 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) { 445 $url = add_query_arg( array( 446 'action' => 'delete-selected', 447 'checked[]' => $theme_key, 448 'theme_status' => $context, 449 'paged' => $page, 450 's' => $s, 451 ), 'themes.php' ); 471 $url = add_query_arg( 472 array( 473 'action' => 'delete-selected', 474 'checked[]' => $theme_key, 475 'theme_status' => $context, 476 'paged' => $page, 477 's' => $s, 478 ), 'themes.php' 479 ); 452 480 453 481 /* translators: %s: theme name */ 454 482 $aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) ); 455 483 456 $actions['delete'] = sprintf( '<a href="%s" class="delete" aria-label="%s">%s</a>', 484 $actions['delete'] = sprintf( 485 '<a href="%s" class="delete" aria-label="%s">%s</a>', 457 486 esc_url( wp_nonce_url( $url, 'bulk-themes' ) ), 458 487 esc_attr( $aria_label ), … … 527 556 528 557 $class = ! $allowed ? 'inactive' : 'active'; 529 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) 558 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) { 530 559 $class .= ' update'; 560 } 531 561 532 562 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div> … … 536 566 $theme_meta = array(); 537 567 538 if ( $theme->get( 'Version') ) {539 $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version') );540 } 541 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author') );542 543 if ( $theme->get( 'ThemeURI') ) {568 if ( $theme->get( 'Version' ) ) { 569 $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) ); 570 } 571 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) ); 572 573 if ( $theme->get( 'ThemeURI' ) ) { 544 574 /* translators: %s: theme name */ 545 575 $aria_label = sprintf( __( 'Visit %s homepage' ), $theme->display( 'Name' ) ); 546 576 547 $theme_meta[] = sprintf( '<a href="%s" aria-label="%s">%s</a>', 577 $theme_meta[] = sprintf( 578 '<a href="%s" aria-label="%s">%s</a>', 548 579 $theme->display( 'ThemeURI' ), 549 580 esc_attr( $aria_label ), … … 619 650 620 651 case 'name': 621 622 652 $active_theme_label = ''; 623 653 … … 633 663 634 664 /* In case this is a child theme, label it properly */ 635 if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {665 if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) { 636 666 $active_theme_label = ' — ' . __( 'Active Child Theme' ); 637 667 } … … 642 672 $this->column_name( $item ); 643 673 644 echo "</td>";674 echo '</td>'; 645 675 break; 646 676 … … 658 688 $this->column_default( $item, $column_name ); 659 689 660 echo "</td>";690 echo '</td>'; 661 691 break; 662 692 } … … 686 716 } 687 717 688 printf( '<tr class="%s" data-slug="%s">', 718 printf( 719 '<tr class="%s" data-slug="%s">', 689 720 esc_attr( $class ), 690 721 esc_attr( $stylesheet ) … … 693 724 $this->single_row_columns( $theme ); 694 725 695 echo "</tr>";696 697 if ( $this->is_site_themes ) 726 echo '</tr>'; 727 728 if ( $this->is_site_themes ) { 698 729 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' ); 730 } 699 731 700 732 /**
Note: See TracChangeset
for help on using the changeset viewer.