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