[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * List Table API: WP_Plugins_List_Table class 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 3.1.0 8 */ 9 10 /** 11 * Core class used to implement displaying installed plugins in a list table. 12 * 13 * @since 3.1.0 14 * 15 * @see WP_List_Table 16 */ 17 class WP_Plugins_List_Table extends WP_List_Table { 18 /** 19 * Whether to show the auto-updates UI. 20 * 21 * @since 5.5.0 22 * 23 * @var bool True if auto-updates UI is to be shown, false otherwise. 24 */ 25 protected $show_autoupdates = true; 26 27 /** 28 * Constructor. 29 * 30 * @since 3.1.0 31 * 32 * @see WP_List_Table::__construct() for more information on default arguments. 33 * 34 * @global string $status 35 * @global int $page 36 * 37 * @param array $args An associative array of arguments. 38 */ 39 public function __construct( $args = array() ) { 40 global $status, $page; 41 42 parent::__construct( 43 array( 44 'plural' => 'plugins', 45 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 46 ) 47 ); 48 49 $allowed_statuses = array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled' ); 50 51 $status = 'all'; 52 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], $allowed_statuses, true ) ) { 53 $status = $_REQUEST['plugin_status']; 54 } 55 56 if ( isset( $_REQUEST['s'] ) ) { 57 $_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) ); 58 } 59 60 $page = $this->get_pagenum(); 61 62 $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'plugin' ) 63 && current_user_can( 'update_plugins' ) 64 && ( ! is_multisite() || $this->screen->in_admin( 'network' ) ); 65 } 66 67 /** 68 * @return array 69 */ 70 protected function get_table_classes() { 71 return array( 'widefat', $this->_args['plural'] ); 72 } 73 74 /** 75 * @return bool 76 */ 77 public function ajax_user_can() { 78 return current_user_can( 'activate_plugins' ); 79 } 80 81 /** 82 * @global string $status 83 * @global array $plugins 84 * @global array $totals 85 * @global int $page 86 * @global string $orderby 87 * @global string $order 88 * @global string $s 89 */ 90 public function prepare_items() { 91 global $status, $plugins, $totals, $page, $orderby, $order, $s; 92 93 $orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : ''; 94 $order = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : ''; 95 96 /** 97 * Filters the full array of plugins to list in the Plugins list table. 98 * 99 * @since 3.0.0 100 * 101 * @see get_plugins() 102 * 103 * @param array $all_plugins An array of plugins to display in the list table. 104 */ 105 $all_plugins = apply_filters( 'all_plugins', get_plugins() ); 106 107 $plugins = array( 108 'all' => $all_plugins, 109 'search' => array(), 110 'active' => array(), 111 'inactive' => array(), 112 'recently_activated' => array(), 113 'upgrade' => array(), 114 'mustuse' => array(), 115 'dropins' => array(), 116 'paused' => array(), 117 ); 118 if ( $this->show_autoupdates ) { 119 $auto_updates = (array) get_site_option( 'auto_update_plugins', array() ); 120 121 $plugins['auto-update-enabled'] = array(); 122 $plugins['auto-update-disabled'] = array(); 123 } 124 125 $screen = $this->screen; 126 127 if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) { 128 129 /** 130 * Filters whether to display the advanced plugins list table. 131 * 132 * There are two types of advanced plugins - must-use and drop-ins - 133 * which can be used in a single site or Multisite network. 134 * 135 * The $type parameter allows you to differentiate between the type of advanced 136 * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'. 137 * 138 * @since 3.0.0 139 * 140 * @param bool $show Whether to show the advanced plugins for the specified 141 * plugin type. Default true. 142 * @param string $type The plugin type. Accepts 'mustuse', 'dropins'. 143 */ 144 if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) { 145 $plugins['mustuse'] = get_mu_plugins(); 146 } 147 148 /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */ 149 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) { 150 $plugins['dropins'] = get_dropins(); 151 } 152 153 if ( current_user_can( 'update_plugins' ) ) { 154 $current = get_site_transient( 'update_plugins' ); 155 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 156 if ( isset( $current->response[ $plugin_file ] ) ) { 157 $plugins['all'][ $plugin_file ]['update'] = true; 158 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; 159 } 160 } 161 } 162 } 163 164 if ( ! $screen->in_admin( 'network' ) ) { 165 $show = current_user_can( 'manage_network_plugins' ); 166 /** 167 * Filters whether to display network-active plugins alongside plugins active for the current site. 168 * 169 * This also controls the display of inactive network-only plugins (plugins with 170 * "Network: true" in the plugin header). 171 * 172 * Plugins cannot be network-activated or network-deactivated from this screen. 173 * 174 * @since 4.4.0 175 * 176 * @param bool $show Whether to show network-active plugins. Default is whether the current 177 * user can manage network plugins (ie. a Super Admin). 178 */ 179 $show_network_active = apply_filters( 'show_network_active_plugins', $show ); 180 } 181 182 if ( $screen->in_admin( 'network' ) ) { 183 $recently_activated = get_site_option( 'recently_activated', array() ); 184 } else { 185 $recently_activated = get_option( 'recently_activated', array() ); 186 } 187 188 foreach ( $recently_activated as $key => $time ) { 189 if ( $time + WEEK_IN_SECONDS < time() ) { 190 unset( $recently_activated[ $key ] ); 191 } 192 } 193 194 if ( $screen->in_admin( 'network' ) ) { 195 update_site_option( 'recently_activated', $recently_activated ); 196 } else { 197 update_option( 'recently_activated', $recently_activated ); 198 } 199 200 $plugin_info = get_site_transient( 'update_plugins' ); 201 202 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 203 // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. 204 if ( isset( $plugin_info->response[ $plugin_file ] ) ) { 205 $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], array( 'update-supported' => true ), $plugin_data ); 206 } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) { 207 $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], array( 'update-supported' => true ), $plugin_data ); 208 } elseif ( empty( $plugin_data['update-supported'] ) ) { 209 $plugin_data['update-supported'] = false; 210 } 211 212 /* 213 * Create the payload that's used for the auto_update_plugin filter. 214 * This is the same data contained within $plugin_info->(response|no_update) however 215 * not all plugins will be contained in those keys, this avoids unexpected warnings. 216 */ 217 $filter_payload = array( 218 'id' => $plugin_file, 219 'slug' => '', 220 'plugin' => $plugin_file, 221 'new_version' => '', 222 'url' => '', 223 'package' => '', 224 'icons' => array(), 225 'banners' => array(), 226 'banners_rtl' => array(), 227 'tested' => '', 228 'requires_php' => '', 229 'compatibility' => new stdClass(), 230 ); 231 232 $filter_payload = (object) wp_parse_args( $plugin_data, $filter_payload ); 233 234 $auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, $filter_payload ); 235 236 if ( ! is_null( $auto_update_forced ) ) { 237 $plugin_data['auto-update-forced'] = $auto_update_forced; 238 } 239 240 $plugins['all'][ $plugin_file ] = $plugin_data; 241 // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade. 242 if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { 243 $plugins['upgrade'][ $plugin_file ] = $plugin_data; 244 } 245 246 // Filter into individual sections. 247 if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) { 248 if ( $show_network_active ) { 249 // On the non-network screen, show inactive network-only plugins if allowed. 250 $plugins['inactive'][ $plugin_file ] = $plugin_data; 251 } else { 252 // On the non-network screen, filter out network-only plugins as long as they're not individually active. 253 unset( $plugins['all'][ $plugin_file ] ); 254 } 255 } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) { 256 if ( $show_network_active ) { 257 // On the non-network screen, show network-active plugins if allowed. 258 $plugins['active'][ $plugin_file ] = $plugin_data; 259 } else { 260 // On the non-network screen, filter out network-active plugins. 261 unset( $plugins['all'][ $plugin_file ] ); 262 } 263 } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) ) 264 || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) { 265 /* 266 * On the non-network screen, populate the active list with plugins that are individually activated. 267 * On the network admin screen, populate the active list with plugins that are network-activated. 268 */ 269 $plugins['active'][ $plugin_file ] = $plugin_data; 270 271 if ( ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ) ) { 272 $plugins['paused'][ $plugin_file ] = $plugin_data; 273 } 274 } else { 275 if ( isset( $recently_activated[ $plugin_file ] ) ) { 276 // Populate the recently activated list with plugins that have been recently activated. 277 $plugins['recently_activated'][ $plugin_file ] = $plugin_data; 278 } 279 // Populate the inactive list with plugins that aren't activated. 280 $plugins['inactive'][ $plugin_file ] = $plugin_data; 281 } 282 283 if ( $this->show_autoupdates ) { 284 $enabled = in_array( $plugin_file, $auto_updates, true ) && $plugin_data['update-supported']; 285 if ( isset( $plugin_data['auto-update-forced'] ) ) { 286 $enabled = (bool) $plugin_data['auto-update-forced']; 287 } 288 289 if ( $enabled ) { 290 $plugins['auto-update-enabled'][ $plugin_file ] = $plugin_data; 291 } else { 292 $plugins['auto-update-disabled'][ $plugin_file ] = $plugin_data; 293 } 294 } 295 } 296 297 if ( strlen( $s ) ) { 298 $status = 'search'; 299 $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) ); 300 } 301 302 /** 303 * Filters the array of plugins for the list table. 304 * 305 * @since 6.3.0 306 * 307 * @param array[] $plugins An array of arrays of plugin data, keyed by context. 308 */ 309 $plugins = apply_filters( 'plugins_list', $plugins ); 310 311 $totals = array(); 312 foreach ( $plugins as $type => $list ) { 313 $totals[ $type ] = count( $list ); 314 } 315 316 if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) { 317 $status = 'all'; 318 } 319 320 $this->items = array(); 321 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) { 322 // Translate, don't apply markup, sanitize HTML. 323 $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); 324 } 325 326 $total_this_page = $totals[ $status ]; 327 328 $js_plugins = array(); 329 foreach ( $plugins as $key => $list ) { 330 $js_plugins[ $key ] = array_keys( $list ); 331 } 332 333 wp_localize_script( 334 'updates', 335 '_wpUpdatesItemCounts', 336 array( 337 'plugins' => $js_plugins, 338 'totals' => wp_get_update_data(), 339 ) 340 ); 341 342 if ( ! $orderby ) { 343 $orderby = 'Name'; 344 } else { 345 $orderby = ucfirst( $orderby ); 346 } 347 348 $order = strtoupper( $order ); 349 350 uasort( $this->items, array( $this, '_order_callback' ) ); 351 352 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 ); 353 354 $start = ( $page - 1 ) * $plugins_per_page; 355 356 if ( $total_this_page > $plugins_per_page ) { 357 $this->items = array_slice( $this->items, $start, $plugins_per_page ); 358 } 359 360 $this->set_pagination_args( 361 array( 362 'total_items' => $total_this_page, 363 'per_page' => $plugins_per_page, 364 ) 365 ); 366 } 367 368 /** 369 * @global string $s URL encoded search term. 370 * 371 * @param array $plugin 372 * @return bool 373 */ 374 public function _search_callback( $plugin ) { 375 global $s; 376 377 foreach ( $plugin as $value ) { 378 if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) { 379 return true; 380 } 381 } 382 383 return false; 384 } 385 386 /** 387 * @global string $orderby 388 * @global string $order 389 * @param array $plugin_a 390 * @param array $plugin_b 391 * @return int 392 */ 393 public function _order_callback( $plugin_a, $plugin_b ) { 394 global $orderby, $order; 395 396 $a = $plugin_a[ $orderby ]; 397 $b = $plugin_b[ $orderby ]; 398 399 if ( $a === $b ) { 400 return 0; 401 } 402 403 if ( 'DESC' === $order ) { 404 return strcasecmp( $b, $a ); 405 } else { 406 return strcasecmp( $a, $b ); 407 } 408 } 409 410 /** 411 * @global array $plugins 412 */ 413 public function no_items() { 414 global $plugins; 415 416 if ( ! empty( $_REQUEST['s'] ) ) { 417 $s = esc_html( urldecode( wp_unslash( $_REQUEST['s'] ) ) ); 418 419 /* translators: %s: Plugin search term. */ 420 printf( __( 'No plugins found for: %s.' ), '<strong>' . $s . '</strong>' ); 421 422 // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link. 423 if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) { 424 echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>'; 425 } 426 } elseif ( ! empty( $plugins['all'] ) ) { 427 _e( 'No plugins found.' ); 428 } else { 429 _e( 'No plugins are currently available.' ); 430 } 431 } 432 433 /** 434 * Displays the search box. 435 * 436 * @since 4.6.0 437 * 438 * @param string $text The 'submit' button label. 439 * @param string $input_id ID attribute value for the search input field. 440 */ 441 public function search_box( $text, $input_id ) { 442 if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { 443 return; 444 } 445 446 $input_id = $input_id . '-search-input'; 447 448 if ( ! empty( $_REQUEST['orderby'] ) ) { 449 echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; 450 } 451 if ( ! empty( $_REQUEST['order'] ) ) { 452 echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; 453 } 454 ?> 455 <p class="search-box"> 456 <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label> 457 <input type="search" id="<?php echo esc_attr( $input_id ); ?>" class="wp-filter-search" name="s" value="<?php _admin_search_query(); ?>" placeholder="<?php esc_attr_e( 'Search installed plugins...' ); ?>" /> 458 <?php submit_button( $text, 'hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?> 459 </p> 460 <?php 461 } 462 463 /** 464 * @global string $status 465 * 466 * @return string[] Array of column titles keyed by their column name. 467 */ 468 public function get_columns() { 469 global $status; 470 471 $columns = array( 472 'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ? '<input type="checkbox" />' : '', 473 'name' => __( 'Plugin' ), 474 'description' => __( 'Description' ), 475 ); 476 477 if ( $this->show_autoupdates && ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { 478 $columns['auto-updates'] = __( 'Automatic Updates' ); 479 } 480 481 return $columns; 482 } 483 484 /** 485 * @return array 486 */ 487 protected function get_sortable_columns() { 488 return array(); 489 } 490 491 /** 492 * @global array $totals 493 * @global string $status 494 * @return array 495 */ 496 protected function get_views() { 497 global $totals, $status; 498 499 $status_links = array(); 500 foreach ( $totals as $type => $count ) { 501 if ( ! $count ) { 502 continue; 503 } 504 505 switch ( $type ) { 506 case 'all': 507 /* translators: %s: Number of plugins. */ 508 $text = _nx( 509 'All <span class="count">(%s)</span>', 510 'All <span class="count">(%s)</span>', 511 $count, 512 'plugins' 513 ); 514 break; 515 case 'active': 516 /* translators: %s: Number of plugins. */ 517 $text = _n( 518 'Active <span class="count">(%s)</span>', 519 'Active <span class="count">(%s)</span>', 520 $count 521 ); 522 break; 523 case 'recently_activated': 524 /* translators: %s: Number of plugins. */ 525 $text = _n( 526 'Recently Active <span class="count">(%s)</span>', 527 'Recently Active <span class="count">(%s)</span>', 528 $count 529 ); 530 break; 531 case 'inactive': 532 /* translators: %s: Number of plugins. */ 533 $text = _n( 534 'Inactive <span class="count">(%s)</span>', 535 'Inactive <span class="count">(%s)</span>', 536 $count 537 ); 538 break; 539 case 'mustuse': 540 /* translators: %s: Number of plugins. */ 541 $text = _n( 542 'Must-Use <span class="count">(%s)</span>', 543 'Must-Use <span class="count">(%s)</span>', 544 $count 545 ); 546 break; 547 case 'dropins': 548 /* translators: %s: Number of plugins. */ 549 $text = _n( 550 'Drop-in <span class="count">(%s)</span>', 551 'Drop-ins <span class="count">(%s)</span>', 552 $count 553 ); 554 break; 555 case 'paused': 556 /* translators: %s: Number of plugins. */ 557 $text = _n( 558 'Paused <span class="count">(%s)</span>', 559 'Paused <span class="count">(%s)</span>', 560 $count 561 ); 562 break; 563 case 'upgrade': 564 /* translators: %s: Number of plugins. */ 565 $text = _n( 566 'Update Available <span class="count">(%s)</span>', 567 'Update Available <span class="count">(%s)</span>', 568 $count 569 ); 570 break; 571 case 'auto-update-enabled': 572 /* translators: %s: Number of plugins. */ 573 $text = _n( 574 'Auto-updates Enabled <span class="count">(%s)</span>', 575 'Auto-updates Enabled <span class="count">(%s)</span>', 576 $count 577 ); 578 break; 579 case 'auto-update-disabled': 580 /* translators: %s: Number of plugins. */ 581 $text = _n( 582 'Auto-updates Disabled <span class="count">(%s)</span>', 583 'Auto-updates Disabled <span class="count">(%s)</span>', 584 $count 585 ); 586 break; 587 } 588 589 if ( 'search' !== $type ) { 590 $status_links[ $type ] = array( 591 'url' => add_query_arg( 'plugin_status', $type, 'plugins.php' ), 592 'label' => sprintf( $text, number_format_i18n( $count ) ), 593 'current' => $type === $status, 594 ); 595 } 596 } 597 598 return $this->get_views_links( $status_links ); 599 } 600 601 /** 602 * @global string $status 603 * @return array 604 */ 605 protected function get_bulk_actions() { 606 global $status; 607 608 $actions = array(); 609 610 if ( 'active' !== $status ) { 611 $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? _x( 'Network Activate', 'plugin' ) : _x( 'Activate', 'plugin' ); 612 } 613 614 if ( 'inactive' !== $status && 'recent' !== $status ) { 615 $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? _x( 'Network Deactivate', 'plugin' ) : _x( 'Deactivate', 'plugin' ); 616 } 617 618 if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { 619 if ( current_user_can( 'update_plugins' ) ) { 620 $actions['update-selected'] = __( 'Update' ); 621 } 622 623 if ( current_user_can( 'delete_plugins' ) && ( 'active' !== $status ) ) { 624 $actions['delete-selected'] = __( 'Delete' ); 625 } 626 627 if ( $this->show_autoupdates ) { 628 if ( 'auto-update-enabled' !== $status ) { 629 $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' ); 630 } 631 if ( 'auto-update-disabled' !== $status ) { 632 $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' ); 633 } 634 } 635 } 636 637 return $actions; 638 } 639 640 /** 641 * @global string $status 642 * @param string $which 643 */ 644 public function bulk_actions( $which = '' ) { 645 global $status; 646 647 if ( in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { 648 return; 649 } 650 651 parent::bulk_actions( $which ); 652 } 653 654 /** 655 * @global string $status 656 * @param string $which 657 */ 658 protected function extra_tablenav( $which ) { 659 global $status; 660 661 if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ), true ) ) { 662 return; 663 } 664 665 echo '<div class="alignleft actions">'; 666 667 if ( 'recently_activated' === $status ) { 668 submit_button( __( 'Clear List' ), '', 'clear-recent-list', false ); 669 } elseif ( 'top' === $which && 'mustuse' === $status ) { 670 echo '<p>' . sprintf( 671 /* translators: %s: mu-plugins directory name. */ 672 __( 'Files in the %s directory are executed automatically.' ), 673 '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>' 674 ) . '</p>'; 675 } elseif ( 'top' === $which && 'dropins' === $status ) { 676 echo '<p>' . sprintf( 677 /* translators: %s: wp-content directory name. */ 678 __( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ), 679 '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>' 680 ) . '</p>'; 681 } 682 echo '</div>'; 683 } 684 685 /** 686 * @return string 687 */ 688 public function current_action() { 689 if ( isset( $_POST['clear-recent-list'] ) ) { 690 return 'clear-recent-list'; 691 } 692 693 return parent::current_action(); 694 } 695 696 /** 697 * @global string $status 698 */ 699 public function display_rows() { 700 global $status; 701 702 if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { 703 return; 704 } 705 706 foreach ( $this->items as $plugin_file => $plugin_data ) { 707 $this->single_row( array( $plugin_file, $plugin_data ) ); 708 } 709 } 710 711 /** 712 * @global string $status 713 * @global int $page 714 * @global string $s 715 * @global array $totals 716 * 717 * @param array $item 718 */ 719 public function single_row( $item ) { 720 global $status, $page, $s, $totals; 721 static $plugin_id_attrs = array(); 722 723 list( $plugin_file, $plugin_data ) = $item; 724 725 $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] ); 726 $plugin_id_attr = $plugin_slug; 727 728 // Ensure the ID attribute is unique. 729 $suffix = 2; 730 while ( in_array( $plugin_id_attr, $plugin_id_attrs, true ) ) { 731 $plugin_id_attr = "$plugin_slug-$suffix"; 732 ++$suffix; 733 } 734 735 $plugin_id_attrs[] = $plugin_id_attr; 736 737 $context = $status; 738 $screen = $this->screen; 739 740 // Pre-order. 741 $actions = array( 742 'deactivate' => '', 743 'activate' => '', 744 'details' => '', 745 'delete' => '', 746 ); 747 748 // Do not restrict by default. 749 $restrict_network_active = false; 750 $restrict_network_only = false; 751 752 $requires_php = isset( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : null; 753 $requires_wp = isset( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : null; 754 755 $compatible_php = is_php_version_compatible( $requires_php ); 756 $compatible_wp = is_wp_version_compatible( $requires_wp ); 757 758 $has_dependents = WP_Plugin_Dependencies::has_dependents( $plugin_file ); 759 $has_active_dependents = WP_Plugin_Dependencies::has_active_dependents( $plugin_file ); 760 $has_unmet_dependencies = WP_Plugin_Dependencies::has_unmet_dependencies( $plugin_file ); 761 $has_circular_dependency = WP_Plugin_Dependencies::has_circular_dependency( $plugin_file ); 762 763 if ( 'mustuse' === $context ) { 764 $is_active = true; 765 } elseif ( 'dropins' === $context ) { 766 $dropins = _get_dropins(); 767 $plugin_name = $plugin_file; 768 769 if ( $plugin_file !== $plugin_data['Name'] ) { 770 $plugin_name .= '<br />' . $plugin_data['Name']; 771 } 772 773 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant. 774 $is_active = true; 775 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 776 } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true. 777 $is_active = true; 778 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 779 } else { 780 $is_active = false; 781 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' . 782 sprintf( 783 /* translators: 1: Drop-in constant name, 2: wp-config.php */ 784 __( 'Requires %1$s in %2$s file.' ), 785 "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>", 786 '<code>wp-config.php</code>' 787 ) . '</p>'; 788 } 789 790 if ( $plugin_data['Description'] ) { 791 $description .= '<p>' . $plugin_data['Description'] . '</p>'; 792 } 793 } else { 794 if ( $screen->in_admin( 'network' ) ) { 795 $is_active = is_plugin_active_for_network( $plugin_file ); 796 } else { 797 $is_active = is_plugin_active( $plugin_file ); 798 $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) ); 799 $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); 800 } 801 802 if ( $screen->in_admin( 'network' ) ) { 803 if ( $is_active ) { 804 if ( current_user_can( 'manage_network_plugins' ) ) { 805 if ( $has_active_dependents ) { 806 $actions['deactivate'] = __( 'Deactivate' ) . 807 '<span class="screen-reader-text">' . 808 __( 'You cannot deactivate this plugin as other plugins require it.' ) . 809 '</span>'; 810 811 } else { 812 $deactivate_url = 'plugins.php?action=deactivate' . 813 '&plugin=' . urlencode( $plugin_file ) . 814 '&plugin_status=' . $context . 815 '&paged=' . $page . 816 '&s=' . $s; 817 818 $actions['deactivate'] = sprintf( 819 '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>', 820 wp_nonce_url( $deactivate_url, 'deactivate-plugin_' . $plugin_file ), 821 esc_attr( $plugin_id_attr ), 822 /* translators: %s: Plugin name. */ 823 esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), 824 _x( 'Network Deactivate', 'plugin' ) 825 ); 826 } 827 } 828 } else { 829 if ( current_user_can( 'manage_network_plugins' ) ) { 830 if ( $compatible_php && $compatible_wp ) { 831 if ( $has_unmet_dependencies ) { 832 $actions['activate'] = _x( 'Network Activate', 'plugin' ) . 833 '<span class="screen-reader-text">' . 834 __( 'You cannot activate this plugin as it has unmet requirements.' ) . 835 '</span>'; 836 } else { 837 $activate_url = 'plugins.php?action=activate' . 838 '&plugin=' . urlencode( $plugin_file ) . 839 '&plugin_status=' . $context . 840 '&paged=' . $page . 841 '&s=' . $s; 842 843 $actions['activate'] = sprintf( 844 '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>', 845 wp_nonce_url( $activate_url, 'activate-plugin_' . $plugin_file ), 846 esc_attr( $plugin_id_attr ), 847 /* translators: %s: Plugin name. */ 848 esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ), 849 _x( 'Network Activate', 'plugin' ) 850 ); 851 } 852 } else { 853 $actions['activate'] = sprintf( 854 '<span>%s</span>', 855 _x( 'Cannot Activate', 'plugin' ) 856 ); 857 } 858 } 859 860 if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) { 861 if ( $has_dependents && ! $has_circular_dependency ) { 862 $actions['delete'] = __( 'Delete' ) . 863 '<span class="screen-reader-text">' . 864 __( 'You cannot delete this plugin as other plugins require it.' ) . 865 '</span>'; 866 } else { 867 $delete_url = 'plugins.php?action=delete-selected' . 868 '&checked[]=' . urlencode( $plugin_file ) . 869 '&plugin_status=' . $context . 870 '&paged=' . $page . 871 '&s=' . $s; 872 873 $actions['delete'] = sprintf( 874 '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>', 875 wp_nonce_url( $delete_url, 'bulk-plugins' ), 876 esc_attr( $plugin_id_attr ), 877 /* translators: %s: Plugin name. */ 878 esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), 879 __( 'Delete' ) 880 ); 881 } 882 } 883 } 884 } else { 885 if ( $restrict_network_active ) { 886 $actions = array( 887 'network_active' => __( 'Network Active' ), 888 ); 889 } elseif ( $restrict_network_only ) { 890 $actions = array( 891 'network_only' => __( 'Network Only' ), 892 ); 893 } elseif ( $is_active ) { 894 if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) { 895 if ( $has_active_dependents ) { 896 $actions['deactivate'] = __( 'Deactivate' ) . 897 '<span class="screen-reader-text">' . 898 __( 'You cannot deactivate this plugin as other plugins depend on it.' ) . 899 '</span>'; 900 } else { 901 $deactivate_url = 'plugins.php?action=deactivate' . 902 '&plugin=' . urlencode( $plugin_file ) . 903 '&plugin_status=' . $context . 904 '&paged=' . $page . 905 '&s=' . $s; 906 907 $actions['deactivate'] = sprintf( 908 '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>', 909 wp_nonce_url( $deactivate_url, 'deactivate-plugin_' . $plugin_file ), 910 esc_attr( $plugin_id_attr ), 911 /* translators: %s: Plugin name. */ 912 esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), 913 __( 'Deactivate' ) 914 ); 915 } 916 } 917 918 if ( current_user_can( 'resume_plugin', $plugin_file ) && is_plugin_paused( $plugin_file ) ) { 919 $resume_url = 'plugins.php?action=resume' . 920 '&plugin=' . urlencode( $plugin_file ) . 921 '&plugin_status=' . $context . 922 '&paged=' . $page . 923 '&s=' . $s; 924 925 $actions['resume'] = sprintf( 926 '<a href="%s" id="resume-%s" class="resume-link" aria-label="%s">%s</a>', 927 wp_nonce_url( $resume_url, 'resume-plugin_' . $plugin_file ), 928 esc_attr( $plugin_id_attr ), 929 /* translators: %s: Plugin name. */ 930 esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ), 931 __( 'Resume' ) 932 ); 933 } 934 } else { 935 if ( current_user_can( 'activate_plugin', $plugin_file ) ) { 936 if ( $compatible_php && $compatible_wp ) { 937 if ( $has_unmet_dependencies ) { 938 $actions['activate'] = _x( 'Activate', 'plugin' ) . 939 '<span class="screen-reader-text">' . 940 __( 'You cannot activate this plugin as it has unmet requirements.' ) . 941 '</span>'; 942 } else { 943 $activate_url = 'plugins.php?action=activate' . 944 '&plugin=' . urlencode( $plugin_file ) . 945 '&plugin_status=' . $context . 946 '&paged=' . $page . 947 '&s=' . $s; 948 949 $actions['activate'] = sprintf( 950 '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>', 951 wp_nonce_url( $activate_url, 'activate-plugin_' . $plugin_file ), 952 esc_attr( $plugin_id_attr ), 953 /* translators: %s: Plugin name. */ 954 esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ), 955 _x( 'Activate', 'plugin' ) 956 ); 957 } 958 } else { 959 $actions['activate'] = sprintf( 960 '<span>%s</span>', 961 _x( 'Cannot Activate', 'plugin' ) 962 ); 963 } 964 } 965 966 if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) { 967 if ( $has_dependents && ! $has_circular_dependency ) { 968 $actions['delete'] = __( 'Delete' ) . 969 '<span class="screen-reader-text">' . 970 __( 'You cannot delete this plugin as other plugins require it.' ) . 971 '</span>'; 972 } else { 973 $delete_url = 'plugins.php?action=delete-selected' . 974 '&checked[]=' . urlencode( $plugin_file ) . 975 '&plugin_status=' . $context . 976 '&paged=' . $page . 977 '&s=' . $s; 978 979 $actions['delete'] = sprintf( 980 '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>', 981 wp_nonce_url( $delete_url, 'bulk-plugins' ), 982 esc_attr( $plugin_id_attr ), 983 /* translators: %s: Plugin name. */ 984 esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), 985 __( 'Delete' ) 986 ); 987 } 988 } 989 } // End if $is_active. 990 } // End if $screen->in_admin( 'network' ). 991 } // End if $context. 992 993 $actions = array_filter( $actions ); 994 995 if ( $screen->in_admin( 'network' ) ) { 996 997 /** 998 * Filters the action links displayed for each plugin in the Network Admin Plugins list table. 999 * 1000 * @since 3.1.0 1001 * 1002 * @param string[] $actions An array of plugin action links. By default this can include 1003 * 'activate', 'deactivate', and 'delete'. 1004 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1005 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1006 * and the {@see 'plugin_row_meta'} filter for the list 1007 * of possible values. 1008 * @param string $context The plugin context. By default this can include 'all', 1009 * 'active', 'inactive', 'recently_activated', 'upgrade', 1010 * 'mustuse', 'dropins', and 'search'. 1011 */ 1012 $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); 1013 1014 /** 1015 * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table. 1016 * 1017 * The dynamic portion of the hook name, `$plugin_file`, refers to the path 1018 * to the plugin file, relative to the plugins directory. 1019 * 1020 * @since 3.1.0 1021 * 1022 * @param string[] $actions An array of plugin action links. By default this can include 1023 * 'activate', 'deactivate', and 'delete'. 1024 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1025 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1026 * and the {@see 'plugin_row_meta'} filter for the list 1027 * of possible values. 1028 * @param string $context The plugin context. By default this can include 'all', 1029 * 'active', 'inactive', 'recently_activated', 'upgrade', 1030 * 'mustuse', 'dropins', and 'search'. 1031 */ 1032 $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); 1033 1034 } else { 1035 1036 /** 1037 * Filters the action links displayed for each plugin in the Plugins list table. 1038 * 1039 * @since 2.5.0 1040 * @since 2.6.0 The `$context` parameter was added. 1041 * @since 4.9.0 The 'Edit' link was removed from the list of action links. 1042 * 1043 * @param string[] $actions An array of plugin action links. By default this can include 1044 * 'activate', 'deactivate', and 'delete'. With Multisite active 1045 * this can also include 'network_active' and 'network_only' items. 1046 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1047 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1048 * and the {@see 'plugin_row_meta'} filter for the list 1049 * of possible values. 1050 * @param string $context The plugin context. By default this can include 'all', 1051 * 'active', 'inactive', 'recently_activated', 'upgrade', 1052 * 'mustuse', 'dropins', and 'search'. 1053 */ 1054 $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); 1055 1056 /** 1057 * Filters the list of action links displayed for a specific plugin in the Plugins list table. 1058 * 1059 * The dynamic portion of the hook name, `$plugin_file`, refers to the path 1060 * to the plugin file, relative to the plugins directory. 1061 * 1062 * @since 2.7.0 1063 * @since 4.9.0 The 'Edit' link was removed from the list of action links. 1064 * 1065 * @param string[] $actions An array of plugin action links. By default this can include 1066 * 'activate', 'deactivate', and 'delete'. With Multisite active 1067 * this can also include 'network_active' and 'network_only' items. 1068 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1069 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1070 * and the {@see 'plugin_row_meta'} filter for the list 1071 * of possible values. 1072 * @param string $context The plugin context. By default this can include 'all', 1073 * 'active', 'inactive', 'recently_activated', 'upgrade', 1074 * 'mustuse', 'dropins', and 'search'. 1075 */ 1076 $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); 1077 1078 } 1079 1080 $class = $is_active ? 'active' : 'inactive'; 1081 $checkbox_id = 'checkbox_' . md5( $plugin_file ); 1082 $disabled = ''; 1083 1084 if ( $has_dependents || $has_unmet_dependencies ) { 1085 $disabled = 'disabled'; 1086 } 1087 1088 if ( 1089 $restrict_network_active || 1090 $restrict_network_only || 1091 in_array( $status, array( 'mustuse', 'dropins' ), true ) || 1092 ! $compatible_php 1093 ) { 1094 $checkbox = ''; 1095 } else { 1096 $checkbox = sprintf( 1097 '<label class="label-covers-full-cell" for="%1$s">' . 1098 '<span class="screen-reader-text">%2$s</span></label>' . 1099 '<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" ' . $disabled . '/>', 1100 $checkbox_id, 1101 /* translators: Hidden accessibility text. %s: Plugin name. */ 1102 sprintf( __( 'Select %s' ), $plugin_data['Name'] ), 1103 esc_attr( $plugin_file ) 1104 ); 1105 } 1106 1107 if ( 'dropins' !== $context ) { 1108 $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>'; 1109 $plugin_name = $plugin_data['Name']; 1110 } 1111 1112 if ( 1113 ! empty( $totals['upgrade'] ) && 1114 ! empty( $plugin_data['update'] ) || 1115 ! $compatible_php || 1116 ! $compatible_wp 1117 ) { 1118 $class .= ' update'; 1119 } 1120 1121 $paused = ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ); 1122 1123 if ( $paused ) { 1124 $class .= ' paused'; 1125 } 1126 1127 if ( is_uninstallable_plugin( $plugin_file ) ) { 1128 $class .= ' is-uninstallable'; 1129 } 1130 1131 printf( 1132 '<tr class="%s" data-slug="%s" data-plugin="%s">', 1133 esc_attr( $class ), 1134 esc_attr( $plugin_slug ), 1135 esc_attr( $plugin_file ) 1136 ); 1137 1138 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); 1139 1140 $auto_updates = (array) get_site_option( 'auto_update_plugins', array() ); 1141 1142 foreach ( $columns as $column_name => $column_display_name ) { 1143 $extra_classes = ''; 1144 if ( in_array( $column_name, $hidden, true ) ) { 1145 $extra_classes = ' hidden'; 1146 } 1147 1148 switch ( $column_name ) { 1149 case 'cb': 1150 echo "<th scope='row' class='check-column'>$checkbox</th>"; 1151 break; 1152 case 'name': 1153 echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>"; 1154 echo $this->row_actions( $actions, true ); 1155 echo '</td>'; 1156 break; 1157 case 'description': 1158 $classes = 'column-description desc'; 1159 1160 echo "<td class='$classes{$extra_classes}'> 1161 <div class='plugin-description'>$description</div> 1162 <div class='$class second plugin-version-author-uri'>"; 1163 1164 $plugin_meta = array(); 1165 1166 if ( ! empty( $plugin_data['Version'] ) ) { 1167 /* translators: %s: Plugin version number. */ 1168 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); 1169 } 1170 1171 if ( ! empty( $plugin_data['Author'] ) ) { 1172 $author = $plugin_data['Author']; 1173 1174 if ( ! empty( $plugin_data['AuthorURI'] ) ) { 1175 $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; 1176 } 1177 1178 /* translators: %s: Plugin author name. */ 1179 $plugin_meta[] = sprintf( __( 'By %s' ), $author ); 1180 } 1181 1182 // Details link using API info, if available. 1183 if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) { 1184 $plugin_meta[] = sprintf( 1185 '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>', 1186 esc_url( 1187 network_admin_url( 1188 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . 1189 '&TB_iframe=true&width=600&height=550' 1190 ) 1191 ), 1192 /* translators: %s: Plugin name. */ 1193 esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ), 1194 esc_attr( $plugin_name ), 1195 __( 'View details' ) 1196 ); 1197 } elseif ( ! empty( $plugin_data['PluginURI'] ) ) { 1198 /* translators: %s: Plugin name. */ 1199 $aria_label = sprintf( __( 'Visit plugin site for %s' ), $plugin_name ); 1200 1201 $plugin_meta[] = sprintf( 1202 '<a href="%s" aria-label="%s">%s</a>', 1203 esc_url( $plugin_data['PluginURI'] ), 1204 esc_attr( $aria_label ), 1205 __( 'Visit plugin site' ) 1206 ); 1207 } 1208 1209 /** 1210 * Filters the array of row meta for each plugin in the Plugins list table. 1211 * 1212 * @since 2.8.0 1213 * 1214 * @param string[] $plugin_meta An array of the plugin's metadata, including 1215 * the version, author, author URI, and plugin URI. 1216 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1217 * @param array $plugin_data { 1218 * An array of plugin data. 1219 * 1220 * @type string $id Plugin ID, e.g. `w.org/plugins/[plugin-name]`. 1221 * @type string $slug Plugin slug. 1222 * @type string $plugin Plugin basename. 1223 * @type string $new_version New plugin version. 1224 * @type string $url Plugin URL. 1225 * @type string $package Plugin update package URL. 1226 * @type string[] $icons An array of plugin icon URLs. 1227 * @type string[] $banners An array of plugin banner URLs. 1228 * @type string[] $banners_rtl An array of plugin RTL banner URLs. 1229 * @type string $requires The version of WordPress which the plugin requires. 1230 * @type string $tested The version of WordPress the plugin is tested against. 1231 * @type string $requires_php The version of PHP which the plugin requires. 1232 * @type string $upgrade_notice The upgrade notice for the new plugin version. 1233 * @type bool $update-supported Whether the plugin supports updates. 1234 * @type string $Name The human-readable name of the plugin. 1235 * @type string $PluginURI Plugin URI. 1236 * @type string $Version Plugin version. 1237 * @type string $Description Plugin description. 1238 * @type string $Author Plugin author. 1239 * @type string $AuthorURI Plugin author URI. 1240 * @type string $TextDomain Plugin textdomain. 1241 * @type string $DomainPath Relative path to the plugin's .mo file(s). 1242 * @type bool $Network Whether the plugin can only be activated network-wide. 1243 * @type string $RequiresWP The version of WordPress which the plugin requires. 1244 * @type string $RequiresPHP The version of PHP which the plugin requires. 1245 * @type string $UpdateURI ID of the plugin for update purposes, should be a URI. 1246 * @type string $Title The human-readable title of the plugin. 1247 * @type string $AuthorName Plugin author's name. 1248 * @type bool $update Whether there's an available update. Default null. 1249 * } 1250 * @param string $status Status filter currently applied to the plugin list. Possible 1251 * values are: 'all', 'active', 'inactive', 'recently_activated', 1252 * 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 1253 * 'auto-update-enabled', 'auto-update-disabled'. 1254 */ 1255 $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); 1256 1257 echo implode( ' | ', $plugin_meta ); 1258 1259 echo '</div>'; 1260 1261 if ( $has_dependents ) { 1262 $this->add_dependents_to_dependency_plugin_row( $plugin_file ); 1263 } 1264 1265 if ( WP_Plugin_Dependencies::has_dependencies( $plugin_file ) ) { 1266 $this->add_dependencies_to_dependent_plugin_row( $plugin_file ); 1267 } 1268 1269 /** 1270 * Fires after plugin row meta. 1271 * 1272 * @since 6.5.0 1273 * 1274 * @param string $plugin_file Refer to {@see 'plugin_row_meta'} filter. 1275 * @param array $plugin_data Refer to {@see 'plugin_row_meta'} filter. 1276 */ 1277 do_action( 'after_plugin_row_meta', $plugin_file, $plugin_data ); 1278 1279 if ( $paused ) { 1280 $notice_text = __( 'This plugin failed to load properly and is paused during recovery mode.' ); 1281 1282 printf( '<p><span class="dashicons dashicons-warning"></span> <strong>%s</strong></p>', $notice_text ); 1283 1284 $error = wp_get_plugin_error( $plugin_file ); 1285 1286 if ( false !== $error ) { 1287 printf( '<div class="error-display"><p>%s</p></div>', wp_get_extension_error_description( $error ) ); 1288 } 1289 } 1290 1291 echo '</td>'; 1292 break; 1293 case 'auto-updates': 1294 if ( ! $this->show_autoupdates || in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { 1295 break; 1296 } 1297 1298 echo "<td class='column-auto-updates{$extra_classes}'>"; 1299 1300 $html = array(); 1301 1302 if ( isset( $plugin_data['auto-update-forced'] ) ) { 1303 if ( $plugin_data['auto-update-forced'] ) { 1304 // Forced on. 1305 $text = __( 'Auto-updates enabled' ); 1306 } else { 1307 $text = __( 'Auto-updates disabled' ); 1308 } 1309 $action = 'unavailable'; 1310 $time_class = ' hidden'; 1311 } elseif ( empty( $plugin_data['update-supported'] ) ) { 1312 $text = ''; 1313 $action = 'unavailable'; 1314 $time_class = ' hidden'; 1315 } elseif ( in_array( $plugin_file, $auto_updates, true ) ) { 1316 $text = __( 'Disable auto-updates' ); 1317 $action = 'disable'; 1318 $time_class = ''; 1319 } else { 1320 $text = __( 'Enable auto-updates' ); 1321 $action = 'enable'; 1322 $time_class = ' hidden'; 1323 } 1324 1325 $query_args = array( 1326 'action' => "{$action}-auto-update", 1327 'plugin' => $plugin_file, 1328 'paged' => $page, 1329 'plugin_status' => $status, 1330 ); 1331 1332 $url = add_query_arg( $query_args, 'plugins.php' ); 1333 1334 if ( 'unavailable' === $action ) { 1335 $html[] = '<span class="label">' . $text . '</span>'; 1336 } else { 1337 $html[] = sprintf( 1338 '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">', 1339 wp_nonce_url( $url, 'updates' ), 1340 $action 1341 ); 1342 1343 $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>'; 1344 $html[] = '<span class="label">' . $text . '</span>'; 1345 $html[] = '</a>'; 1346 } 1347 1348 if ( ! empty( $plugin_data['update'] ) ) { 1349 $html[] = sprintf( 1350 '<div class="auto-update-time%s">%s</div>', 1351 $time_class, 1352 wp_get_auto_update_message() 1353 ); 1354 } 1355 1356 $html = implode( '', $html ); 1357 1358 /** 1359 * Filters the HTML of the auto-updates setting for each plugin in the Plugins list table. 1360 * 1361 * @since 5.5.0 1362 * 1363 * @param string $html The HTML of the plugin's auto-update column content, 1364 * including toggle auto-update action links and 1365 * time to next update. 1366 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1367 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1368 * and the {@see 'plugin_row_meta'} filter for the list 1369 * of possible values. 1370 */ 1371 echo apply_filters( 'plugin_auto_update_setting_html', $html, $plugin_file, $plugin_data ); 1372 1373 wp_admin_notice( 1374 '', 1375 array( 1376 'type' => 'error', 1377 'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ), 1378 ) 1379 ); 1380 1381 echo '</td>'; 1382 1383 break; 1384 default: 1385 $classes = "$column_name column-$column_name $class"; 1386 1387 echo "<td class='$classes{$extra_classes}'>"; 1388 1389 /** 1390 * Fires inside each custom column of the Plugins list table. 1391 * 1392 * @since 3.1.0 1393 * 1394 * @param string $column_name Name of the column. 1395 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1396 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1397 * and the {@see 'plugin_row_meta'} filter for the list 1398 * of possible values. 1399 */ 1400 do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); 1401 1402 echo '</td>'; 1403 } 1404 } 1405 1406 echo '</tr>'; 1407 1408 if ( ! $compatible_php || ! $compatible_wp ) { 1409 printf( 1410 '<tr class="plugin-update-tr"><td colspan="%s" class="plugin-update colspanchange">', 1411 esc_attr( $this->get_column_count() ) 1412 ); 1413 1414 $incompatible_message = ''; 1415 if ( ! $compatible_php && ! $compatible_wp ) { 1416 $incompatible_message .= __( 'This plugin does not work with your versions of WordPress and PHP.' ); 1417 if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { 1418 $incompatible_message .= sprintf( 1419 /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ 1420 ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), 1421 self_admin_url( 'update-core.php' ), 1422 esc_url( wp_get_update_php_url() ) 1423 ); 1424 $incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false ); 1425 } elseif ( current_user_can( 'update_core' ) ) { 1426 $incompatible_message .= sprintf( 1427 /* translators: %s: URL to WordPress Updates screen. */ 1428 ' ' . __( '<a href="%s">Please update WordPress</a>.' ), 1429 self_admin_url( 'update-core.php' ) 1430 ); 1431 } elseif ( current_user_can( 'update_php' ) ) { 1432 $incompatible_message .= sprintf( 1433 /* translators: %s: URL to Update PHP page. */ 1434 ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), 1435 esc_url( wp_get_update_php_url() ) 1436 ); 1437 $incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false ); 1438 } 1439 } elseif ( ! $compatible_wp ) { 1440 $incompatible_message .= __( 'This plugin does not work with your version of WordPress.' ); 1441 if ( current_user_can( 'update_core' ) ) { 1442 $incompatible_message .= sprintf( 1443 /* translators: %s: URL to WordPress Updates screen. */ 1444 ' ' . __( '<a href="%s">Please update WordPress</a>.' ), 1445 self_admin_url( 'update-core.php' ) 1446 ); 1447 } 1448 } elseif ( ! $compatible_php ) { 1449 $incompatible_message .= __( 'This plugin does not work with your version of PHP.' ); 1450 if ( current_user_can( 'update_php' ) ) { 1451 $incompatible_message .= sprintf( 1452 /* translators: %s: URL to Update PHP page. */ 1453 ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), 1454 esc_url( wp_get_update_php_url() ) 1455 ); 1456 $incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false ); 1457 } 1458 } 1459 1460 wp_admin_notice( 1461 $incompatible_message, 1462 array( 1463 'type' => 'error', 1464 'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ), 1465 ) 1466 ); 1467 1468 echo '</td></tr>'; 1469 } 1470 1471 /** 1472 * Fires after each row in the Plugins list table. 1473 * 1474 * @since 2.3.0 1475 * @since 5.5.0 Added 'auto-update-enabled' and 'auto-update-disabled' 1476 * to possible values for `$status`. 1477 * 1478 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1479 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1480 * and the {@see 'plugin_row_meta'} filter for the list 1481 * of possible values. 1482 * @param string $status Status filter currently applied to the plugin list. 1483 * Possible values are: 'all', 'active', 'inactive', 1484 * 'recently_activated', 'upgrade', 'mustuse', 'dropins', 1485 * 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled'. 1486 */ 1487 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); 1488 1489 /** 1490 * Fires after each specific row in the Plugins list table. 1491 * 1492 * The dynamic portion of the hook name, `$plugin_file`, refers to the path 1493 * to the plugin file, relative to the plugins directory. 1494 * 1495 * @since 2.7.0 1496 * @since 5.5.0 Added 'auto-update-enabled' and 'auto-update-disabled' 1497 * to possible values for `$status`. 1498 * 1499 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 1500 * @param array $plugin_data An array of plugin data. See get_plugin_data() 1501 * and the {@see 'plugin_row_meta'} filter for the list 1502 * of possible values. 1503 * @param string $status Status filter currently applied to the plugin list. 1504 * Possible values are: 'all', 'active', 'inactive', 1505 * 'recently_activated', 'upgrade', 'mustuse', 'dropins', 1506 * 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled'. 1507 */ 1508 do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status ); 1509 } 1510 1511 /** 1512 * Gets the name of the primary column for this specific list table. 1513 * 1514 * @since 4.3.0 1515 * 1516 * @return string Unalterable name for the primary column, in this case, 'name'. 1517 */ 1518 protected function get_primary_column_name() { 1519 return 'name'; 1520 } 1521 1522 /** 1523 * Prints a list of other plugins that depend on the plugin. 1524 * 1525 * @since 6.5.0 1526 * 1527 * @param string $dependency The dependency's filepath, relative to the plugins directory. 1528 */ 1529 protected function add_dependents_to_dependency_plugin_row( $dependency ) { 1530 $dependent_names = WP_Plugin_Dependencies::get_dependent_names( $dependency ); 1531 1532 if ( empty( $dependent_names ) ) { 1533 return; 1534 } 1535 1536 $dependency_note = __( 'Note: This plugin cannot be deactivated or deleted until the plugins that require it are deactivated or deleted.' ); 1537 1538 $comma = wp_get_list_item_separator(); 1539 $required_by = sprintf( 1540 /* translators: %s: List of dependencies. */ 1541 __( '<strong>Required by:</strong> %s' ), 1542 implode( $comma, $dependent_names ) 1543 ); 1544 1545 printf( 1546 '<div class="required-by"><p>%1$s</p><p>%2$s</p></div>', 1547 $required_by, 1548 $dependency_note 1549 ); 1550 } 1551 1552 /** 1553 * Prints a list of other plugins that the plugin depends on. 1554 * 1555 * @since 6.5.0 1556 * 1557 * @param string $dependent The dependent plugin's filepath, relative to the plugins directory. 1558 */ 1559 protected function add_dependencies_to_dependent_plugin_row( $dependent ) { 1560 $dependency_names = WP_Plugin_Dependencies::get_dependency_names( $dependent ); 1561 1562 if ( array() === $dependency_names ) { 1563 return; 1564 } 1565 1566 $links = array(); 1567 foreach ( $dependency_names as $slug => $name ) { 1568 $links[] = $this->get_dependency_view_details_link( $name, $slug ); 1569 } 1570 1571 $is_active = is_multisite() ? is_plugin_active_for_network( $dependent ) : is_plugin_active( $dependent ); 1572 $comma = wp_get_list_item_separator(); 1573 $requires = sprintf( 1574 /* translators: %s: List of dependency names. */ 1575 __( '<strong>Requires:</strong> %s' ), 1576 implode( $comma, $links ) 1577 ); 1578 1579 $notice = ''; 1580 $error_message = ''; 1581 if ( WP_Plugin_Dependencies::has_unmet_dependencies( $dependent ) ) { 1582 if ( $is_active ) { 1583 $error_message = __( 'This plugin is active but may not function correctly because required plugins are missing or inactive.' ); 1584 } else { 1585 $error_message = __( 'This plugin cannot be activated because required plugins are missing or inactive.' ); 1586 } 1587 $notice = wp_get_admin_notice( 1588 $error_message, 1589 array( 1590 'type' => 'error', 1591 'additional_classes' => array( 'inline', 'notice-alt' ), 1592 ) 1593 ); 1594 } 1595 1596 printf( 1597 '<div class="requires"><p>%1$s</p><p>%2$s</p></div>', 1598 $requires, 1599 $notice 1600 ); 1601 } 1602 1603 /** 1604 * Returns a 'View details' like link for a dependency. 1605 * 1606 * @since 6.5.0 1607 * 1608 * @param string $name The dependency's name. 1609 * @param string $slug The dependency's slug. 1610 * @return string A 'View details' link for the dependency. 1611 */ 1612 protected function get_dependency_view_details_link( $name, $slug ) { 1613 $dependency_data = WP_Plugin_Dependencies::get_dependency_data( $slug ); 1614 1615 if ( false === $dependency_data 1616 || $name === $slug 1617 || $name !== $dependency_data['name'] 1618 || empty( $dependency_data['version'] ) 1619 ) { 1620 return $name; 1621 } 1622 1623 return $this->get_view_details_link( $name, $slug ); 1624 } 1625 1626 /** 1627 * Returns a 'View details' link for the plugin. 1628 * 1629 * @since 6.5.0 1630 * 1631 * @param string $name The plugin's name. 1632 * @param string $slug The plugin's slug. 1633 * @return string A 'View details' link for the plugin. 1634 */ 1635 protected function get_view_details_link( $name, $slug ) { 1636 $url = add_query_arg( 1637 array( 1638 'tab' => 'plugin-information', 1639 'plugin' => $slug, 1640 'TB_iframe' => 'true', 1641 'width' => '600', 1642 'height' => '550', 1643 ), 1644 network_admin_url( 'plugin-install.php' ) 1645 ); 1646 1647 $name_attr = esc_attr( $name ); 1648 return sprintf( 1649 "<a href='%s' class='thickbox open-plugin-details-modal' aria-label='%s' data-title='%s'>%s</a>", 1650 esc_url( $url ), 1651 /* translators: %s: Plugin name. */ 1652 sprintf( __( 'More information about %s' ), $name_attr ), 1653 $name_attr, 1654 esc_html( $name ) 1655 ); 1656 } 1657 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri May 10 08:20:01 2024 | Cross-referenced by PHPXref |