- 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-plugins-list-table.php
r42228 r42343 33 33 global $status, $page; 34 34 35 parent::__construct( array( 36 'plural' => 'plugins', 37 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 38 ) ); 35 parent::__construct( 36 array( 37 'plural' => 'plugins', 38 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 39 ) 40 ); 39 41 40 42 $status = 'all'; 41 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) 43 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) { 42 44 $status = $_REQUEST['plugin_status']; 43 44 if ( isset($_REQUEST['s']) ) 45 $_SERVER['REQUEST_URI'] = add_query_arg('s', wp_unslash($_REQUEST['s']) ); 45 } 46 47 if ( isset( $_REQUEST['s'] ) ) { 48 $_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) ); 49 } 46 50 47 51 $page = $this->get_pagenum(); … … 59 63 */ 60 64 public function ajax_user_can() { 61 return current_user_can('activate_plugins'); 62 } 63 64 /** 65 * 65 return current_user_can( 'activate_plugins' ); 66 } 67 68 /** 66 69 * @global string $status 67 70 * @global array $plugins … … 123 126 124 127 /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */ 125 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) 128 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) { 126 129 $plugins['dropins'] = get_dropins(); 130 } 127 131 128 132 if ( current_user_can( 'update_plugins' ) ) { … … 131 135 if ( isset( $current->response[ $plugin_file ] ) ) { 132 136 $plugins['all'][ $plugin_file ]['update'] = true; 133 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];137 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; 134 138 } 135 139 } … … 165 169 foreach ( $recently_activated as $key => $time ) { 166 170 if ( $time + WEEK_IN_SECONDS < time() ) { 167 unset( $recently_activated[ $key] );171 unset( $recently_activated[ $key ] ); 168 172 } 169 173 } … … 185 189 $plugins['upgrade'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data ); 186 190 } 187 188 191 } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) { 189 192 $plugins['all'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data ); … … 227 230 228 231 if ( strlen( $s ) ) { 229 $status = 'search';232 $status = 'search'; 230 233 $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) ); 231 234 } 232 235 233 236 $totals = array(); 234 foreach ( $plugins as $type => $list ) 237 foreach ( $plugins as $type => $list ) { 235 238 $totals[ $type ] = count( $list ); 236 237 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) ) 239 } 240 241 if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) { 238 242 $status = 'all'; 243 } 239 244 240 245 $this->items = array(); 241 246 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) { 242 247 // Translate, Don't Apply Markup, Sanitize HTML 243 $this->items[ $plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );248 $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); 244 249 } 245 250 … … 251 256 } 252 257 253 wp_localize_script( 'updates', '_wpUpdatesItemCounts', array( 254 'plugins' => $js_plugins, 255 'totals' => wp_get_update_data(), 256 ) ); 258 wp_localize_script( 259 'updates', '_wpUpdatesItemCounts', array( 260 'plugins' => $js_plugins, 261 'totals' => wp_get_update_data(), 262 ) 263 ); 257 264 258 265 if ( ! $orderby ) { … … 270 277 $start = ( $page - 1 ) * $plugins_per_page; 271 278 272 if ( $total_this_page > $plugins_per_page ) 279 if ( $total_this_page > $plugins_per_page ) { 273 280 $this->items = array_slice( $this->items, $start, $plugins_per_page ); 274 275 $this->set_pagination_args( array( 276 'total_items' => $total_this_page, 277 'per_page' => $plugins_per_page, 278 ) ); 281 } 282 283 $this->set_pagination_args( 284 array( 285 'total_items' => $total_this_page, 286 'per_page' => $plugins_per_page, 287 ) 288 ); 279 289 } 280 290 … … 307 317 global $orderby, $order; 308 318 309 $a = $plugin_a[ $orderby];310 $b = $plugin_b[ $orderby];311 312 if ( $a == $b ) 319 $a = $plugin_a[ $orderby ]; 320 $b = $plugin_b[ $orderby ]; 321 322 if ( $a == $b ) { 313 323 return 0; 324 } 314 325 315 326 if ( 'DESC' === $order ) { … … 321 332 322 333 /** 323 *324 334 * @global array $plugins 325 335 */ … … 336 346 echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>'; 337 347 } 338 } elseif ( ! empty( $plugins['all'] ) ) 348 } elseif ( ! empty( $plugins['all'] ) ) { 339 349 _e( 'No plugins found.' ); 340 else350 } else { 341 351 _e( 'You do not appear to have any plugins available at this time.' ); 352 } 342 353 } 343 354 … … 373 384 374 385 /** 375 *376 386 * @global string $status 377 387 * @return array … … 381 391 382 392 return array( 383 'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',393 'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '', 384 394 'name' => __( 'Plugin' ), 385 395 'description' => __( 'Description' ), … … 395 405 396 406 /** 397 *398 407 * @global array $totals 399 408 * @global string $status … … 405 414 $status_links = array(); 406 415 foreach ( $totals as $type => $count ) { 407 if ( ! $count )416 if ( ! $count ) { 408 417 continue; 418 } 409 419 410 420 switch ( $type ) { … … 433 443 434 444 if ( 'search' !== $type ) { 435 $status_links[$type] = sprintf( "<a href='%s'%s>%s</a>", 436 add_query_arg('plugin_status', $type, 'plugins.php'), 445 $status_links[ $type ] = sprintf( 446 "<a href='%s'%s>%s</a>", 447 add_query_arg( 'plugin_status', $type, 'plugins.php' ), 437 448 ( $type === $status ) ? ' class="current" aria-current="page"' : '', 438 449 sprintf( $text, number_format_i18n( $count ) ) 439 );450 ); 440 451 } 441 452 } … … 445 456 446 457 /** 447 *448 458 * @global string $status 449 459 * @return array … … 454 464 $actions = array(); 455 465 456 if ( 'active' != $status ) 466 if ( 'active' != $status ) { 457 467 $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' ); 458 459 if ( 'inactive' != $status && 'recent' != $status ) 468 } 469 470 if ( 'inactive' != $status && 'recent' != $status ) { 460 471 $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' ); 461 462 if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) { 463 if ( current_user_can( 'update_plugins' ) ) 472 } 473 474 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 475 if ( current_user_can( 'update_plugins' ) ) { 464 476 $actions['update-selected'] = __( 'Update' ); 465 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) 477 } 478 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { 466 479 $actions['delete-selected'] = __( 'Delete' ); 480 } 467 481 } 468 482 … … 477 491 global $status; 478 492 479 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) 493 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) { 480 494 return; 495 } 481 496 482 497 parent::bulk_actions( $which ); … … 490 505 global $status; 491 506 492 if ( ! in_array( $status, array('recently_activated', 'mustuse', 'dropins') ) )507 if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ) ) ) { 493 508 return; 509 } 494 510 495 511 echo '<div class="alignleft actions">'; … … 499 515 } elseif ( 'top' === $which && 'mustuse' === $status ) { 500 516 /* translators: %s: mu-plugins directory name */ 501 echo '<p>' . sprintf( __( 'Files in the %s directory are executed automatically.' ), 517 echo '<p>' . sprintf( 518 __( 'Files in the %s directory are executed automatically.' ), 502 519 '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>' 503 520 ) . '</p>'; 504 521 } elseif ( 'top' === $which && 'dropins' === $status ) { 505 522 /* translators: %s: wp-content directory name */ 506 echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ), 523 echo '<p>' . sprintf( 524 __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ), 507 525 '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>' 508 526 ) . '</p>'; … … 515 533 */ 516 534 public function current_action() { 517 if ( isset( $_POST['clear-recent-list']) )535 if ( isset( $_POST['clear-recent-list'] ) ) { 518 536 return 'clear-recent-list'; 537 } 519 538 520 539 return parent::current_action(); … … 522 541 523 542 /** 524 *525 543 * @global string $status 526 544 */ … … 528 546 global $status; 529 547 530 if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) 548 if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) { 531 549 return; 532 533 foreach ( $this->items as $plugin_file => $plugin_data ) 550 } 551 552 foreach ( $this->items as $plugin_file => $plugin_data ) { 534 553 $this->single_row( array( $plugin_file, $plugin_data ) ); 554 } 535 555 } 536 556 … … 547 567 548 568 list( $plugin_file, $plugin_data ) = $item; 549 $context = $status;550 $screen = $this->screen;569 $context = $status; 570 $screen = $this->screen; 551 571 552 572 // Pre-order. 553 573 $actions = array( 554 574 'deactivate' => '', 555 'activate' => '',556 'details' => '',557 'delete' => '',575 'activate' => '', 576 'details' => '', 577 'delete' => '', 558 578 ); 559 579 560 580 // Do not restrict by default 561 581 $restrict_network_active = false; 562 $restrict_network_only = false;582 $restrict_network_only = false; 563 583 564 584 if ( 'mustuse' === $context ) { 565 585 $is_active = true; 566 586 } elseif ( 'dropins' === $context ) { 567 $dropins = _get_dropins();587 $dropins = _get_dropins(); 568 588 $plugin_name = $plugin_file; 569 if ( $plugin_file != $plugin_data['Name'] ) 589 if ( $plugin_file != $plugin_data['Name'] ) { 570 590 $plugin_name .= '<br/>' . $plugin_data['Name']; 591 } 571 592 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant 572 $is_active = true;593 $is_active = true; 573 594 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 574 595 } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true 575 $is_active = true;596 $is_active = true; 576 597 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 577 598 } else { 578 $is_active = false;599 $is_active = false; 579 600 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' . 580 601 /* translators: 1: drop-in constant name, 2: wp-config.php */ 581 sprintf( __( 'Requires %1$s in %2$s file.' ), 602 sprintf( 603 __( 'Requires %1$s in %2$s file.' ), 582 604 "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>", 583 605 '<code>wp-config.php</code>' 584 606 ) . '</p>'; 585 607 } 586 if ( $plugin_data['Description'] ) 608 if ( $plugin_data['Description'] ) { 587 609 $description .= '<p>' . $plugin_data['Description'] . '</p>'; 610 } 588 611 } else { 589 612 if ( $screen->in_admin( 'network' ) ) { 590 613 $is_active = is_plugin_active_for_network( $plugin_file ); 591 614 } else { 592 $is_active = is_plugin_active( $plugin_file );615 $is_active = is_plugin_active( $plugin_file ); 593 616 $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) ); 594 $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );617 $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); 595 618 } 596 619 … … 600 623 /* translators: %s: plugin name */ 601 624 $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>'; 602 }625 } 603 626 } else { 604 627 if ( current_user_can( 'manage_network_plugins' ) ) { … … 636 659 } 637 660 } // end if $is_active 638 639 661 } // end if $screen->in_admin( 'network' ) 640 641 662 } // end if $context 642 663 … … 716 737 } 717 738 718 $class = $is_active ? 'active' : 'inactive';719 $checkbox_id = "checkbox_" . md5($plugin_data['Name']);739 $class = $is_active ? 'active' : 'inactive'; 740 $checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] ); 720 741 if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) { 721 742 $checkbox = ''; 722 743 } else { 723 $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"744 $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . '</label>' 724 745 . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />"; 725 746 } … … 729 750 } 730 751 731 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) 752 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) { 732 753 $class .= ' update'; 754 } 733 755 734 756 $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name ); 735 printf( '<tr class="%s" data-slug="%s" data-plugin="%s">', 757 printf( 758 '<tr class="%s" data-slug="%s" data-plugin="%s">', 736 759 esc_attr( $class ), 737 760 esc_attr( $plugin_slug ), … … 754 777 echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>"; 755 778 echo $this->row_actions( $actions, true ); 756 echo "</td>";779 echo '</td>'; 757 780 break; 758 781 case 'description': … … 764 787 765 788 $plugin_meta = array(); 766 if ( ! empty( $plugin_data['Version'] ) )789 if ( ! empty( $plugin_data['Version'] ) ) { 767 790 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); 768 if ( !empty( $plugin_data['Author'] ) ) { 791 } 792 if ( ! empty( $plugin_data['Author'] ) ) { 769 793 $author = $plugin_data['Author']; 770 if ( ! empty( $plugin_data['AuthorURI'] ) )794 if ( ! empty( $plugin_data['AuthorURI'] ) ) { 771 795 $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; 796 } 772 797 $plugin_meta[] = sprintf( __( 'By %s' ), $author ); 773 798 } … … 775 800 // Details link using API info, if available 776 801 if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) { 777 $plugin_meta[] = sprintf( '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>', 778 esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . 779 '&TB_iframe=true&width=600&height=550' ) ), 802 $plugin_meta[] = sprintf( 803 '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>', 804 esc_url( 805 network_admin_url( 806 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . 807 '&TB_iframe=true&width=600&height=550' 808 ) 809 ), 780 810 esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ), 781 811 esc_attr( $plugin_name ), … … 783 813 ); 784 814 } elseif ( ! empty( $plugin_data['PluginURI'] ) ) { 785 $plugin_meta[] = sprintf( '<a href="%s">%s</a>', 815 $plugin_meta[] = sprintf( 816 '<a href="%s">%s</a>', 786 817 esc_url( $plugin_data['PluginURI'] ), 787 818 __( 'Visit plugin site' ) … … 806 837 echo implode( ' | ', $plugin_meta ); 807 838 808 echo "</div></td>";839 echo '</div></td>'; 809 840 break; 810 841 default: … … 824 855 do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); 825 856 826 echo "</td>";827 } 828 } 829 830 echo "</tr>";857 echo '</td>'; 858 } 859 } 860 861 echo '</tr>'; 831 862 832 863 /**
Note: See TracChangeset
for help on using the changeset viewer.