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